Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix automated conversion in adaptive solve #317

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
18 changes: 16 additions & 2 deletions src/ensemblegpukernel/lowerlevel_solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,27 @@ function vectorized_asolve(probs, prob::ODEProblem, alg;
us = allocate(backend, typeof(prob.u0), (len, length(probs)))
else
saveat = if saveat isa AbstractRange
range(convert(eltype(prob.tspan), first(saveat)),
_saveat = range(convert(eltype(prob.tspan), first(saveat)),
convert(eltype(prob.tspan), last(saveat)),
length = length(saveat))
convert(StepRangeLen{
eltype(_saveat),
eltype(_saveat),
eltype(_saveat),
eltype(_saveat) === Float32 ? Int32 : Int64,
},
_saveat)
elseif saveat isa AbstractVector
adapt(backend, convert.(eltype(prob.tspan), saveat))
else
prob.tspan[1]:convert(eltype(prob.tspan), saveat):prob.tspan[end]
_saveat = prob.tspan[1]:convert(eltype(prob.tspan), saveat):prob.tspan[end]
convert(StepRangeLen{
eltype(_saveat),
eltype(_saveat),
eltype(_saveat),
eltype(_saveat) === Float32 ? Int32 : Int64,
},
_saveat)
end
ts = allocate(backend, typeof(dt), (length(saveat), length(probs)))
fill!(ts, prob.tspan[1])
Expand Down
34 changes: 15 additions & 19 deletions test/gpu_kernel_de/conversions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,21 @@ prob = ODEProblem{false}(lorenz, u0, tspan, p)
prob_func = (prob, i, repeat) -> remake(prob, p = (@SVector rand(Float32, 3)) .* p)
monteprob = EnsembleProblem(prob, prob_func = prob_func, safetycopy = false)

## Don't test the problems in which GPUs don't support FP64 completely yet
## Creating StepRangeLen causes some param types to be FP64 inferred by `float` function
if ENV["GROUP"] ∉ ("Metal", "oneAPI")
@test solve(monteprob, GPUTsit5(), EnsembleGPUKernel(backend),
trajectories = 10_000,
saveat = 1:10)[1].t == Float32.(1:10)

@test solve(monteprob, GPUTsit5(), EnsembleGPUKernel(backend),
trajectories = 10_000,
saveat = 1:0.1:10)[1].t == 1.0f0:0.1f0:10.0f0

@test solve(monteprob, GPUTsit5(), EnsembleGPUKernel(backend),
trajectories = 10_000,
saveat = 1:(1.0f0):10)[1].t == 1:1.0f0:10

@test solve(monteprob, GPUTsit5(), EnsembleGPUKernel(backend),
trajectories = 10_000,
saveat = 1.0)[1].t == 0.0f0:1.0f0:10.0f0
end
@test solve(monteprob, GPUTsit5(), EnsembleGPUKernel(backend),
trajectories = 10_000,
saveat = 1:10)[1].t == Float32.(1:10)

@test solve(monteprob, GPUTsit5(), EnsembleGPUKernel(backend),
trajectories = 10_000,
saveat = 1:0.1:10)[1].t == 1.0f0:0.1f0:10.0f0

@test solve(monteprob, GPUTsit5(), EnsembleGPUKernel(backend),
trajectories = 10_000,
saveat = 1:(1.0f0):10)[1].t == 1:1.0f0:10

@test solve(monteprob, GPUTsit5(), EnsembleGPUKernel(backend),
trajectories = 10_000,
saveat = 1.0)[1].t == 0.0f0:1.0f0:10.0f0

@test solve(monteprob, GPUTsit5(), EnsembleGPUKernel(backend),
trajectories = 10_000,
Expand Down