Repository navigation
Conversation
maleadt
force-pushed
the
tb/sparse
branch
5 times, most recently
from
October 21, 2026 17:39
c15be39 to
4e837cb
Compare
GPUArrays now implements the sparse formats generically, parametrized on their storage, so Metal only names them for MtlVector storage (MtlSparseVector, MtlSparseMatrixCSR/CSC/COO) and decides what mtl does with host sparse arrays: matrices become CSR, indices Int32 when they fit, and values follow the dense narrowing rules. Structural adapt(MtlArray, S) keeps the format and types without Metal code. This requires GPUArrays 13 (JuliaGPU/GPUArrays.jl#745).
Constructors on the aliases move their input to Metal, keeping its format and types, and convert on the device; with explicit element types, host inputs are converted on the host first so that Float64 data can be used. MtlArray(A) densifies a sparse array on the device instead of copying through the host. The usage page explains mtl's transfer policy, the operations, and which format suits which operation.
materialize! and copyto! for MtlArrayStyle broadcasts accepted any destination. With GPUArrays sparse arrays, which broadcast into Metal storage but are not AbstractGPUArrays, that is ambiguous with GPUArrays' in-place sparse broadcast and would run the dense kernel over the sparse array's elements. Restrict both to GPU arrays and wrappers of them; other destinations take the generic path.
Sparse array support needs GPUArrays 13, which is not a breaking change for Metal itself.
GPUArrays 13 is not registered yet. Drop this commit before merging.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #982 +/- ##
==========================================
- Coverage 88.86% 83.68% -5.18%
==========================================
Files 105 105
Lines 9399 8843 -556
==========================================
- Hits 8352 7400 -952
- Misses 1047 1443 +396 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch has not been deployed
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.
Metal.jl gets sparse vectors and matrices. GPUArrays 13 implements them for every back-end (JuliaGPU/GPUArrays.jl#745), and this PR names them for Metal storage and moves host sparse arrays to the GPU.
MtlSparseVectorandMtlSparseMatrixCSR/CSC/COOare aliases of the GPUArrays types withMtlVectorstorage.mtl(::SparseMatrixCSC)gives CSR, the best format forA * x. It usesInt32indices when they fit, and narrowsFloat64values like it does for dense arrays.adapt(MtlArray, A)keeps the format and types.Float64data works.MtlArray(A)densifies on the device.There is no vendor sparse library, so all products use GPUArrays' portable kernels. This is a minor release (1.13.0); Metal had no sparse support before. It supersedes #909.
Tested on an M1 and an M3 Pro (Julia 1.13): Metal's sparse tests (53) and GPUArrays' shared sparse testsuite on
MtlArray(12,365), against GPUArraystb/sparse. The package also loads on Julia 1.10.The last commit (
TEMP) points CI at the unregistered GPUArrays branch. Drop it before merging.