Repository navigation
[rocSPARSE] Fix sctr/rocsparse_scatter integer overflow for large nnz (AISPARSE-652) - #11136
Merged
Merged
Conversation
The sctr kernel computed the element index as `hipBlockIdx_x * BLOCKSIZE + hipThreadIdx_x`, which is evaluated in 32-bit unsigned arithmetic and wraps at 2^32 even when the index type I is int64_t. Because the kernel mapped one thread to one element with no grid-stride loop, elements past the wrap point were silently never scattered. Cast the block index to I before the multiply and add a grid-stride loop over nnz so the kernel covers the full range regardless of grid size. Clamp the launch grid.x against handle->properties.maxGridSize[0] so an overflowing nnz cannot exceed the device grid limit. Fixes AC3/AC4 of ROCM-28948 for rocsparse_Xsctr and rocsparse_scatter. Co-authored-by: Cursor <cursoragent@cursor.com>
…AISPARSE-652) Add the sctr_extra regression test driving the 64-bit-index path of rocsparse_scatter with nnz = 2^32 + 512 and probing an element past the 2^32 boundary; before the fix the wrapped block index leaves it unscattered. Guarded to the nightly category with a device_memory_gb budget so it is skipped on smaller GPUs. Document the fix in CHANGELOG. Co-authored-by: Cursor <cursoragent@cursor.com>
✅ All Checks Passed — Ready for Review
📖 Need help? See the Policy FAQ for details on every check and how to fix failures. |
|
🎉 All checks passed! This PR is ready for review. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #11136 +/- ##
===========================================
+ Coverage 69.69% 70.78% +1.09%
===========================================
Files 2932 2849 -83
Lines 481712 468248 -13464
Branches 69452 69174 -278
===========================================
- Hits 335700 331422 -4278
+ Misses 121811 112813 -8998
+ Partials 24201 24013 -188
*This pull request uses carry forward flags. Click here to find out more.
🚀 New features to boost your workflow:
|
jsandham
reviewed
Aug 25, 2026
jsandham
reviewed
Aug 25, 2026
jsandham
reviewed
Aug 25, 2026
jsandham
approved these changes
Aug 25, 2026
- use rocsparse::min to clamp the grid size instead of an if-branch - name the grid-stride start index (gid) for readability - move the large-nnz regression test from sctr_extra to scatter_extra (it exercises the generic rocsparse_scatter API) Co-authored-by: Cursor <cursoragent@cursor.com>
dso-amd
reviewed
Sep 2, 2026
dso-amd
approved these changes
Sep 2, 2026
dso-amd
left a comment
Contributor
There was a problem hiding this comment.
LGTM (see my suggestions on the changelog entry).
…ix (AISPARSE-652) Applies the dso-amd review suggestion on projects/rocsparse/CHANGELOG.md verbatim: reword the 'Resolved issues' entry for rocsparse_Xsctr / rocsparse_scatter to the shorter, standardized overflow description. Co-authored-by: Cursor <cursoragent@cursor.com>
…nable (AISPARSE-652) The large-nnz regression test built a sparse vector descriptor with size = 2 and nnz = 2^32 + 512. rocsparse_create_spvec_descr rejects nnz > size with rocsparse_status_invalid_size, so the test could never pass; it went unnoticed because its device_memory_gb guard kept it from being instantiated on every machine it had been run on so far. Size the dense vector to nnz so the descriptor is valid, and raise device_memory_gb to 70 to cover the now three nnz-sized device allocations (32 GiB indices + 16 GiB values + 16 GiB dense vector). Verified by running the test body at a scaled-down nnz: it passes with the fixed kernel and fails when the kernel is made to drop the tail of the sparse vector, so the probe is load-bearing. Co-authored-by: Cursor <cursoragent@cursor.com>
ntrost57
approved these changes
Sep 17, 2026
…PARSE-652) The snap date for rocSPARSE 5.1.0 has passed, so this fix belongs in the next version. Open "## (Unreleased) rocSPARSE 5.2.0" and move only this PR's Resolved issues entry there. The 5.1.0 section is left otherwise unchanged so the net diff against develop stays additive.
Contributor
TheRock Submodule Bump ActivityNewest first
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
rocsparse_Xsctrand the genericrocsparse_scatterroutine (which delegates to it) computed the element index in the device kernel using 32-bit arithmetic:I idx = hipBlockIdx_x * BLOCKSIZE + hipThreadIdx_x;hipBlockIdx_x * BLOCKSIZEis evaluated in 32-bit unsigned arithmetic before being widened to the (possibly 64-bit) index typeI. For sparse vectors withnnzof2^32(~4.3 billion) or more entries, reachable with 64-bit indices, the block-index multiply overflows. The kernel maps one thread to one element with no grid-stride loop, so past the wrap point the tail of the vector is silently never scattered and no error is returned.The fix casts the block index to the index type
Ibefore the multiply and iterates with a grid-stride loop; the launch grid is clamped to the device limit so a clamped grid still covers allnnzelements. This follows the grid-stride shape already used bydoti_device.h.Changes
sctr_device.h: casthipBlockIdx_x/hipGridDim_xtoIbefore the multiply and use a grid-stride loop overnnz.rocsparse_sctr_impl.cpp: clamp the launch grid tomaxGridSize[0].CHANGELOG.md: document the fix under Resolved issues.testing_sctr.cpp/test_sctr.yaml: add thesctr_extraregression test.Test plan
sctr_extraregression test drivesrocsparse_scatter(64-bit index path) withnnz = 2^32 + 512, then checks that an element beyond the2^32boundary is scattered intoy(y[1] == x_in). Before the fix this element is left untouched, so the test fails; after the fix it passes.nightlycategory with adevice_memory_gb: 55guard and is skipped on smaller GPUs.Made with Cursor
JIRA ID : AISPARSE-652