Skip to content

Conversation

@gdalle
Copy link
Member

@gdalle gdalle commented Jun 10, 2025

Combining this small fix with gdalle/SparseMatrixColorings.jl#253, we can perform sparse autodiff on NVIDIA GPUs and leverage CUDA's native sparse matrices:

using ADTypes
using CUDA, CUDA.CUSPARSE
using DifferentiationInterface
using ForwardDiff: ForwardDiff
using LinearAlgebra
using SparseMatrixColorings

x = CuVector(rand(Float32, 10))
S = CuSparseMatrixCSR(Diagonal(ones(Float32, 10)))

sparsity_detector = ADTypes.KnownJacobianSparsityDetector(S)  # make sure the sparsity pattern is a CUDA sparse matrix
coloring_algorithm = GreedyColoringAlgorithm()
backend = AutoSparse(AutoForwardDiff(); sparsity_detector, coloring_algorithm)
julia> prep = prepare_jacobian(identity, backend, x);

julia> jacobian(identity, prep, backend, x)
10×10 CuSparseMatrixCSR{Float32, Int32} with 10 stored entries:
 1.0                                    
     1.0                                
         1.0                            
             1.0                        
                 1.0                    
                     1.0                
                         1.0            
                             1.0        
                                 1.0    
                                     1.0

@gdalle gdalle added skipci Don't run CI tests and docs gpu Run GPU tests with buildkite and removed skipci Don't run CI tests and docs labels Jun 10, 2025
@codecov
Copy link

codecov bot commented Jun 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.93%. Comparing base (d8905f5) to head (34019b5).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #810      +/-   ##
==========================================
- Coverage   97.93%   97.93%   -0.01%     
==========================================
  Files         128      128              
  Lines        7693     7690       -3     
==========================================
- Hits         7534     7531       -3     
  Misses        159      159              
Flag Coverage Δ
DI 98.81% <100.00%> (-0.01%) ⬇️
DIT 95.61% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 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.

@gdalle gdalle marked this pull request as ready for review June 10, 2025 16:36
@gdalle gdalle merged commit 272eeb5 into main Jun 10, 2025
68 of 72 checks passed
@gdalle gdalle deleted the gd/gpusparse branch June 10, 2025 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gpu Run GPU tests with buildkite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant