|
| 1 | +using PrecompileTools |
1 | 2 | using PrecompileTools: @setup_workload, @compile_workload
|
2 | 3 |
|
3 | 4 | function infer_sig(sig)
|
@@ -34,15 +35,33 @@ function infer_sig(sig)
|
34 | 35 | end
|
35 | 36 | end
|
36 | 37 |
|
| 38 | +function clear_oc_cache() |
| 39 | + # Opaque closures capture the worldage of their compilation and thus are not relocatable |
| 40 | + # Therefore we explicitly purge all OC's we have created here |
| 41 | + for v in oc_capture_vec |
| 42 | + if v isa Base.RefValue |
| 43 | + p = Ptr{Ptr{Cvoid}}(pointer_from_objref(v)) |
| 44 | + Base.atomic_pointerset(p, C_NULL, :monotonic) |
| 45 | + else |
| 46 | + empty!(v) |
| 47 | + end |
| 48 | + end |
| 49 | +end |
| 50 | + |
| 51 | +# Precompilation on 1.10 hits an apparent bug: https://github.com/JuliaLang/julia/issues/56947 |
| 52 | +function precompilation_supported() |
| 53 | + return VERSION >= v"1.11" || VERSION >= v"1.10.8" |
| 54 | +end |
| 55 | + |
| 56 | +function precompiling() |
| 57 | + return (@ccall jl_generating_output()::Cint) == 1 |
| 58 | +end |
| 59 | + |
37 | 60 | @setup_workload begin
|
38 | 61 | initialize_dialect()
|
39 | 62 | client = XLA.CPUClient(; checkcount=false)
|
40 | 63 | @compile_workload begin
|
41 |
| - # Precompilation on 1.10 hits an apparent bug: https://github.com/JuliaLang/julia/issues/56947 |
42 |
| - @static if VERSION < v"1.11" |
43 |
| - else |
44 |
| - # infer_sig(Tuple{typeof(Base.sum), Reactant.TracedRArray{Float64, 2}}) |
45 |
| - # infer_sig(Tuple{typeof(Base.sin), Reactant.TracedRNumber{Float64}}) |
| 64 | + @static if precompilation_supported() |
46 | 65 | x = ConcreteRNumber(2.0; client)
|
47 | 66 | Reactant.compile(sin, (x,); client)
|
48 | 67 |
|
|
53 | 72 | XLA.free_client(client)
|
54 | 73 | client.client = C_NULL
|
55 | 74 | deinitialize_dialect()
|
56 |
| - # Opaque closures capture the worldage of their compilation and thus are not relocatable |
57 |
| - # Therefore we explicitly purge all OC's we have created here |
58 |
| - for v in oc_capture_vec |
59 |
| - if v isa Base.RefValue |
60 |
| - p = Ptr{Ptr{Cvoid}}(pointer_from_objref(v)) |
61 |
| - Base.atomic_pointerset(p, C_NULL, :monotonic) |
62 |
| - else |
63 |
| - empty!(v) |
64 |
| - end |
65 |
| - end |
| 75 | + clear_oc_cache() |
66 | 76 | end
|
0 commit comments