Skip to content

Commit 4797dd2

Browse files
Move ForwardDiff CUDA error handling outside @testset
The @testset for-loop wraps each iteration body in its own try-catch, intercepting the CUDA error before the inner try-catch can handle it. Move the try-catch into a helper function called before the testset body, so the CUDA alignment error is caught cleanly. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 8f3b7b4 commit 4797dd2

File tree

1 file changed

+30
-16
lines changed

1 file changed

+30
-16
lines changed

test/gpu_kernel_de/forward_diff.jl

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,28 +35,42 @@ monteprob = EnsembleProblem(prob, prob_func = prob_func, safetycopy = false)
3535
# NOTE: On some CUDA GPUs (e.g. V100), SVector{3, ForwardDiff.Dual{Nothing, Float32, 6}}
3636
# triggers a misaligned address error (CUDA error code 716) due to the 84-byte element size
3737
# not satisfying GPU memory alignment requirements. This is a CUDA.jl issue, not DiffEqGPU.
38-
@testset "ForwardDiff with $alg" for alg in (
38+
# Test that the solve either succeeds or fails with the known alignment error.
39+
function try_solve(monteprob, alg, backend; kwargs...)
40+
try
41+
sol = solve(monteprob, alg, EnsembleGPUKernel(backend, 0.0); kwargs...)
42+
return sol
43+
catch e
44+
if occursin("misaligned address", string(e))
45+
return nothing # Known CUDA alignment issue
46+
else
47+
rethrow(e)
48+
end
49+
end
50+
end
51+
52+
for alg in (
3953
GPUTsit5(), GPUVern7(), GPUVern9(), GPURosenbrock23(autodiff = false),
4054
GPURodas4(autodiff = false), GPURodas5P(autodiff = false),
4155
GPUKvaerno3(autodiff = false), GPUKvaerno5(autodiff = false),
4256
)
4357
@info alg
44-
try
45-
sol = solve(
46-
monteprob, alg, EnsembleGPUKernel(backend, 0.0),
47-
trajectories = 2, save_everystep = false, adaptive = false, dt = 0.01f0
48-
)
58+
sol = try_solve(
59+
monteprob, alg, backend,
60+
trajectories = 2, save_everystep = false, adaptive = false, dt = 0.01f0
61+
)
62+
if sol !== nothing
4963
@test length(sol) == 2
50-
asol = solve(
51-
monteprob, alg, EnsembleGPUKernel(backend, 0.0),
52-
trajectories = 2, adaptive = true, dt = 0.01f0
53-
)
64+
else
65+
@test_broken false # Known CUDA alignment issue with ForwardDiff Duals
66+
end
67+
asol = try_solve(
68+
monteprob, alg, backend,
69+
trajectories = 2, adaptive = true, dt = 0.01f0
70+
)
71+
if asol !== nothing
5472
@test length(asol) == 2
55-
catch e
56-
if occursin("misaligned address", string(e))
57-
@test_broken false # Known CUDA alignment issue with ForwardDiff Duals
58-
else
59-
rethrow(e)
60-
end
73+
else
74+
@test_broken false # Known CUDA alignment issue with ForwardDiff Duals
6175
end
6276
end

0 commit comments

Comments
 (0)