Skip to content

Fix intermittent NaNs from ldiv! with a transposed right-hand side on CUDA 12.0-12.2 - #3392

Merged
maleadt merged 2 commits into
mainfrom
tb/cusparse-spsm-workspace
Oct 14, 2026
Merged

maleadt merged 2 commits into
mainfrom
tb/cusparse-spsm-workspace

Conversation

@maleadt

@maleadt maleadt commented Oct 13, 2026

Copy link
Copy Markdown
Member

cuSPARSE 12.0 and 12.1 (CUDA 12.0-12.2) have a bug in cusparseSpSM_solve with a transposed B: it reads part of the workspace that cusparseSpSM_analysis never writes (compute-sanitizer initcheck flags spsm_v1_kernel). If the pooled workspace holds stale NaNs, the solution comes out NaN. That is the intermittent lib/cusparse/test/interfaces/ldiv.jl:70 failure on the CUDA 12.0 job since #3314, which only changed what the pool happened to contain. With the workspace filled with 0x00 the result is always correct, and with 0xff it is always NaN. cuSPARSE 12.2.0 (CUDA 12.3) and later aren't affected.

On the affected versions, sm! now zeroes the workspace before the analysis. The same bug explains the "library bug" skip of Float32/ComplexF32 out-of-place solves on CUDA 12.0-12.2, so that skip is removed. A new test frees NaN-filled buffers to the pool before solving, and fails reliably without the fix on CUDA 12.0.

Separately, the in-place ldiv! -- CuMatrix test compared the untouched B and dB. It now checks the solved D and dD.

With a transposed right-hand side, `cusparseSpSM_solve` from cuSPARSE 12.0
and 12.1 (CUDA 12.0-12.2) reads parts of the workspace that the analysis
doesn't write. A fresh workspace from the memory pool can hold stale data,
and when that contains NaNs, so does the solution: out-of-place
`ldiv!(C, triangular(A), transpose(B))` intermittently returned NaN on the
CUDA 12.0 CI job. Zero the workspace on those versions.

The same bug is why Float32 and ComplexF32 out-of-place solves were skipped
on CUDA 12.0-12.2, so run those again.
The test compared the untouched B and dB, instead of the D and dD that
ldiv! solves into.
@maleadt maleadt added bugfix libraries Vendor library wrappers (cuBLAS, cuSPARSE, cuFFT, cuDNN, ...). labels Oct 13, 2026
@github-actions

Copy link
Copy Markdown
Contributor

CUDA.jl Benchmarks

Details
Benchmark suite Current: e08c69c Previous: 212af1e Ratio
array/accumulate/Float32/1d 63535 ns 65317 ns 0.97
array/accumulate/Float32/dims=1 208166 ns 208785 ns 1.00
array/accumulate/Float32/dims=1L 230410 ns 231362 ns 1.00
array/accumulate/Float32/dims=2 92381 ns 92936 ns 0.99
array/accumulate/Float32/dims=2L 4413402 ns 4414162 ns 1.00
array/accumulate/Int64/1d 105906 ns 106759 ns 0.99
array/accumulate/Int64/dims=1 224086 ns 224599 ns 1.00
array/accumulate/Int64/dims=1L 403903 ns 404787 ns 1.00
array/accumulate/Int64/dims=2 111463 ns 112409 ns 0.99
array/accumulate/Int64/dims=2L 5302657 ns 5304186 ns 1.00
array/broadcast 10672 ns 11284 ns 0.95
array/broadcast launch 6689.8 ns 7388.5 ns 0.91
array/construct 928.2222222222222 ns 966.34375 ns 0.96
array/copy 16802 ns 17285 ns 0.97
array/copyto!/cpu_to_gpu 206908 ns 206598 ns 1.00
array/copyto!/gpu_to_cpu 240140 ns 240623 ns 1.00
array/copyto!/gpu_to_gpu 8730 ns 8960 ns 0.97
array/iteration/findall/bool 49595 ns 49634 ns 1.00
array/iteration/findall/int 69141 ns 70475 ns 0.98
array/iteration/findfirst/bool 114143 ns 116138 ns 0.98
array/iteration/findfirst/int 111608 ns 113800 ns 0.98
array/iteration/findmin/1d 65140 ns 66791 ns 0.98
array/iteration/findmin/2d 66983 ns 67619 ns 0.99
array/iteration/logical 53064 ns 52939 ns 1.00
array/iteration/scalar 60160 ns 61169 ns 0.98
array/permutedims/2d 47307 ns 48338 ns 0.98
array/permutedims/3d 45078 ns 45659 ns 0.99
array/permutedims/4d 48281 ns 48717 ns 0.99
array/random/rand/Float32 10852 ns 11309 ns 0.96
array/random/rand/Int64 18230 ns 18964 ns 0.96
array/random/rand!/Float32 8177 ns 8438.333333333334 ns 0.97
array/random/rand!/Int64 16029 ns 16530 ns 0.97
array/random/randn/Float32 33860 ns 34478 ns 0.98
array/random/randn!/Float32 24849 ns 25061 ns 0.99
array/reductions/mapreduce/Float32/1d 48907 ns 50429 ns 0.97
array/reductions/mapreduce/Float32/dims=1 42442 ns 43107 ns 0.98
array/reductions/mapreduce/Float32/dims=1L 71895 ns 72540 ns 0.99
array/reductions/mapreduce/Float32/dims=2 43675 ns 44886 ns 0.97
array/reductions/mapreduce/Float32/dims=2L 72933 ns 73143 ns 1.00
array/reductions/mapreduce/Int64/1d 49839 ns 51687 ns 0.96
array/reductions/mapreduce/Int64/dims=1 44556 ns 45426 ns 0.98
array/reductions/mapreduce/Int64/dims=1L 111755 ns 112852 ns 0.99
array/reductions/mapreduce/Int64/dims=2 44909 ns 46742 ns 0.96
array/reductions/mapreduce/Int64/dims=2L 98894 ns 100935 ns 0.98
array/reductions/reduce/Float32/1d 49119 ns 50222 ns 0.98
array/reductions/reduce/Float32/dims=1 42568 ns 43415 ns 0.98
array/reductions/reduce/Float32/dims=1L 72046 ns 73141 ns 0.99
array/reductions/reduce/Float32/dims=2 44413 ns 44957 ns 0.99
array/reductions/reduce/Float32/dims=2L 73171 ns 73558 ns 0.99
array/reductions/reduce/Int64/1d 50816 ns 52140 ns 0.97
array/reductions/reduce/Int64/dims=1 44697 ns 45836 ns 0.98
array/reductions/reduce/Int64/dims=1L 112012 ns 113326 ns 0.99
array/reductions/reduce/Int64/dims=2 45366 ns 46418 ns 0.98
array/reductions/reduce/Int64/dims=2L 98895 ns 100281 ns 0.99
array/reverse/1d 23359 ns 23893 ns 0.98
array/reverse/1dL 129206 ns 129747 ns 1.00
array/reverse/1dL_inplace 70839 ns 71493 ns 0.99
array/reverse/1d_inplace 12691 ns 13317 ns 0.95
array/reverse/2d 23062 ns 23517 ns 0.98
array/reverse/2dL 81612 ns 82043 ns 0.99
array/reverse/2dL_inplace 71051 ns 71810 ns 0.99
array/reverse/2d_inplace 15211 ns 15843 ns 0.96
array/sorting/1d 749604 ns 751635 ns 1.00
array/sorting/2d 194299 ns 195077 ns 1.00
array/sorting/by 928088 ns 928868 ns 1.00
cuda/graph/capture 41280 ns 41925 ns 0.98
cuda/graph/eager 38632 ns 42248 ns 0.91
cuda/graph/launch 13924 ns 14019 ns 0.99
cuda/synchronization/context/auto 8024 ns 7997.75 ns 1.00
cuda/synchronization/context/blocking 902.2790697674419 ns 895.8 ns 1.01
cuda/synchronization/context/nonblocking 8002 ns 7974.75 ns 1.00
cuda/synchronization/stream/auto 844.1111111111111 ns 886.9019607843137 ns 0.95
cuda/synchronization/stream/blocking 781.7619047619048 ns 780.3818181818182 ns 1.00
cuda/synchronization/stream/nonblocking 7765.333333333333 ns 7939.75 ns 0.98
integration/byval/reference 147625 ns 147881 ns 1.00
integration/byval/slices=1 148753 ns 148971 ns 1.00
integration/byval/slices=2 290203 ns 290729 ns 1.00
integration/byval/slices=3 432232 ns 432610 ns 1.00
integration/cudadevrt 104995 ns 105333 ns 1.00
integration/volumerhs 9609479 ns 9609784 ns 1.00
kernel/indexing 11518 ns 11657 ns 0.99
kernel/indexing_checked 11777 ns 12194 ns 0.97
kernel/launch 2293 ns 2508 ns 0.91
kernel/occupancy 840.75 ns 878.25 ns 0.96
kernel/rand 14722 ns 15391 ns 0.96
latency/import 4766802587 ns 4759695773 ns 1.00
latency/precompile 5428943406 ns 5390889215 ns 1.01
latency/ttfp 5251971608 ns 5247400815 ns 1.00

This comment was automatically generated by workflow using github-action-benchmark.

@codecov

codecov Bot commented Oct 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.97%. Comparing base (212af1e) to head (e08c69c).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3392      +/-   ##
==========================================
- Coverage   86.36%   84.97%   -1.39%     
==========================================
  Files         192      191       -1     
  Lines       19525    19243     -282     
==========================================
- Hits        16862    16352     -510     
- Misses       2663     2891     +228     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@maleadt
maleadt merged commit 26f2c4f into main Oct 14, 2026
18 checks passed
@maleadt
maleadt deleted the tb/cusparse-spsm-workspace branch October 14, 2026 06:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

libraries Vendor library wrappers (cuBLAS, cuSPARSE, cuFFT, cuDNN, ...).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant