Skip to content

fix(rocsparse): size the csr2csc temporary buffer for the types it actually sorts - #11651

Merged
kliegeois merged 3 commits into
ROCm:developfrom
ntrost57:users/ntrost57/rocsparse/fix/csr2csc64
Sep 3, 2026
Merged

kliegeois merged 3 commits into
ROCm:developfrom
ntrost57:users/ntrost57/rocsparse/fix/csr2csc64

Conversation

@ntrost57

@ntrost57 ntrost57 commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

csr2csc_buffer_size_core always asked rocPRIM how much scratch a <J, J> sort
needs, but the numeric path sorts <J, I> (column indices as keys, permutation
offsets as values). rocPRIM tunes its onesweep config per key/value size, so the
answer differs between the two, and the conversion ended up writing past the end
of the buffer it had asked the caller to allocate.

This only bites when the row pointer and column index types differ, so it is
reachable through rocsparse_sparse_to_sparse (CSR source, CSC target) but not
through rocsparse_Xcsr2csc, where both types are rocsparse_int. It also needs
more than 1M non-zeros, below that rocPRIM uses a merge sort whose scratch does
not depend on the value type. On gfx942/gfx950 the shortfall is about 64 KB at
1M non-zeros and grows from there; gfx908, gfx90a and gfx1100 happen to pick the
same config for both sorts and were never affected.

The fix is to query the size with the types the sort actually uses.

The new unit test converts a matrix with 1,075,200 non-zeros for all four
index-type combinations, with a poisoned guard band right behind the buffer, and
fails if anything wrote into it. It passes on gfx1100, and shrinking the
allocation by 64 KB as a negative control makes the guard fire. Worth knowing:
on gfx1100 the old and new code produce identical buffer sizes, so this test can
only catch the real defect on MI300-class hardware and the other affected
targets. That caveat is in the file's header comment.

JIRA ID: ROCM-30643

@therock-pr-bot

therock-pr-bot Bot commented Sep 3, 2026 •

Copy link
Copy Markdown

✅ All Checks Passed — Ready for Review

Check Status Details
📝 PR Description ✅ Pass —
⛔ Forbidden Files ✅ Pass —
🧪 Unit Test ⚠️ Warning Error: Source/code files changed without an accompanying unit test.
Expected: add at least one test file named like test_<name>.py / test_<name>.cpp (or <name>_test.*).
Current: code file(s) changed: projects/rocsparse/clients/unittests/unit_test_internal_conversion_csr2csc_buffer.cpp, projects/rocsparse/library/src/conversion/rocsparse_csr2csc.cpp; no test file found
🔎 pre-commit ✅ Pass —
🚫 Draft PR 🔜 To Be Enabled —
🚩 Feature Flag 🔜 To Be Enabled —
📊 Code Coverage 🔜 To Be Enabled —
🤖 therock-pr-bot ✅ Pass —

🎉 All checks passed! This PR is ready for review.

📖 Need help? See the Policy FAQ for details on every check and how to fix failures.

🙋 Wish to Override Policy?

@therock-pr-bot

therock-pr-bot Bot commented Sep 3, 2026

Copy link
Copy Markdown

🎉 All checks passed! This PR is ready for review.

@codecov

codecov Bot commented Sep 3, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...parse/library/src/conversion/rocsparse_csr2csc.cpp 80.00% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           develop   #11651   +/-   ##
========================================
  Coverage    64.11%   64.11%           
========================================
  Files         2826     2826           
  Lines       469784   469792    +8     
  Branches     69375    69377    +2     
========================================
+ Hits        301190   301197    +7     
  Misses      147486   147486           
- Partials     21108    21109    +1     
Flag Coverage Δ *Carryforward flag
TensileLite-CPP 38.59% <ø> (ø) Carriedforward from a2f5bb1
TensileLite-Unit 75.61% <ø> (ø) Carriedforward from a2f5bb1
hipBLAS 90.62% <ø> (ø) Carriedforward from a2f5bb1
hipBLASLt 35.22% <ø> (ø) Carriedforward from a2f5bb1
hipCUB 82.68% <ø> (ø) Carriedforward from a2f5bb1
hipDNN 86.95% <ø> (ø) Carriedforward from a2f5bb1
hipFFT 42.66% <ø> (ø) Carriedforward from a2f5bb1
hipRAND 76.12% <ø> (ø) Carriedforward from a2f5bb1
hipSOLVER 68.92% <ø> (ø) Carriedforward from a2f5bb1
hipSPARSE 86.99% <ø> (ø) Carriedforward from a2f5bb1
rocBLAS 0.28% <ø> (ø) Carriedforward from a2f5bb1
rocFFT 51.25% <ø> (ø) Carriedforward from a2f5bb1
rocRAND 56.91% <ø> (ø) Carriedforward from a2f5bb1
rocSOLVER 76.83% <ø> (ø) Carriedforward from a2f5bb1
rocSPARSE 74.61% <80.00%> (+<0.01%) ⬆️
rocThrust 91.60% <ø> (ø) Carriedforward from a2f5bb1

*This pull request uses carry forward flags. Click here to find out more.

Files with missing lines Coverage Δ
...parse/library/src/conversion/rocsparse_csr2csc.cpp 85.48% <80.00%> (+0.07%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread projects/rocsparse/CHANGELOG.md Resolved

@dso-amd dso-amd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (see suggestions on the changelog entry)

Co-authored-by: Daniel So <dso@amd.com>
@kliegeois
kliegeois merged commit c696973 into ROCm:develop Sep 3, 2026
80 of 81 checks passed
@assistant-librarian

Copy link
Copy Markdown
Contributor

TheRock Submodule Bump Activity

Newest first

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants