-
Notifications
You must be signed in to change notification settings - Fork 61
[WIP] Sparse addmm on SparseXPU #2409
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 15 commits
3e2fd3d
60361f8
14ffb20
6ddb883
d92a628
f413e27
b20065f
8b17d68
f8808c9
81c4832
05ec329
7373309
fbb360f
cd31ed1
5eddb3b
7ce0059
b13168f
a2a5280
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 | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,14 @@ | ||||||||||
| #include <ATen/native/sparse/xpu/sycl/SparseTensorMathKernels.h> | ||||||||||
|
|
||||||||||
| #ifndef AT_PER_OPERATOR_HEADERS | ||||||||||
| #include <ATen/Functions.h> | ||||||||||
| #include <ATen/NativeFunctions.h> | ||||||||||
| #else | ||||||||||
| #include <ATen/ops/addmm.h> | ||||||||||
| #endif | ||||||||||
|
|
||||||||||
| #include <ATen/ExpandUtils.h> | ||||||||||
|
|
||||||||||
| namespace at::native { | ||||||||||
|
|
||||||||||
| using namespace at::sparse; | ||||||||||
|
|
@@ -26,4 +35,68 @@ Tensor _sparse_sum_backward_xpu( | |||||||||
| return xpu::_sparse_sum_backward_kernel(grad_, input_, dims_to_sum); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| Tensor& s_addmm_out_sparse_dense_xpu(Tensor& r_, const Tensor& t, const SparseTensor& sparse_, const Tensor& dense, const Scalar& beta, const Scalar& alpha) { | ||||||||||
| TORCH_CHECK(t.is_xpu(), "Expected all tensors to be on the same device. addmm: expected 'self' to be XPU, but got CPU"); | ||||||||||
| TORCH_CHECK(r_.is_xpu(), "Expected all tensors to be on the same device. addmm: expected 'out' to be XPU, but got CPU"); | ||||||||||
| TORCH_CHECK(sparse_.is_xpu(), "Expected all tensors to be on the same device. addmm: expected 'mat1' to be XPU, but got CPU"); | ||||||||||
| TORCH_CHECK(dense.is_xpu(), "Expected all tensors to be on the same device. addmm: expected 'mat2' to be XPU, but got CPU"); | ||||||||||
|
|
||||||||||
| // TORCH_CHECK(xpu::check_device({sparse_, r_, t, dense})); | ||||||||||
|
||||||||||
| // TORCH_CHECK(xpu::check_device({sparse_, r_, t, dense})); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will Tensor mat1_dense = sparse_._to_dense() cause undefined issues? I noticed that dtype and masked are optional for sparse_to_dense.
Copilot
AI
Nov 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Converting the sparse tensor to dense format defeats the purpose of sparse operations and may cause significant memory overhead for large sparse tensors. Consider implementing a proper sparse matrix multiplication kernel instead of this fallback approach.
| Tensor mat1_dense = sparse_._to_dense(std::nullopt, std::nullopt); | |
| at::addmm_out(r_, t, mat1_dense, dense, beta, alpha); | |
| // Use a proper sparse matrix multiplication kernel for XPU | |
| xpu::addmm_out_sparse_dense_kernel(r_, t, sparse_, dense, beta, alpha); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
xpu::check_devicecan be found insparse/xpu/sycl/SparseTensorMathKernels.cpp.