GPUifyLoops.jl
GPUifyLoops.jl copied to clipboard
Return of ODESolution type fails
With https://github.com/JuliaDiffEq/DiffEqBase.jl/pull/240 and SimpleDiffEq#master, the entire returned object is immutable. However, it segfaults when it returns. But, returning it's solution array, sol.u, is fine.
using GPUifyLoops, CuArrays, SimpleDiffEq
using StaticArrays, Cthulhu
function loop(u, p, t)
@inbounds begin
σ = p[1]; ρ = p[2]; β = p[3]
du1 = σ*(u[2]-u[1])
du2 = u[1]*(ρ-u[3]) - u[2]
du3 = u[1]*u[2] - β*u[3]
return SVector{3}(du1, du2, du3)
end
end
function liip(du, u, p, t)
σ = p[1]; ρ = p[2]; β = p[3]
du[1] = σ*(u[2]-u[1])
du[2] = u[1]*(ρ-u[3]) - u[2]
du[3] = u[1]*u[2] - β*u[3]
return nothing
end
u0 = 10ones(Float32,3)
const su0= SVector{3}(u0)
const dt = 1f-1
odeoop = ODEProblem{false}(loop, SVector{3}(u0), (0.0f0, 10.0f0), Float32[10, 28, 8/3])
sol2 = solve(odeoop,GPUSimpleTsit5(),dt=dt)
ps = CuArray([@SVector [10f0,28f0,8/3f0] for i in 1:10])
CuArrays.allowscalar(false)
function f(p)
prob = ODEProblem{false}(loop, su0, (0.0f0, 10.0f0), p)
solve(prob,GPUSimpleTsit5(),dt=dt).u
end
_f = GPUifyLoops.contextualize(f)
map(_f,ps)
function f2(p)
prob = ODEProblem{false}(loop, su0, (0.0f0, 10.0f0), p)
solve(prob,GPUSimpleTsit5(),dt=dt)
end
_f2 = GPUifyLoops.contextualize(f2)
map(_f2,ps)
Maybe I am on the wrong branch, but I am getting
julia> sol2 = solve(odeoop,GPUSimpleTsit5(),dt=dt)
ERROR: MethodError: Cannot `convert` an object of type Nothing to an object of type DiffEqBase.DEStats
Closest candidates are:
convert(::Type{T}, ::T) where T at essentials.jl:154
DiffEqBase.DEStats(::Any) at /home/vchuravy/.julia/packages/DiffEqBase/6ewdP/src/destats.jl:15
DiffEqBase.DEStats(::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any) at /home/vchuravy/.julia/packages/DiffEqBase/6ewdP/src/destats.jl:2
Stacktrace:
[1] ODESolution{Float32,2,SArray{Tuple{101},SArray{Tuple{3},Float32,1,3},1,101},Nothing,Nothing,StepRangeLen{Float32,Float64,Float64},Nothing,ODEProblem{SArray{Tuple{3},Float32,1,3},Tuple{Float32,Float32},false,Array{Float32,1},ODEFunction{false,typeof(loop),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Nothing,DiffEqBase.StandardODEProblem},GPUSimpleTsit5,DiffEqBase.LinearInterpolation{StepRangeLen{Float32,Float64,Float64},SArray{Tuple{101},SArray{Tuple{3},Float32,1,3},1,101}}}(::SArray{Tuple{101},SArray{Tuple{3},Float32,1,3},1,101}, ::Nothing, ::Nothing, ::StepRangeLen{Float32,Float64,Float64}, ::Nothing, ::ODEProblem{SArray{Tuple{3},Float32,1,3},Tuple{Float32,Float32},false,Array{Float32,1},ODEFunction{false,typeof(loop),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Nothing,DiffEqBase.StandardODEProblem}, ::GPUSimpleTsit5, ::Function, ::Bool, ::Int64, ::Nothing, ::Symbol) at /home/vchuravy/.julia/packages/DiffEqBase/6ewdP/src/solutions/ode_solutions.jl:2
[2] #build_solution#14(::Bool, ::Bool, ::Bool, ::Bool, ::Nothing, ::Function, ::Symbol, ::Nothing, ::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::typeof(DiffEqBase.build_solution), ::ODEProblem{SArray{Tuple{3},Float32,1,3},Tuple{Float32,Float32},false,Array{Float32,1},ODEFunction{false,typeof(loop),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Nothing,DiffEqBase.StandardODEProblem}, ::GPUSimpleTsit5, ::StepRangeLen{Float32,Float64,Float64}, ::SArray{Tuple{101},SArray{Tuple{3},Float32,1,3},1,101}) at /home/vchuravy/.julia/packages/DiffEqBase/6ewdP/src/solutions/ode_solutions.jl:57
[3] (::getfield(DiffEqBase, Symbol("#kw##build_solution")))(::NamedTuple{(:k, :destats, :calculate_error),Tuple{Nothing,Nothing,Bool}}, ::typeof(DiffEqBase.build_solution), ::ODEProblem{SArray{Tuple{3},Float32,1,3},Tuple{Float32,Float32},false,Array{Float32,1},ODEFunction{false,typeof(loop),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Nothing,DiffEqBase.StandardODEProblem}, ::GPUSimpleTsit5, ::StepRangeLen{Float32,Float64,Float64}, ::SArray{Tuple{101},SArray{Tuple{3},Float32,1,3},1,101}) at ./none:0
[4] #solve#25(::Float32, ::Float32, ::Float32, ::Function, ::ODEProblem{SArray{Tuple{3},Float32,1,3},Tuple{Float32,Float32},false,Array{Float32,1},ODEFunction{false,typeof(loop),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Nothing,DiffEqBase.StandardODEProblem}, ::GPUSimpleTsit5) at /home/vchuravy/.julia/packages/SimpleDiffEq/FTIOd/src/tsit5/gpuatsit5.jl:51
[5] (::getfield(DiffEqBase, Symbol("#kw##solve")))(::NamedTuple{(:dt,),Tuple{Float32}}, ::typeof(solve), ::ODEProblem{SArray{Tuple{3},Float32,1,3},Tuple{Float32,Float32},false,Array{Float32,1},ODEFunction{false,typeof(loop),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Nothing,DiffEqBase.StandardODEProblem}, ::GPUSimpleTsit5) at ./none:0
[6] top-level scope at none:0
ah yes wrong branch
So investigating with Cthulhu:
• %108 = invoke overdub(::Cassette.Context{…},::typeof(DiffEqBase.__has_syms){…},::typeof(loop){…})::Any
which calls fieldnames, which is not an inferrable function