Skip to content

feat: SDDMM/SPMM NPU-native kernels + stream sync fixes for Ascend - #14

Closed
xuejiakn wants to merge 7 commits into
BUPT-GAMMA:masterfrom
xuejiakn:feat-sddmm-spmm-ascend
Closed

feat: SDDMM/SPMM NPU-native kernels + stream sync fixes for Ascend#14
xuejiakn wants to merge 7 commits into
BUPT-GAMMA:masterfrom
xuejiakn:feat-sddmm-spmm-ascend

Conversation

@xuejiakn

Copy link
Copy Markdown

Summary

Add NPU-native Ascend C kernels for SDDMM and SPMM operators, plus PyTorch NPU stream synchronization fixes to resolve data races between DGL kernels and PyTorch autograd.

Changes

1. SDDMM operator (4 new files)

  • : Ascend C kernel for dot op (FP32/FP16, COO format)
  • : NPU-native gather kernel for copy_lhs/copy_rhs (avoids CPU roundtrip that caused stream sync issues)
  • : Tiling struct
  • : Host dispatch for all ops (dot: NPU kernel; copy_lhs/copy_rhs: NPU gather; add/sub/mul/div: CPU fallback)

2. SPMM operator (2 new files)

  • : Ascend C kernel for SpMM copy_lhs + sum/max/min (FP32/FP16)
  • : Tiling struct
  • modified: FP32 uses NPU kernel (was CPU fallback), int64 index cast, default stream

3. Stream sync fixes (PR #13 + segment_reduce)

  • : Support torch.npu.Stream (.npu_stream)
  • : _sync_npu() before/after structure queries (in_degrees, in_edges, etc.)
  • : torch.npu.synchronize() before segment_reduce kernel
  • : Default stream (nullptr), synchronous memcpy, aclrtSynchronizeDevice

4. COO operation Ascend support

  • : CPU fallback with aclrtSynchronizeDevice for COOGetRowNNZ, COOGetRowDataAndIndices, COOSliceRows, COOSort_
  • : InEdges prefers COO format on Ascend

Test Results

  • DGL SDDMM tests: 180 passed
  • DGL SpMM tests: diff=0.0 (bit-exact)
  • DGL sparse SDDMM tests: 48 passed
  • DeepChem LCNN test: 2 passed (forward + backward + training)

xuejiakn added 4 commits July 21, 2026 21:42
- Add sddmm_dot_kernel.cpp: Ascend C kernel for dot op (FP32/FP16, COO format)
- Add sddmm_copy_lhs_kernel.cpp: NPU-native gather kernel for copy_lhs/copy_rhs
- Add sddmm.cc: host dispatch supporting all ops
- Modify kernel.cc: SDDMM dispatch macros to ATEN_XPU_SWITCH_CUDA_ASCEND
- Add spmm_kernel.cpp: Ascend C kernel for SpMM (copy_lhs + sum/max/min)
- Add spmm_tiling.h: tiling struct
- Modify spmm.cc: FP32 uses NPU kernel, int64 cast, default stream
…ment_reduce

- streams.py: support torch.npu.Stream
- heterograph.py: _sync_npu() before/after structure queries
- _sparse_ops.py: sync before segment_reduce
- core.py: fix assert int(deg)
…stream

- array.cc: CPU fallback for COOGetRowNNZ/COOGetRowDataAndIndices/COOSliceRows/COOSort_
- segment_reduce.cc: default stream, synchronous memcpy, aclrtSynchronizeDevice
- unit_graph.cc: InEdges prefers COO on Ascend
@xuejiakn
xuejiakn force-pushed the feat-sddmm-spmm-ascend branch from 70eabed to 28901c0 Compare July 21, 2026 13:42
xuejiakn added 3 commits July 21, 2026 21:43
51 test cases covering SDDMM/SPMM ops, UDF reduce, stream sync, and end-to-end GCN.
51 test cases covering SDDMM/SPMM ops, UDF reduce, stream sync, and end-to-end GCN.
- sddmm.cc: explicit aclrtSynchronizeDevice after each CopyTo in CPU fallback
- _sparse_ops.py: add torch.npu.synchronize() before SDDMM CAPI call
- All 58 tests pass: 0 failed, 0 skipped, 0 xfailed
@xuejiakn

Copy link
Copy Markdown
Author

PR 已由重组后的新 PR 替代

本 PR 的内容已按功能维度重新拆分并整合到以下新 PR 中,避免与 #13/#15 的重复:

原 commit 新 PR 说明
#14[1] SDDMM 实现 #16 feat/sddmm-ascend feat(sddmm)
#14[2] SPMM 实现 #17 feat/spmm-ascend feat(spmm)
#14[3] stream sync #13 fix/npu-stream-sync #13 重复,已合并
#14[4] COO fallback #18 fix/coo-cpu-fallback fix(npu)
#14[5][6] 测试(重复) #19 test/sddmm-spmm 合并为单 commit
#14[7] SDDMM fix #16 feat/sddmm-ascend 并入 sddmm PR

关闭原因:本 PR 与 #13(stream sync)、#15(SDDMM/SPMM)存在大面积功能重叠,reviewer 难以判断以哪个为准。重组后每个功能对应一个独立 PR,便于逐项 review 和 cherry-pick。

如需查看重组详情,请见各新 PR 的 description。

@xuejiakn xuejiakn closed this Jul 28, 2026
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