-
-
Notifications
You must be signed in to change notification settings - Fork 119
Setup OpaqueClosures norecompile mode #745
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
Closed
Closed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The opaque closure version is faster? using OrdinaryDiffEq, BenchmarkTools
function f(du, u, p, t)
du[1] = 0.2u[1]
du[2] = 0.4u[2]
end
u0 = ones(2)
tspan = (0.0, 1.0)
prob = ODEProblem{true,false}(f, u0, tspan, Float64[])
prob2 = ODEProblem(lorenz, [1.0; 0.0; 0.0], (0.0, 1.0), Float64[])
alg1 = Rosenbrock23(autodiff=false)
alg2 = Rosenbrock23(chunk_size=1)
@benchmark sol = $solve($prob, $alg1)
@benchmark sol = $solve($prob2, $alg1)
@benchmark sol = $solve($prob, $alg2)
@benchmark sol = $solve($prob2, $alg2) julia> @benchmark sol = $solve($prob, $alg1)
BenchmarkTools.Trial: 10000 samples with 1 evaluation.
Range (min … max): 17.900 μs … 8.254 ms ┊ GC (min … max): 0.00% … 99.25%
Time (median): 20.100 μs ┊ GC (median): 0.00%
Time (mean ± σ): 23.709 μs ± 132.326 μs ┊ GC (mean ± σ): 9.58% ± 1.72%
▁▁█▃▇▁▂
▁▂▃████████▅▇▄▅▃▄▃▃▃▂▃▂▂▂▂▂▂▁▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ▂
17.9 μs Histogram: frequency by time 33.2 μs <
Memory estimate: 21.72 KiB, allocs estimate: 502.
julia> @benchmark sol = $solve($prob2, $alg1)
BenchmarkTools.Trial: 10000 samples with 1 evaluation.
Range (min … max): 89.400 μs … 7.018 ms ┊ GC (min … max): 0.00% … 98.08%
Time (median): 94.400 μs ┊ GC (median): 0.00%
Time (mean ± σ): 102.397 μs ± 160.294 μs ┊ GC (mean ± σ): 3.78% ± 2.40%
▅██▇▅▅▄▃▂▁▁ ▂
████████████▇▇█▇▆▇▆▆▅▄▆▅▄▅▄▃▆▅▅▄▅▅▅▁▄▄▅▄▄▃▁▁▆▄▄▅▅▄▅▆▆▅▆▅▆▅▁▄▅ █
89.4 μs Histogram: log(frequency) by time 212 μs <
Memory estimate: 49.11 KiB, allocs estimate: 1207.
julia> @benchmark sol = $solve($prob, $alg2)
BenchmarkTools.Trial: 10000 samples with 1 evaluation.
Range (min … max): 13.100 μs … 7.901 ms ┊ GC (min … max): 0.00% … 99.29%
Time (median): 15.600 μs ┊ GC (median): 0.00%
Time (mean ± σ): 19.110 μs ± 131.043 μs ┊ GC (mean ± σ): 11.79% ± 1.72%
▄▂█▂▆▁▃ ▁
▁▂▄▅███████▆█▅▇▄▇▄▅▄▅▃▃▂▃▂▂▂▂▂▂▂▁▂▁▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ▂
13.1 μs Histogram: frequency by time 28 μs <
Memory estimate: 24.81 KiB, allocs estimate: 419.
julia> @benchmark sol = $solve($prob2, $alg2)
BenchmarkTools.Trial: 10000 samples with 1 evaluation.
Range (min … max): 48.000 μs … 5.135 ms ┊ GC (min … max): 0.00% … 98.20%
Time (median): 50.800 μs ┊ GC (median): 0.00%
Time (mean ± σ): 58.643 μs ± 143.606 μs ┊ GC (mean ± σ): 7.26% ± 2.95%
█▂
▇██▄▃▃▃▃▃▃▃▃▃▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▁▁▂▂▁▂▂▁▂▂▂▁▁▁▁▁▂▂▁▁▁▁▂▂ ▂
48 μs Histogram: frequency by time 131 μs <
Memory estimate: 66.72 KiB, allocs estimate: 651. |
The MWE is "working": using OrdinaryDiffEq
function f(du, u, p, t)
du[1] = 0.2u[1]
du[2] = 0.4u[2]
end
u0 = ones(2)
tspan = (0.0, 1.0)
prob = ODEProblem{true,false}(f, u0, tspan, Float64[])
function lorenz(du, u, p, t)
du[1] = 10.0(u[2] - u[1])
du[2] = u[1] * (28.0 - u[3]) - u[2]
du[3] = u[1] * u[2] - (8 / 3) * u[3]
end
lorenzprob = ODEProblem{true,false}(lorenz, [1.0; 0.0; 0.0], (0.0, 1.0), Float64[])
typeof(prob) === typeof(lorenzprob) # true
@time sol = solve(prob, Rosenbrock23(autodiff=false))
@time sol = solve(prob, Rosenbrock23(chunk_size=1)) but the precompilation doesn't remove compilation time: 1.391319 seconds (5.64 M allocations: 309.916 MiB, 4.14% gc time, 99.88% compilation time)
1.240713 seconds (3.85 M allocations: 216.374 MiB, 3.14% gc time, 99.98% compilation time) |
using OrdinaryDiffEq
function f(du, u, p, t)
du[1] = 0.2u[1]
du[2] = 0.4u[2]
end
u0 = ones(2)
tspan = (0.0, 1.0)
prob = ODEProblem{true,false}(f, u0, tspan, Float64[])
function lorenz(du, u, p, t)
du[1] = 10.0(u[2] - u[1])
du[2] = u[1] * (28.0 - u[3]) - u[2]
du[3] = u[1] * u[2] - (8 / 3) * u[3]
end
lorenzprob = ODEProblem{true,false}(lorenz, [1.0; 0.0; 0.0], (0.0, 1.0), Float64[])
typeof(prob) === typeof(lorenzprob) # true
using Profile
@profile sol = solve(prob, Rosenbrock23(autodiff=false))
@profile sol = solve(prob, Rosenbrock23(chunk_size=1))
|
using OrdinaryDiffEq, SnoopCompile
function f(du, u, p, t)
du[1] = 0.2u[1]
du[2] = 0.4u[2]
end
u0 = ones(2)
tspan = (0.0, 1.0)
prob = ODEProblem{true,false}(f, u0, tspan, Float64[])
function lorenz(du, u, p, t)
du[1] = 10.0(u[2] - u[1])
du[2] = u[1] * (28.0 - u[3]) - u[2]
du[3] = u[1] * u[2] - (8 / 3) * u[3]
end
lorenzprob = ODEProblem{true,false}(lorenz, [1.0; 0.0; 0.0], (0.0, 1.0), Float64[])
typeof(prob) === typeof(lorenzprob) # true
alg = Rosenbrock23(chunk_size=1)
@snoopi_deep sol = solve(prob, alg)
InferenceTimingNode: 0.923631/1.610302 on Core.Compiler.Timings.ROOT() with 36 direct children |
Needs: - SciML/SciMLBase.jl#143 - SciML/OrdinaryDiffEq.jl#1627 ```julia using OrdinaryDiffEq function f(du, u, p, t) du[1] = 0.2u[1] du[2] = 0.4u[2] end u0 = ones(2) tspan = (0.0, 1.0) prob = ODEProblem{true,false}(f, u0, tspan, Float64[]) function lorenz(du, u, p, t) du[1] = 10.0(u[2] - u[1]) du[2] = u[1] * (28.0 - u[3]) - u[2] du[3] = u[1] * u[2] - (8 / 3) * u[3] end lorenzprob = ODEProblem{true,false}(lorenz, [1.0; 0.0; 0.0], (0.0, 1.0), Float64[]) typeof(prob) === typeof(lorenzprob) # true @time sol = solve(prob, Rosenbrock23(autodiff=false)) @time sol = solve(prob, Rosenbrock23(chunk_size=1)) ``` ``` 2.763588 seconds (10.32 M allocations: 648.718 MiB, 4.92% gc time, 99.89% compilation time) 10.577789 seconds (45.44 M allocations: 2.760 GiB, 4.87% gc time, 99.97% compilation time) ``` While the types of `prob` are exactly the same, there is still a significant amount of compile time, even with that exact same time being called in `using` at OrdinaryDiffEq. Maybe this needs to be run on master?
2174aa0
to
1251dd6
Compare
1251dd6
to
b2c2823
Compare
b2c2823
to
02dadda
Compare
Does not play nicely with SnoopPrecompile [ Info: Precompiling OrdinaryDiffEq [1dea7af3-3e70-54e6-95c3-0bf5283fa5ed]
fatal: error thrown and no exception handler available.
ErrorException("unimplemented: serialization of MethodInstances for OpaqueClosure")
ijl_error at /cygdrive/c/buildbot/worker/package_win64/build/src\rtutils.c:41
jl_serialize_value_ at /cygdrive/c/buildbot/worker/package_win64/build/src\dump.c:852
jl_serialize_value_ at /cygdrive/c/buildbot/worker/package_win64/build/src\dump.c:649 [inlined]
jl_serialize_value_ at /cygdrive/c/buildbot/worker/package_win64/build/src\dump.c:665
jl_serialize_value_ at /cygdrive/c/buildbot/worker/package_win64/build/src\dump.c:649 [inlined]
jl_serialize_value_ at /cygdrive/c/buildbot/worker/package_win64/build/src\dump.c:824
jl_serialize_value_ at /cygdrive/c/buildbot/worker/package_win64/build/src\dump.c:649 [inlined]
jl_serialize_value_ at /cygdrive/c/buildbot/worker/package_win64/build/src\dump.c:820
jl_serialize_value_ at /cygdrive/c/buildbot/worker/package_win64/build/src\dump.c:649 [inlined]
jl_serialize_value_ at /cygdrive/c/buildbot/worker/package_win64/build/src\dump.c:872
jl_serialize_value_ at /cygdrive/c/buildbot/worker/package_win64/build/src\dump.c:649 [inlined]
jl_serialize_value_ at /cygdrive/c/buildbot/worker/package_win64/build/src\dump.c:704
jl_serialize_value_ at /cygdrive/c/buildbot/worker/package_win64/build/src\dump.c:649 [inlined]
jl_serialize_value_ at /cygdrive/c/buildbot/worker/package_win64/build/src\dump.c:893
jl_serialize_value_ at /cygdrive/c/buildbot/worker/package_win64/build/src\dump.c:1073 [inlined]
serialize_htable_keys at /cygdrive/c/buildbot/worker/package_win64/build/src\dump.c:1075 [inlined]
ijl_save_incremental at /cygdrive/c/buildbot/worker/package_win64/build/src\dump.c:2686
jl_write_compiler_output at /cygdrive/c/buildbot/worker/package_win64/build/src\precompile.c:65
ijl_atexit_hook at /cygdrive/c/buildbot/worker/package_win64/build/src\init.c:207
jl_repl_entrypoint at /cygdrive/c/buildbot/worker/package_win64/build/src\jlapi.c:712
mainCRTStartup at /cygdrive/c/buildbot/worker/package_win64/build/cli\loader_exe.c:59
BaseThreadInitThunk at C:\WINDOWS\System32\KERNEL32.DLL (unknown line)
RtlUserThreadStart at C:\WINDOWS\SYSTEM32\ntdll.dll (unknown line)
ERROR: Failed to precompile OrdinaryDiffEq [1dea7af3-3e70-54e6-95c3-0bf5283fa5ed] to C:\Users\accou\.julia\compiled\v1.8\OrdinaryDiffEq\jl_B4DB.tmp.
Stacktrace:
[1] error(s::String)
@ Base .\error.jl:35
[2] compilecache(pkg::Base.PkgId, path::String, internal_stderr::IO, internal_stdout::IO, ignore_loaded_modules::Bool)
@ Base .\loading.jl:1558
[3] compilecache
@ .\loading.jl:1502 [inlined]
[4] _require(pkg::Base.PkgId)
@ Base .\loading.jl:1203
[5] _require_prelocked(uuidkey::Base.PkgId)
@ Base .\loading.jl:1091
[6] macro expansion
@ .\loading.jl:1071 [inlined]
[7] macro expansion
@ .\lock.jl:223 [inlined]
[8] require(into::Module, mod::Symbol)
@ Base .\loading.jl:1035
[9] eval
@ .\boot.jl:368 [inlined]
[10] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
@ Base .\loading.jl:1281
[11] invokelatest(::Any, ::Any, ::Vararg{Any}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ Base .\essentials.jl:729
[12] invokelatest(::Any, ::Any, ::Vararg{Any})
@ Base .\essentials.jl:726
[13] inlineeval(m::Module, code::String, code_line::Int64, code_column::Int64, file::String; softscope::Bool)
@ VSCodeServer c:\Users\accou\.vscode\extensions\julialang.language-julia-1.6.31\scripts\packages\VSCodeServer\src\eval.jl:233
[14] (::VSCodeServer.var"#66#70"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})()
@ VSCodeServer c:\Users\accou\.vscode\extensions\julialang.language-julia-1.6.31\scripts\packages\VSCodeServer\src\eval.jl:157
[15] withpath(f::VSCodeServer.var"#66#70"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams}, path::String)
@ VSCodeServer c:\Users\accou\.vscode\extensions\julialang.language-julia-1.6.31\scripts\packages\VSCodeServer\src\repl.jl:249
[16] (::VSCodeServer.var"#65#69"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})()
@ VSCodeServer c:\Users\accou\.vscode\extensions\julialang.language-julia-1.6.31\scripts\packages\VSCodeServer\src\eval.jl:155
[17] hideprompt(f::VSCodeServer.var"#65#69"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})
@ VSCodeServer c:\Users\accou\.vscode\extensions\julialang.language-julia-1.6.31\scripts\packages\VSCodeServer\src\repl.jl:38
[18] (::VSCodeServer.var"#64#68"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})()
@ VSCodeServer c:\Users\accou\.vscode\extensions\julialang.language-julia-1.6.31\scripts\packages\VSCodeServer\src\eval.jl:126
[19] with_logstate(f::Function, logstate::Any)
@ Base.CoreLogging .\logging.jl:511
[20] with_logger
@ .\logging.jl:623 [inlined]
[21] (::VSCodeServer.var"#63#67"{VSCodeServer.ReplRunCodeRequestParams})()
@ VSCodeServer c:\Users\accou\.vscode\extensions\julialang.language-julia-1.6.31\scripts\packages\VSCodeServer\src\eval.jl:225
[22] #invokelatest#2
@ .\essentials.jl:729 [inlined]
[23] invokelatest(::Any)
@ Base .\essentials.jl:726
[24] macro expansion
@ c:\Users\accou\.vscode\extensions\julialang.language-julia-1.6.31\scripts\packages\VSCodeServer\src\eval.jl:34 [inlined]
[25] (::VSCodeServer.var"#61#62")()
@ VSCodeServer .\task.jl:482 |
02dadda
to
96b6526
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a continuation of #736 instead using OpaqueClosures. As such, it also requires:
But now the MWE doesn't run:
The precompilation from SciML/OrdinaryDiffEq.jl#1627 seems to not work with opaque closures. Do they not support precompilation? @Keno