Skip to content

[XPU] Register _spsolve for the SparseCsrXPU backend - #97

Open
laifenxiawucha wants to merge 1 commit into
mainfrom
agent/handle-pr_189372-spsolve-xpu-dispatch
Open

laifenxiawucha wants to merge 1 commit into
mainfrom
agent/handle-pr_189372-spsolve-xpu-dispatch

Conversation

@laifenxiawucha

Copy link
Copy Markdown
Owner

Summary

Enables torch.sparse.spsolve on Intel XPU. aten::_spsolve previously had only a SparseCsrCUDA dispatch, so on XPU it raised:

RuntimeError: Could not run 'aten::_spsolve' with arguments from the 'SparseCsrXPU' backend

This adds the SparseCsrXPU dispatch line (one line), mirroring the existing SparseCsrCUDA registration:

- func: _spsolve(Tensor A, Tensor B, *, bool left=True) -> Tensor
  python_module: sparse
  dispatch:
    SparseCsrCUDA: _sparse_csr_linear_solve
    SparseCsrXPU: _sparse_csr_linear_solve_xpu   # added

Coordinated out-of-tree change

The XPU kernel _sparse_csr_linear_solve_xpu is implemented in torch-xpu-ops (intel-sandbox/torch-xpu-ops-exp#1965): since XPU has no native sparse direct solver, it densifies the CSR matrix and defers to the dense at::linalg_solve, mirroring the CUDA cuDSS backend's semantics and validation contract. That PR also carries the identical dispatch line in the torch-xpu-ops codegen yaml (as triangular_solve already does across both yamls).

Verification (Intel Data Center GPU Max 1100, source build torch 2.14.0a0)

With this dispatch line plus the torch-xpu-ops kernel built in:

  • Issue reproducer: torch.sparse.spsolve on an identity CSR system returns [1,1,1,1] (was: dispatch RuntimeError).
  • Regression suite test_spsolve_sparse_csr.py passes 5/5 (identity, dense reference + residual A@x==b, CPU-dense parity, float32, size-mismatch error).

🤖 Generated with Claude Code

torch.sparse.spsolve (aten::_spsolve) previously had only a SparseCsrCUDA
dispatch, so on XPU it raised "Could not run 'aten::_spsolve' with
arguments from the 'SparseCsrXPU' backend".

Add a SparseCsrXPU dispatch entry mapping to _sparse_csr_linear_solve_xpu,
mirroring the existing SparseCsrCUDA registration. The XPU kernel is
implemented out-of-tree in torch-xpu-ops (densify + at::linalg_solve,
mirroring the cuDSS backend contract).

Verified on Intel Data Center GPU Max 1100 (source build, torch 2.14.0a0):
with this dispatch line plus the torch-xpu-ops kernel, torch.sparse.spsolve
returns the correct identity solve and a 5-case regression suite passes.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant