Skip to content

Clear the output of sparse products when beta is zero - #702

Merged
maleadt merged 1 commit into
mainfrom
tb/sparse-csc-nan
Oct 16, 2026
Merged

maleadt merged 1 commit into
mainfrom
tb/sparse-csc-nan

Conversation

@maleadt

@maleadt maleadt commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

oneMKL computes beta * y in some sparse products even when beta is zero, so NaNs in the output buffer end up in the result: gemv with a transposed CSR matrix (op 'T' or 'C') on oneMKL 2026.1, and gemm with any op on the older oneMKL of the Aurora LTS stack. mul! has to ignore the output when beta is zero, and * passes it uninitialized memory from similar.

oneSparseMatrixCSC is stored as the CSR handle of its transpose, so oneSparseMatrixCSC * x runs exactly this transposed product. Depending on what the allocator hands out, it returns NaN in rows that should be 0. This is the intermittent oneMKL.oneSparseMatrixCSC failure in GPUArrays.jl's downstream CI (e.g. onemkl.jl:1289, :1321, varying from run to run). transpose(::oneSparseMatrixCSR) * x and complex adjoint(::oneSparseMatrixCSR) * x are affected too.

Minimal reproducer (oneMKL 2026.1, Iris Xe): a 4x3 CSR matrix with an empty row and column, alpha = 1, beta = 0, op 'T'. With y prefilled with NaN the result is all NaN; prefilled with 42 it is correct, so y is scaled by beta, not skipped. On 2026.1, non-transposed CSR gemv, COO gemv and sparse gemm handle beta = 0 correctly, but the first CI run of this PR showed gemm getting it wrong on the LTS stack.

This PR zeroes the output before every oneMKL call that takes a beta (gemv, gemm, symv, trmv) when beta is zero, rather than tracking which op and release get it right, and adds a regression test that multiplies into NaN-filled outputs for CSR and CSC with identity, transpose and adjoint. The test fails on main (2 of 12 cases for Float32, 3 of 12 for ComplexF32) and passes with the fix. The full SPARSE testset passes as well. Float64 is untested because the test GPU has no fp64.

Upstream bug: #703.

@maleadt maleadt changed the title Clear the output of transposed sparse gemv when beta is zero Clear the output of sparse products when beta is zero Oct 16, 2026
`mul!` ignores the output when beta is zero, and its callers pass
uninitialized memory from `similar`. oneMKL computes beta * y regardless
in some cases: gemv with a transposed CSR matrix on oneMKL 2026.1, and
gemm with any op on the older release of the Aurora LTS stack. NaNs from
the allocator then end up in the result. This made
`oneSparseMatrixCSC * x`, which runs as a transposed product on the CSR
handle of the transpose, fail intermittently.

Zero the output before every oneMKL call that takes a beta when beta is
zero, rather than tracking which op and release get it right.
@maleadt
maleadt merged commit da89802 into main Oct 16, 2026
4 of 5 checks passed
@maleadt
maleadt deleted the tb/sparse-csc-nan branch October 16, 2026 08:09
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