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

Better inference #169

Merged
merged 1 commit into from
Dec 8, 2021
Merged

Better inference #169

merged 1 commit into from
Dec 8, 2021

Conversation

YingboMa
Copy link
Member

@YingboMa YingboMa commented Dec 8, 2021

Before:

julia> itrigs = inference_triggers(tinf)
6-element Vector{InferenceTrigger}:
 Inference triggered to call CommonSolve.solve(::ODEProblem{Vector{Fl, ::Rodas5{3, true, Defa) from eval (./boot.jl:373) inlined into REPL.eval_user_input(::Any, ::REPL.REPLBackend) (/Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.7/REPL/src/REPL.jl:150)
 Inference triggered to call OrdinaryDiffEq.build_J_W(::Rodas5{3, true, Defa, ::Vector{Float64}, ::Vector{Float64}, ::SciMLBase.NullParame, ::Float64, ::Float64, ::ODEFunction{true, ty, ::Type, ::Val{true}) from alg_cache (/Users/scheme/.julia/packages/OrdinaryDiffEq/6gTvi/src/caches/rosenbrock_caches.jl:581) with specialization OrdinaryDiffEq.alg_cache(::Rodas5{3, true, Defa, ::Vector{Float64}, ::Vector{Float64}, ::Type{Float64}, ::Type{Float64}, ::Type{Float64}, ::Vector{Float64}, ::Vector{Float64}, ::ODEFunction{true, ty, ::Float64, ::Float64, ::Float64, ::SciMLBase.NullParame, ::Bool, ::Val{true})
 Inference triggered to call setindex!(::Vector{Tuple{Float64, ::Tuple{Bool, Bool, Bo, ::Int64) from generate_chunked_partials (/Users/scheme/src/julia/SparseDiffTools/src/differentiation/compute_jacobian_ad.jl:75) with specialization SparseDiffTools.generate_chunked_partials(::Vector{Float64}, ::UnitRange{Int64}, ::Val{3})
 Inference triggered to call unsafe_copyto!(::Matrix{Float64}, ::Int64, ::Matrix{Float64}, ::Int64, ::Int64) from _copyto_impl! (./array.jl:331) inlined into OrdinaryDiffEq.calc_W!(::Matrix{Float64}, ::OrdinaryDiffEq.ODEIn, ::Nothing, ::OrdinaryDiffEq.Rosen, ::Float64, ::Bool, ::Bool) (/Users/scheme/.julia/packages/OrdinaryDiffEq/6gTvi/src/derivative_utils.jl:503)
 Inference triggered to call DiffEqBase.var"#_#31"(::Nothing, ::Base.Pairs{Symbol, U, ::DefaultLinSolve, ::Vector{Float64}, ::Matrix{Float64}, ::Vector{Float64}, ::Bool) from DefaultLinSolve (/Users/scheme/.julia/packages/DiffEqBase/b1nST/src/linear_nonlinear.jl:94) inlined into OrdinaryDiffEq.perform_step!(::OrdinaryDiffEq.ODEIn, ::OrdinaryDiffEq.Rosen, ::Bool) (/Users/scheme/.julia/packages/OrdinaryDiffEq/6gTvi/src/perform_step/rosenbrock_perform_step.jl:1577)
 Inference triggered to call LinearAlgebra.var"#generic_lufact!#152"(::Bool, ::typeof(LinearAlgebra, ::Matrix{Float64}, ::LinearAlgebra.RowMax) from generic_lufact!##kw (/Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.7/LinearAlgebra/src/lu.jl:139) inlined into DiffEqBase.var"#_#31"(::Nothing, ::Base.Pairs{Symbol, U, ::DefaultLinSolve, ::Vector{Float64}, ::Matrix{Float64}, ::Vector{Float64}, ::Bool) (/Users/scheme/.julia/packages/DiffEqBase/b1nST/src/linear_nonlinear.jl:112)

After:

julia> itrigs = inference_triggers(tinf)
5-element Vector{InferenceTrigger}:
 Inference triggered to call CommonSolve.solve(::ODEProblem{Vector{Fl, ::Rodas5{3, true, Defa) from eval (./boot.jl:373) inlined into REPL.eval_user_input(::Any, ::REPL.REPLBackend) (/Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.7/REPL/src/REPL.jl:150)
 Inference triggered to call OrdinaryDiffEq.build_J_W(::Rodas5{3, true, Defa, ::Vector{Float64}, ::Vector{Float64}, ::SciMLBase.NullParame, ::Float64, ::Float64, ::ODEFunction{true, ty, ::Type, ::Val{true}) from alg_cache (/Users/scheme/.julia/packages/OrdinaryDiffEq/6gTvi/src/caches/rosenbrock_caches.jl:581) with specialization OrdinaryDiffEq.alg_cache(::Rodas5{3, true, Defa, ::Vector{Float64}, ::Vector{Float64}, ::Type{Float64}, ::Type{Float64}, ::Type{Float64}, ::Vector{Float64}, ::Vector{Float64}, ::ODEFunction{true, ty, ::Float64, ::Float64, ::Float64, ::SciMLBase.NullParame, ::Bool, ::Val{true})
 Inference triggered to call unsafe_copyto!(::Matrix{Float64}, ::Int64, ::Matrix{Float64}, ::Int64, ::Int64) from _copyto_impl! (./array.jl:331) inlined into OrdinaryDiffEq.calc_W!(::Matrix{Float64}, ::OrdinaryDiffEq.ODEIn, ::Nothing, ::OrdinaryDiffEq.Rosen, ::Float64, ::Bool, ::Bool) (/Users/scheme/.julia/packages/OrdinaryDiffEq/6gTvi/src/derivative_utils.jl:503)
 Inference triggered to call DiffEqBase.var"#_#31"(::Nothing, ::Base.Pairs{Symbol, U, ::DefaultLinSolve, ::Vector{Float64}, ::Matrix{Float64}, ::Vector{Float64}, ::Bool) from DefaultLinSolve (/Users/scheme/.julia/packages/DiffEqBase/b1nST/src/linear_nonlinear.jl:94) inlined into OrdinaryDiffEq.perform_step!(::OrdinaryDiffEq.ODEIn, ::OrdinaryDiffEq.Rosen, ::Bool) (/Users/scheme/.julia/packages/OrdinaryDiffEq/6gTvi/src/perform_step/rosenbrock_perform_step.jl:1577)
 Inference triggered to call LinearAlgebra.var"#generic_lufact!#152"(::Bool, ::typeof(LinearAlgebra, ::Matrix{Float64}, ::LinearAlgebra.RowMax) from generic_lufact!##kw (/Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.7/LinearAlgebra/src/lu.jl:139) inlined into DiffEqBase.var"#_#31"(::Nothing, ::Base.Pairs{Symbol, U, ::DefaultLinSolve, ::Vector{Float64}, ::Matrix{Float64}, ::Vector{Float64}, ::Bool) (/Users/scheme/.julia/packages/DiffEqBase/b1nST/src/linear_nonlinear.jl:112)

Before:
```julia
julia> itrigs = inference_triggers(tinf)
6-element Vector{InferenceTrigger}:
 Inference triggered to call CommonSolve.solve(::ODEProblem{Vector{Fl, ::Rodas5{3, true, Defa) from eval (./boot.jl:373) inlined into REPL.eval_user_input(::Any, ::REPL.REPLBackend) (/Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.7/REPL/src/REPL.jl:150)
 Inference triggered to call OrdinaryDiffEq.build_J_W(::Rodas5{3, true, Defa, ::Vector{Float64}, ::Vector{Float64}, ::SciMLBase.NullParame, ::Float64, ::Float64, ::ODEFunction{true, ty, ::Type, ::Val{true}) from alg_cache (/Users/scheme/.julia/packages/OrdinaryDiffEq/6gTvi/src/caches/rosenbrock_caches.jl:581) with specialization OrdinaryDiffEq.alg_cache(::Rodas5{3, true, Defa, ::Vector{Float64}, ::Vector{Float64}, ::Type{Float64}, ::Type{Float64}, ::Type{Float64}, ::Vector{Float64}, ::Vector{Float64}, ::ODEFunction{true, ty, ::Float64, ::Float64, ::Float64, ::SciMLBase.NullParame, ::Bool, ::Val{true})
 Inference triggered to call setindex!(::Vector{Tuple{Float64, ::Tuple{Bool, Bool, Bo, ::Int64) from generate_chunked_partials (/Users/scheme/src/julia/SparseDiffTools/src/differentiation/compute_jacobian_ad.jl:75) with specialization SparseDiffTools.generate_chunked_partials(::Vector{Float64}, ::UnitRange{Int64}, ::Val{3})
 Inference triggered to call unsafe_copyto!(::Matrix{Float64}, ::Int64, ::Matrix{Float64}, ::Int64, ::Int64) from _copyto_impl! (./array.jl:331) inlined into OrdinaryDiffEq.calc_W!(::Matrix{Float64}, ::OrdinaryDiffEq.ODEIn, ::Nothing, ::OrdinaryDiffEq.Rosen, ::Float64, ::Bool, ::Bool) (/Users/scheme/.julia/packages/OrdinaryDiffEq/6gTvi/src/derivative_utils.jl:503)
 Inference triggered to call DiffEqBase.var"#_#31"(::Nothing, ::Base.Pairs{Symbol, U, ::DefaultLinSolve, ::Vector{Float64}, ::Matrix{Float64}, ::Vector{Float64}, ::Bool) from DefaultLinSolve (/Users/scheme/.julia/packages/DiffEqBase/b1nST/src/linear_nonlinear.jl:94) inlined into OrdinaryDiffEq.perform_step!(::OrdinaryDiffEq.ODEIn, ::OrdinaryDiffEq.Rosen, ::Bool) (/Users/scheme/.julia/packages/OrdinaryDiffEq/6gTvi/src/perform_step/rosenbrock_perform_step.jl:1577)
 Inference triggered to call LinearAlgebra.var"#generic_lufact!#152"(::Bool, ::typeof(LinearAlgebra, ::Matrix{Float64}, ::LinearAlgebra.RowMax) from generic_lufact!##kw (/Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.7/LinearAlgebra/src/lu.jl:139) inlined into DiffEqBase.var"#_#31"(::Nothing, ::Base.Pairs{Symbol, U, ::DefaultLinSolve, ::Vector{Float64}, ::Matrix{Float64}, ::Vector{Float64}, ::Bool) (/Users/scheme/.julia/packages/DiffEqBase/b1nST/src/linear_nonlinear.jl:112)
```

After:
```julia
julia> itrigs = inference_triggers(tinf)
5-element Vector{InferenceTrigger}:
 Inference triggered to call CommonSolve.solve(::ODEProblem{Vector{Fl, ::Rodas5{3, true, Defa) from eval (./boot.jl:373) inlined into REPL.eval_user_input(::Any, ::REPL.REPLBackend) (/Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.7/REPL/src/REPL.jl:150)
 Inference triggered to call OrdinaryDiffEq.build_J_W(::Rodas5{3, true, Defa, ::Vector{Float64}, ::Vector{Float64}, ::SciMLBase.NullParame, ::Float64, ::Float64, ::ODEFunction{true, ty, ::Type, ::Val{true}) from alg_cache (/Users/scheme/.julia/packages/OrdinaryDiffEq/6gTvi/src/caches/rosenbrock_caches.jl:581) with specialization OrdinaryDiffEq.alg_cache(::Rodas5{3, true, Defa, ::Vector{Float64}, ::Vector{Float64}, ::Type{Float64}, ::Type{Float64}, ::Type{Float64}, ::Vector{Float64}, ::Vector{Float64}, ::ODEFunction{true, ty, ::Float64, ::Float64, ::Float64, ::SciMLBase.NullParame, ::Bool, ::Val{true})
 Inference triggered to call unsafe_copyto!(::Matrix{Float64}, ::Int64, ::Matrix{Float64}, ::Int64, ::Int64) from _copyto_impl! (./array.jl:331) inlined into OrdinaryDiffEq.calc_W!(::Matrix{Float64}, ::OrdinaryDiffEq.ODEIn, ::Nothing, ::OrdinaryDiffEq.Rosen, ::Float64, ::Bool, ::Bool) (/Users/scheme/.julia/packages/OrdinaryDiffEq/6gTvi/src/derivative_utils.jl:503)
 Inference triggered to call DiffEqBase.var"#_#31"(::Nothing, ::Base.Pairs{Symbol, U, ::DefaultLinSolve, ::Vector{Float64}, ::Matrix{Float64}, ::Vector{Float64}, ::Bool) from DefaultLinSolve (/Users/scheme/.julia/packages/DiffEqBase/b1nST/src/linear_nonlinear.jl:94) inlined into OrdinaryDiffEq.perform_step!(::OrdinaryDiffEq.ODEIn, ::OrdinaryDiffEq.Rosen, ::Bool) (/Users/scheme/.julia/packages/OrdinaryDiffEq/6gTvi/src/perform_step/rosenbrock_perform_step.jl:1577)
 Inference triggered to call LinearAlgebra.var"#generic_lufact!#152"(::Bool, ::typeof(LinearAlgebra, ::Matrix{Float64}, ::LinearAlgebra.RowMax) from generic_lufact!##kw (/Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.7/LinearAlgebra/src/lu.jl:139) inlined into DiffEqBase.var"#_#31"(::Nothing, ::Base.Pairs{Symbol, U, ::DefaultLinSolve, ::Vector{Float64}, ::Matrix{Float64}, ::Vector{Float64}, ::Bool) (/Users/scheme/.julia/packages/DiffEqBase/b1nST/src/linear_nonlinear.jl:112)
```
Copy link
Contributor

@chriselrod chriselrod left a comment

Choose a reason for hiding this comment

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

Sad that this is needed, but closures...

@ChrisRackauckas
Copy link
Member

And with all of the latest updates in SciMLBase and OrdinaryDiffEq, this is down to:

julia> itrigs = inference_triggers(tinf)
1-element Vector{InferenceTrigger}:
 Inference triggered to call OrdinaryDiffEq.jacobian2W!(::Matrix{Float64}, ::LinearAlgebra.UniformScaling{Bool}, ::Float64, ::Matrix{Float64}, ::Bool) called from toplevel

Literally one inference trigger, and it's a snoopcompile bug. Awesome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants