Make oneMKL sparse matrices AbstractGPUSparseArrays - #642
Merged
Merged
Conversation
Subtype GPUArrays' AbstractGPUSparseMatrixCSR/CSC/COO so that the generic sparse functionality of GPUArrays (broadcast, mapreduce, norms, findnz, triu/tril/kron, indexing, similar/copy) applies to oneSparseMatrixCSR/CSC/COO, and run the GPUArrays sparse testsuite on the CSR and CSC types. The oneMKL matrix handle is now created lazily on the first oneMKL operation and invalidated when the storage vectors are replaced (copyto!, unsafe_free!), since GPUArrays' generic code constructs sparse matrices freely and resizes their storage. As a consequence any element type can be stored; the oneMKL operations still require Float32/Float64/ComplexF32/ComplexF64 values with Int32/Int64 indices and error otherwise. Conversions between the three formats, transposition/adjoint, sparse addition and the COO structural operations (triu, tril, kron, reshape, droptol!) are implemented on the device with generic operations (sortperm, broadcast). adapt(oneArray, ::SparseMatrixCSC) now returns a oneSparseMatrixCSC, matching CUDA.jl and AMDGPU.jl. Fixes #627.
…ular ops - Every sparse matrix now holds its own reference to its storage vectors, so unsafe_free! on one matrix no longer frees vectors shared with another (single-input broadcast outputs, type conversions). - copyto! between sparse matrices of the same format accepts different element and index types, replacing the storage and dropping the handle instead of falling back to in-place or scalar GPUArrays methods. - Empty triangular matrices with a unit diagonal act as the identity in trmv/trsv/trsm; with a non-unit diagonal the solves throw SingularException. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #642 +/- ##
==========================================
- Coverage 81.61% 80.76% -0.85%
==========================================
Files 50 55 +5
Lines 3611 4087 +476
==========================================
+ Hits 2947 3301 +354
- Misses 664 786 +122 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Fixes #627.
oneSparseMatrixCSR,oneSparseMatrixCSCandoneSparseMatrixCOOnow subtype GPUArrays'AbstractGPUSparseMatrixCSR/CSC/COO, so the generic sparse functionality of GPUArrays.jl applies to them: broadcasting (zero-preserving functions keep the result sparse),sum/mapreducealong dimensions,norm/opnorm,findnz,triu/tril/kron,iszero, scalar indexing under@allowscalar,similar/copy/collect. The GPUArrays sparse testsuite is enabled for the CSR and CSC types (COO is excluded because GPUArrays' generic sparse broadcast only supports vectors, CSR and CSC).Changes
oneMKL.sparse_matrix_handle) and dropped when the storage is replaced (copyto!,unsafe_free!). Empty matrices never get a handle; the wrappers short-circuit instead. Any element type can be stored; oneMKL operations still requireFloat32/Float64/ComplexF32/ComplexF64withInt32/Int64indices and throw a clear error otherwise. CSC matrices on oneMKL < 2025.3 now error at the first oneMKL operation instead of at construction.lib/mkl/sparse_conversions.jl): CSR↔CSC↔COO,_sptranspose/_spadjoint, sparse+/-(needed by GPUArrays'issymmetric, since oneMKL has nogeam-like routine), and the COO operations GPUArrays forwards to (triu,tril,kron,reshape,droptol!), built fromsortpermon integer keys and broadcasts.get_backend, andadapt(oneArray, ::SparseMatrixCSC)returning aoneSparseMatrixCSC(as CUDA.jl and AMDGPU.jl do). This is a behavior change: previously the sparse matrix was densified.test/onemkl.jlgains interface, conversion, broadcast/reduction and lazy-handle tests.Notes