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

Make the chunksize determination static when static #1540

Merged
merged 1 commit into from
Dec 11, 2021
Merged
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
14 changes: 13 additions & 1 deletion src/alg_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,22 @@ 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
cs = ForwardDiff.pickchunksize(x)
remake(alg,chunk_size=cs)
else # statically sized
cs = 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}())
Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW, Pumas has been relying on const prop for this, and that seems to be fine so far.

Copy link
Member Author

Choose a reason for hiding this comment

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

IIRC it caused a major performance change here 😅

Copy link
Contributor

Choose a reason for hiding this comment

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

I should double check Pumas, then.

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