Skip to content

Enable _linalg_det, _linalg_slogdet and _linalg_solve_ex related operations on xpu #1660

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions src/ATen/native/xpu/BatchLinearAlgebra.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include <ATen/core/Tensor.h>
#include <ATen/native/BatchLinearAlgebra.h>
#include <ATen/native/DispatchStub.h>
#if defined(USE_ONEMKL_XPU)
#include <ATen/native/xpu/mkl/BatchLinearAlgebra.h>
#endif // USE_ONEMKL_XPU

namespace at::native {

void lu_solve_kernel_xpu(
const Tensor& LU,
const Tensor& pivots,
const Tensor& B,
TransposeType trans) {
#if defined(USE_ONEMKL_XPU)
native::xpu::lu_solve_mkl(LU, pivots, B, trans);
#else
const auto LU_cpu = LU.to(LU.options().device(kCPU));
const auto pivots_cpu = pivots.to(pivots.options().device(kCPU));
auto B_cpu = B.to(B.options().device(kCPU));

lu_solve_stub(at::kCPU, LU_cpu, pivots_cpu, B_cpu, trans);

B.copy_(B_cpu);
#endif // USE_ONEMKL_XPU
}

REGISTER_XPU_DISPATCH(lu_solve_stub, &lu_solve_kernel_xpu);

void lu_factor_kernel_xpu(
const Tensor& input,
const Tensor& pivots,
const Tensor& infos,
bool compute_pivots) {
#if defined(USE_ONEMKL_XPU)
native::xpu::lu_factor_mkl(input, pivots, infos, compute_pivots);
#else
auto input_cpu = input.to(input.options().device(kCPU));
auto pivots_cpu = pivots.to(pivots.options().device(kCPU));
const auto infos_cpu = infos.to(infos.options().device(kCPU));

lu_factor_stub(at::kCPU, input_cpu, pivots_cpu, infos_cpu, compute_pivots);

input.copy_(input_cpu);
pivots.copy_(pivots_cpu);
infos.copy_(infos_cpu);
#endif // USE_ONEMKL_XPU
}

REGISTER_XPU_DISPATCH(lu_factor_stub, &lu_factor_kernel_xpu);

} // namespace at::native
5 changes: 0 additions & 5 deletions src/ATen/native/xpu/XPUFallback.template
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ TORCH_LIBRARY_IMPL(aten, XPU, m) {
"_flash_attention_forward",
"geqrf",
"linalg_cholesky_ex.L",
"_linalg_det.result",
"linalg_eig",
"_linalg_eigvals",
"linalg_eigvals.out",
Expand All @@ -203,13 +202,9 @@ TORCH_LIBRARY_IMPL(aten, XPU, m) {
"linalg_ldl_factor_ex.out",
"linalg_ldl_solve.out",
"linalg_lstsq.out",
"linalg_lu_factor_ex.out",
"linalg_lu.out",
"linalg_lu_solve.out",
"linalg_matrix_exp",
"linalg_qr.out",
"_linalg_slogdet.sign",
"_linalg_solve_ex.result",
"linalg_solve_triangular",
"_linalg_svd.U",
"lu_unpack.out",
Expand Down
Loading
Loading