Add CUDA GPU tests for AD gradient computation#84
Add CUDA GPU tests for AD gradient computation#84zazabap wants to merge 1 commit intoJuliaManifolds:mainfrom
Conversation
New test_cuda_ext.jl verifying RiemannianProjectionBackend(AutoZygote()) works correctly on CuArrays. ForwardDiff is incompatible with CuArrays due to scalar indexing in seed!; only Zygote (reverse-mode) is tested. 11 tests: Euclidean gradient (Float64/Float32), Sphere Riemannian gradient with tangent space verification, CPU-vs-GPU equivalence, quadratic objective with known analytical solution.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #84 +/- ##
=======================================
Coverage 95.69% 95.69%
=======================================
Files 13 13
Lines 395 395
=======================================
Hits 378 378
Misses 17 17 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Thanks for that, the two tests missing are
|
|
I have ideas on how to make ForwardDiff gradients work on GPUs via DI, if you're interested. It was low-priority but it wouldn't take long for me to implement |
|
Help on that side would be very welcome. |
|
If you check out the branch from JuliaDiff/DifferentiationInterface.jl#974 and use |
Summary
Add GPU tests verifying that the AD gradient pipeline (
RiemannianProjectionBackend) works correctly withCuArrayinputs. 11 tests, all verified passing on RTX 3090.No code changes to ManifoldDiff.jl itself — the library already works on GPU because it delegates to DifferentiationInterface.jl and ManifoldsBase operations. This PR adds test coverage to verify and document this.
What works on GPU
RiemannianProjectionBackend(AutoZygote())RiemannianProjectionBackend(AutoForwardDiff())seed!uses scalar indexing — fundamental limitation, not version-specificOperations tested
ManifoldDiff.gradient(M, f, p, backend)ManifoldDiff.gradient(M, f, p, backend)isapprox(Array(gpu), cpu; atol=1e-12)End-to-end GPU solver pipeline
With ManifoldDiff + Manifolds CUDA ext + Manopt
_produce_type(#577):This works transparently with CuArrays when Zygote is the AD backend.
Tests: 11/11 verified passing
grad isa CuArray{Float64}, matches analyticalpgrad isa CuArray{Float32}, correct withatol=1e-4dot(grad, p) ≈ 0, matchesa - dot(a,p)*pisapprox(Array(grad_gpu), grad_cpu; atol=1e-12)grad = p - target, verified against analytical solutionAll tests use
dot(a, p)instead ofp[1]to avoid scalar indexing on Sphere.All tests gracefully skip when CUDA/Zygote is not available.
Changes
test/test_cuda_ext.jl— new test file (11 tests)test/runtests.jl— addedinclude("test_cuda_ext.jl")Project.toml— added CUDA to[compat],[extras], and[targets]