diff --git a/test/alloc_tests.jl b/test/alloc_tests.jl index 50d09b54..d67a1691 100644 --- a/test/alloc_tests.jl +++ b/test/alloc_tests.jl @@ -7,6 +7,8 @@ using DiffEqGPU # Note: AllocCheck.@check_allocs is not compatible with GPU kernels and complex # dispatch, so we use @allocated instead for testing allocation counts. +# @allocated must be evaluated inside a function: measured at top-level scope, +# older Julia versions also count boxing the measured call's result. # Test Lorenz system for allocation tests function lorenz(u, p, t) @@ -26,11 +28,11 @@ end t = 0.0f0 # Warmup - lorenz(u, p, t) + measure() = @allocated lorenz(u, p, t) + measure() # Test allocations - allocs = @allocated lorenz(u, p, t) - @test allocs == 0 + @test measure() == 0 end @testset "make_prob_compatible should be low allocation" begin @@ -42,12 +44,12 @@ end prob = ODEProblem{false}(lorenz, u0, tspan, p) # Warmup - DiffEqGPU.make_prob_compatible(prob) + measure() = @allocated DiffEqGPU.make_prob_compatible(prob) + measure() # Test - some allocations are expected for problem conversion - allocs = @allocated DiffEqGPU.make_prob_compatible(prob) # Should be reasonably low (less than 1KB) - @test allocs < 1024 + @test measure() < 1024 end @testset "diffeqgpunorm should not allocate for SVector" begin @@ -55,11 +57,11 @@ end t = 0.0f0 # Warmup - DiffEqGPU.diffeqgpunorm(u, t) + measure() = @allocated DiffEqGPU.diffeqgpunorm(u, t) + measure() # Test allocations - allocs = @allocated DiffEqGPU.diffeqgpunorm(u, t) - @test allocs == 0 + @test measure() == 0 end @testset "diffeqgpunorm should not allocate for scalars" begin @@ -67,10 +69,10 @@ end t = 0.0f0 # Warmup - DiffEqGPU.diffeqgpunorm(u, t) + measure() = @allocated DiffEqGPU.diffeqgpunorm(u, t) + measure() # Test allocations - allocs = @allocated DiffEqGPU.diffeqgpunorm(u, t) - @test allocs == 0 + @test measure() == 0 end end diff --git a/test/runtests.jl b/test/runtests.jl index e26fe6b0..ac7e777f 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -136,6 +136,9 @@ if GROUP == "CPU" @time @safetestset "Adaptive endpoint termination" begin include("gpu_kernel_de/adaptive_endpoint.jl") end + @time @safetestset "Allocation Tests" begin + include("alloc_tests.jl") + end end if GROUP == "JLArrays" @@ -168,10 +171,3 @@ if GROUP == "CUDA" include("enzyme_environment.jl") end end - -# Allocation tests run separately to avoid precompilation interference -if GROUP == "all" || GROUP == "nopre" - @time @safetestset "Allocation Tests" begin - include("alloc_tests.jl") - end -end