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

Manually union split chunksize calculation #1536

Closed
wants to merge 4 commits into from
Closed
Changes from 3 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
23 changes: 22 additions & 1 deletion src/alg_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,31 @@ function DiffEqBase.prepare_alg(alg::Union{OrdinaryDiffEqAdaptiveImplicitAlgorit
if typeof(alg) <: OrdinaryDiffEqImplicitExtrapolationAlgorithm
return alg # remake fails, should get fixed
else
remake(alg,chunk_size=Val{ForwardDiff.pickchunksize(x)}())
L = ArrayInterface.known_length(typeof(u0))
if L === nothing # dynamic sized
chunk_size = ForwardDiff.pickchunksize(x)
if chunk_size > 8
cs = Val{8}()
remake(alg,chunk_size=cs)
elseif chunk_size > 4
ChrisRackauckas marked this conversation as resolved.
Show resolved Hide resolved
cs = Val{4}()
remake(alg,chunk_size=cs)
else
Copy link
Contributor

@chriselrod chriselrod Dec 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth adding branches for 2 and 3? It'd cost some compile time, but I'm worried about possible runtime regressions for small problems.

This comment is also conditional on max_methods.
Currently, you're getting a union of 3 return types.
That breaks when we set max_methods<3 (e.g. =1).

My proposal (5 return types) breaks currently. Hence, the above comment on performing this split at a point of return type convergence.

cs = Val{1}()
remake(alg,chunk_size=cs)
end
else # statically sized
chunk_size = pick_static_chunksize(Val{L}())
remake(alg,chunk_size=cs)
end
end
end

@generated function pick_static_chunksize(::Val{chunksize}) where chunksize
x = ForwardDiff.pickchunksize(chunksize)
:(Val{$x}())
end

function DiffEqBase.prepare_alg(alg::CompositeAlgorithm,u0,p,prob)
algs = map(alg -> DiffEqBase.prepare_alg(alg, u0, p, prob), alg.algs)
CompositeAlgorithm(algs, alg.choice_function)
Expand Down