-
Notifications
You must be signed in to change notification settings - Fork 62
QR operator utilizing XPU. #2399
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
base: main
Are you sure you want to change the base?
Changes from 20 commits
78e95cd
60b868b
2267fca
ba893b0
e0f5f6b
16028d1
c40b846
025291a
6e025e1
5e593d8
2038538
e564e1a
8f5a74c
3c26a9e
1531fa1
980732b
e8b49e7
419eb57
a56a4ff
7906ef2
c995189
472a9de
a5f9ce3
306c683
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -2,6 +2,8 @@ | |||
| #include <ATen/native/BatchLinearAlgebra.h> | ||||
| #include <ATen/native/DispatchStub.h> | ||||
| #include <ATen/native/LinearAlgebraUtils.h> | ||||
| #include <ATen/ops/linalg_qr_native.h> | ||||
| #include <ATen/ops/linalg_qr_cpu_dispatch.h> | ||||
| #if defined(USE_ONEMKL_XPU) | ||||
| #include <ATen/native/xpu/mkl/BatchLinearAlgebra.h> | ||||
| #endif // USE_ONEMKL_XPU | ||||
|
|
@@ -64,4 +66,21 @@ void lu_factor_kernel_xpu( | |||
|
|
||||
| REGISTER_XPU_DISPATCH(lu_factor_stub, &lu_factor_kernel_xpu); | ||||
|
|
||||
| TORCH_IMPL_FUNC(linalg_qr_xpu_out)(const Tensor& A, | ||||
| std::string_view mode, | ||||
| const Tensor & Q, | ||||
| const Tensor & R) { | ||||
| #if defined(USE_ONEMKL_XPU) | ||||
| xpu::linalg_qr_kernel(A, mode, Q, R); | ||||
| #else | ||||
| auto A_cpu = A.to(at::kCPU); | ||||
| auto Q_cpu = at::empty_like(Q, at::kCPU); | ||||
| auto R_cpu = at::empty_like(R, at::kCPU); | ||||
| at::cpu::linalg_qr_out(Q_cpu, R_cpu, A_cpu, mode); | ||||
| Q.copy_(Q_cpu); | ||||
| R.copy_(R_cpu); | ||||
| #endif // USE_ONEMKL_XPU | ||||
| } | ||||
|
Comment on lines
69
to
92
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My suggestion is to register |
||||
|
|
||||
|
|
||||
|
||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9443,6 +9443,17 @@ | |
| - func: linalg_solve(Tensor A, Tensor B, *, bool left=True) -> Tensor | ||
| python_module: linalg | ||
|
|
||
| - func: linalg_qr(Tensor A, str mode='reduced') -> (Tensor Q, Tensor R) | ||
| python_module: linalg | ||
| variants: function | ||
| structured_delegate: linalg_qr.out | ||
|
|
||
| - func: linalg_qr.out(Tensor A, str mode='reduced', *, Tensor(a!) Q, Tensor(b!) R) -> (Tensor(a!) Q, Tensor(b!) R) | ||
| python_module: linalg | ||
| structured: True | ||
| dispatch: | ||
| XPU: linalg_qr_xpu_out | ||
|
|
||
|
Comment on lines
+9446
to
+9456
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please refer to https://github.com/pytorch/pytorch/blob/main/aten/src/ATen/native/native_functions.yaml#L14623 and consider stub mentioned above.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using existing PT stub for implementing QR has both pros and cons. At the side of pros, we take the most of the existing infrastructure with simplified flow on sycl/xpu side. The implementation proposed here has, however also several strengths. Namely:
Thus, although provitidn these two kernels separately is a natural development path, I would prioritize it for later, after QR and two pending requests will be ready.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mwiktor-intel For layout differences, could you indicate in MKL document the reason why LAPACK is row-major? https://www.intel.com/content/www/us/en/docs/onemkl/developer-reference-dpcpp/2025-2/geqrf-usm-version.html Please pay attention to leading dimension
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LDA cannot be replacement of stride. LDA can be used to skip some elements in matrix, but with LDA we cannot force difference data orientation. Specifically: say we have 3x2 matrix. Lapack expects this 6 element array in memory to represent the data as follows: Some BLAS function have row_major of col_major order, but it is not the case within LAPACK.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the elaboration. Let me rephase your example 1: given 3x2 matrix stored as [0, 2, 4, 1, 3, 5] in memory, the logic order is [[0, 1], [2, 3], [4, 5]] if this matrix is col-major, right? You mentioned "LDA here is 2", but why LDA here can be smaller than the number of rows? |
||
| - func: linalg_inv_ex(Tensor A, *, bool check_errors=False) -> (Tensor inverse, Tensor info) | ||
| python_module: linalg | ||
| structured_delegate: linalg_inv_ex.inverse | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.