Skip to content

Fix rocsparse_sptrsv_get_output singularity outputs for ELL matrices - #12010

Open
kliegeois wants to merge 4 commits into
ROCm:developfrom
kliegeois:users/kliegeois/fix-ell-sptrsv-singularity
Open

Fix rocsparse_sptrsv_get_output singularity outputs for ELL matrices#12010
kliegeois wants to merge 4 commits into
ROCm:developfrom
kliegeois:users/kliegeois/fix-ell-sptrsv-singularity

Conversation

@kliegeois

Copy link
Copy Markdown
Contributor

Problem

rocsparse_sptrsv_get_output returned rocsparse_singularity_none and position -1 for ELL matrices even when analysis or compute had detected a missing or exactly-zero diagonal pivot. The rocsparse_sptrsv_output_zero_pivot_position query reported the pivot row correctly, so the two outputs disagreed and a caller relying on the generic singularity outputs treated a singular ELL matrix as regular.

In the rocsparse_sptrsv_output_singularity / rocsparse_sptrsv_output_singularity_position branch of rocsparse_sptrsv_get_output, ELL was grouped with the formats that have no triangular-solve info (Blocked ELL, SELL, COO AoS). The symbolic and numeric pivot markers were therefore left null and the reduction produced the "no singularity" answer, while the zero-pivot branch had always used the ELL info.

Fix

The ELL case now passes the pivot markers of the ELL triangular-solve info to the singularity reduction, the same way CSR, COO, and CSC do: the info object provides the symbolic marker and get_singularity_numeric_exact() provides the numeric one. When BUILD_WITH_ELL_TRSV is off, the case returns rocsparse_status_not_implemented, matching the zero-pivot branch. A null info, i.e. a query before analysis, still yields none and -1.

Test

testing_sptrsv_ell cross-checks the generic singularity outputs against the zero-pivot output after analysis and after compute, in both host and device pointer mode. A new sptrsv_ell_extra case pins down the classification on three 3x3 matrices: regular, missing diagonal (symbolic at row 1 after both stages), and stored zero diagonal (none after analysis, numeric_exact at row 1 after compute).

Verification

Built and run on gfx1201:

  • --gtest_filter=*sptrsv_ell*: 949 tests passed
  • --gtest_filter=*extra*: 8066 tests passed
  • With the library change reverted, sptrsv_ell_extra fails with expected type 1 position 1, got type 0 position -1 and expected type 2 position 1, got type 0 position -1, so the new test reproduces the reported defect.

JIRA ID: ROCM-30894

kliegeois and others added 3 commits September 11, 2026 10:36
Wire ellsv info into rocsparse_sptrsv_get_output so singular ELL
matrices no longer return a false-clean none/-1 result.

Co-authored-by: Cursor <cursoragent@cursor.com>
Check invariants after compute instead of re-deriving the library's
symbolic/numeric precedence rule, preserve the caller's pointer mode
while querying, and allocate the singularity output buffer directly
since device_dense_vector cannot be instantiated on an enumeration.

Co-authored-by: Cursor <cursoragent@cursor.com>
The unreleased section already announces ELL support for
rocsparse_sptrsv, so the defect never shipped.

Co-authored-by: Cursor <cursoragent@cursor.com>
@kliegeois
kliegeois requested a review from a team as a code owner September 11, 2026 22:24
@therock-pr-bot

therock-pr-bot Bot commented Sep 11, 2026

Copy link
Copy Markdown

✅ All Checks Passed — Ready for Review

Check Status Details
📝 PR Description ✅ Pass
Forbidden Files ✅ Pass
🧪 Unit Test ✅ Pass
🔎 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

Copy link
Copy Markdown

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

@codecov

codecov Bot commented Sep 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 70.00000% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
.../rocsparse/library/src/level2/rocsparse_sptrsv.cpp 70.00% 2 Missing and 1 partial ⚠️

❌ Your project check has failed because the head coverage (74.68%) is below the target coverage (80.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #12010      +/-   ##
===========================================
+ Coverage    70.55%   70.56%   +0.01%     
===========================================
  Files         2810     2810              
  Lines       462508   462528      +20     
  Branches     68099    68103       +4     
===========================================
+ Hits        326292   326357      +65     
+ Misses      112675   112619      -56     
- Partials     23541    23552      +11     
Flag Coverage Δ *Carryforward flag
TensileLite-CPP 46.40% <ø> (ø) Carriedforward from 697e8e5
TensileLite-Unit 76.07% <ø> (ø) Carriedforward from 697e8e5
hipBLAS 90.62% <ø> (ø) Carriedforward from 697e8e5
hipBLASLt 35.27% <ø> (ø) Carriedforward from 697e8e5
hipCUB 82.68% <ø> (ø) Carriedforward from 697e8e5
hipDNN 87.02% <ø> (ø) Carriedforward from 697e8e5
hipFFT 42.66% <ø> (ø) Carriedforward from 697e8e5
hipRAND 76.12% <ø> (ø) Carriedforward from 697e8e5
hipSOLVER 68.92% <ø> (ø) Carriedforward from 697e8e5
hipSPARSE 86.99% <ø> (ø) Carriedforward from 697e8e5
rocBLAS 48.31% <ø> (ø) Carriedforward from 697e8e5
rocFFT 51.72% <ø> (ø) Carriedforward from 697e8e5
rocRAND 56.90% <ø> (ø) Carriedforward from 697e8e5
rocSOLVER 76.83% <ø> (ø) Carriedforward from 697e8e5
rocSPARSE 74.68% <70.00%> (+0.06%) ⬆️
rocThrust 91.60% <ø> (ø) Carriedforward from 697e8e5

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

Files with missing lines Coverage Δ
.../rocsparse/library/src/level2/rocsparse_sptrsv.cpp 74.67% <70.00%> (+2.10%) ⬆️

... and 2 files with indirect coverage changes

🚀 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.

@@ -175,6 +264,15 @@ void testing_sptrsv_ell(const Arguments& arg)
CHECK_ROCSPARSE_ERROR(rocsparse_status_internal_error);
}

// Analysis can only expose a structural singularity, and it must be the row

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.

Above we already query the analysis pivot so I think this is redundant. I do think that using rocsparse_sptrsv_output_singularity and rocsparse_sptrsv_output_singularity_position as you have done here is the more robust way to handle zero pivot queries with the new generic routines than using rocsparse_sptrsv_output_zero_pivot_position, but we should pick one or the other and not both.

My proposal

Given that we use rocsparse_sptrsv_output_zero_pivot_position in the other SpTRSV format testing, I suggest deleting these additions for now to keep ELL consistent with the other formats. Then in a follow-up PR, replace the usage of rocsparse_sptrsv_output_zero_pivot_position with rocsparse_sptrsv_output_singularity and rocsparse_sptrsv_output_singularity_position. This keeps this bug fix small and does not duplicate zero pivot lookup.

@@ -237,6 +335,31 @@ void testing_sptrsv_ell(const Arguments& arg)
CHECK_ROCSPARSE_ERROR(rocsparse_status_invalid_value);
}

// After compute the singularity can be structural or numeric depending on

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.

@@ -327,4 +450,134 @@ INSTANTIATE(int64_t, float);
INSTANTIATE(int64_t, double);
INSTANTIATE(int64_t, rocsparse_float_complex);
INSTANTIATE(int64_t, rocsparse_double_complex);
void testing_sptrsv_ell_extra(const Arguments& arg) {}

static void testing_sptrsv_ell_extra_case(const host_ell_matrix<float>& hA,

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.

Keep this test though.

@@ -347,6 +347,20 @@ try
break;
}
case rocsparse_format_ell:
{

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.

Thanks for fixing this.

Keep testing_sptrsv_ell on the zero-pivot output used by the other
formats; generic type/position coverage stays in sptrsv_ell_extra.

Co-authored-by: Cursor <cursoragent@cursor.com>
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.

2 participants