Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions test/alloc_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -42,35 +44,35 @@ 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
u = @SVector [1.0f0, 2.0f0, 3.0f0]
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
u = 3.14f0
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
10 changes: 3 additions & 7 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Loading