Add native XPU SVD implementation using oneMKL gesvd#3264
Add native XPU SVD implementation using oneMKL gesvd#3264PatrykWilczewski wants to merge 8 commits intointel:mainfrom
Conversation
Implement native _linalg_svd for XPU using oneMKL's gesvd USM API, removing the CPU fallback that caused extra warning. Previously, _linalg_svd.U was in the XPU fallback list, which meant every SVD call on the XPU transferred data to CPU and back, emitting a fallback warning. This caused test_cond_errors_and_warnings to fail because torch.linalg.cond() internally calls linalg_svdvals() -> _linalg_svd, producing an unexpected second warning alongside the expected resize warning. - Add apply_svd_mkl<>() template calling oneapi::mkl::lapack::gesvd with batch loop, in mkl/BatchLinearAlgebra.cpp - Add svd_mkl() declaration in mkl/BatchLinearAlgebra.h - Register svd_stub for XPU via svd_kernel_xpu() in BatchLinearAlgebra.cpp (with CPU fallback when USE_ONEMKL_XPU is not defined) - Remove "_linalg_svd.U" from XPUFallback.template - Add _linalg_svd dispatch entries for XPU in yaml/native/native_functions.yaml Fixes: intel#2389
There was a problem hiding this comment.
Pull request overview
This PR adds a native XPU implementation of torch._linalg_svd backed by oneMKL gesvd (USM), removing the previous CPU fallback path that caused extra device transfers and fallback warnings.
Changes:
- Added XPU dispatch entries for
_linalg_svd/_linalg_svd.Uinnative_functions.yaml. - Implemented an oneMKL-based SVD path (
svd_mkl,apply_svd_mkl) and registered the XPUsvd_stub. - Removed
"_linalg_svd.U"from the XPU fallback allowlist.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
yaml/native/native_functions.yaml |
Registers XPU dispatch for _linalg_svd so calls no longer fall back to CPU. |
src/ATen/native/xpu/mkl/BatchLinearAlgebra.h |
Adds the svd_mkl declaration and required includes. |
src/ATen/native/xpu/mkl/BatchLinearAlgebra.cpp |
Implements oneMKL gesvd-based SVD and batching loop. |
src/ATen/native/xpu/XPUFallback.template |
Removes _linalg_svd.U from the fallback list. |
src/ATen/native/xpu/BatchLinearAlgebra.cpp |
Registers XPU svd_stub and provides CPU fallback when oneMKL XPU is unavailable. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
53ea463 to
9c04a68
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
4cd7a54 to
e1ccb1d
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Implement native _linalg_svd for XPU using oneMKL's gesvd USM API, removing the CPU fallback that caused extra warning.
Previously, _linalg_svd.U was in the XPU fallback list, which meant every SVD call on the XPU transferred data to CPU and back, emitting a fallback warning. This caused test_cond_errors_and_warnings to fail because torch.linalg.cond() internally calls linalg_svdvals() -> _linalg_svd, producing an unexpected second warning alongside the expected resize warning.
This PR also includes a targeted test-input stabilization for SVD-dependent OpInfo coverage on XPU:
Linalg.cond internally relies on SVD. With unconstrained random float32 matrices, samples are often near singular which can introduce high numerical variance and flaky failures unrelated to the kernel changes in this PR.
Fixes: #2389