-
Notifications
You must be signed in to change notification settings - Fork 33
precompile first interpretation #353
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
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
d39a883
precompile first try
glou-nes 702c3b1
add __init__ & assert remove
glou-nes 6a0dc9b
remove counter & fix precompilation
glou-nes 9ebf3da
keep only one workload
glou-nes 9d2c0d2
try to fix CI
glou-nes 67ca304
forgotten init
glou-nes 6ade5e7
compact
glou-nes 7952694
apply CI check inside setup_workload
glou-nes 7239533
reviews
glou-nes 36c03cc
typo
glou-nes 8c883bd
remove CI ENV hack
glou-nes 6c4d00c
Revert "remove CI ENV hack"
glou-nes 9d82b9f
test CI
glou-nes d4c71bb
test CI 2
glou-nes 63b0b03
Merge branch 'main' into branch-3
wsmoses 4031e9c
de initialize opaque closure cache
wsmoses 77fe082
ongoing
wsmoses 598860a
more attempts
wsmoses 26d0c0a
fix
wsmoses adc2622
fix
wsmoses 03ff85e
fix
wsmoses 7bdcaab
Disable rules for now as unused
wsmoses File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| using PrecompileTools: @setup_workload, @compile_workload | ||
|
|
||
| function infer_sig(sig) | ||
| interp = ReactantInterpreter() | ||
|
|
||
| min_world = Ref{UInt}(typemin(UInt)) | ||
| max_world = Ref{UInt}(typemax(UInt)) | ||
|
|
||
| lookup_result = Reactant.lookup_world( | ||
| sig, interp.world, Core.Compiler.method_table(interp), min_world, max_world | ||
| ) | ||
| match = lookup_result::Core.MethodMatch | ||
| # look up the method and code instance | ||
| mi = ccall( | ||
| :jl_specializations_get_linfo, | ||
| Ref{Core.MethodInstance}, | ||
| (Any, Any, Any), | ||
| match.method, | ||
| match.spec_types, | ||
| match.sparams, | ||
| ) | ||
|
|
||
| @static if VERSION < v"1.11" | ||
| # For older Julia versions, we vendor in some of the code to prevent | ||
| # having to build the MethodInstance twice. | ||
| result = CC.InferenceResult(mi, CC.typeinf_lattice(interp)) | ||
| frame = CC.InferenceState(result, :no, interp) | ||
| @assert !isnothing(frame) | ||
| CC.typeinf(interp, frame) | ||
| ir = CC.run_passes(frame.src, CC.OptimizationState(frame, interp), result, nothing) | ||
| rt = CC.widenconst(CC.ignorelimited(result.result)) | ||
| else | ||
| ir, rt = CC.typeinf_ircode(interp, mi, nothing) | ||
| end | ||
| end | ||
|
|
||
| @setup_workload begin | ||
| initialize_dialect() | ||
| client = XLA.CPUClient(; checkcount=false) | ||
| @compile_workload begin | ||
| # Precompilation on 1.10 hits an apparent bug: https://github.com/JuliaLang/julia/issues/56947 | ||
| @static if VERSION < v"1.11" | ||
| else | ||
| # infer_sig(Tuple{typeof(Base.sum), Reactant.TracedRArray{Float64, 2}}) | ||
| # infer_sig(Tuple{typeof(Base.sin), Reactant.TracedRNumber{Float64}}) | ||
| x = ConcreteRNumber(2.0; client) | ||
| Reactant.compile(sin, (x,); client) | ||
|
|
||
| y = ConcreteRArray([2.0]; client) | ||
| Reactant.compile(Base.sum, (y,); client) | ||
| end | ||
| end | ||
| XLA.free_client(client) | ||
| client.client = C_NULL | ||
| deinitialize_dialect() | ||
| # Opaque closures capture the worldage of their compilation and thus are not relocatable | ||
| # Therefore we explicitly purge all OC's we have created here | ||
| for v in oc_capture_vec | ||
| if v isa Base.RefValue | ||
| p = Ptr{Ptr{Cvoid}}(pointer_from_objref(v)) | ||
| Base.atomic_pointerset(p, C_NULL, :monotonic) | ||
| else | ||
| empty!(v) | ||
| end | ||
| end | ||
| end | ||
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
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.