diff --git a/src/deprecated.jl b/src/deprecated.jl index 4b6c5b2a..f395eb39 100644 --- a/src/deprecated.jl +++ b/src/deprecated.jl @@ -315,3 +315,21 @@ end Base.@deprecate_binding compile_hook active_compile_hook false ", use `run_compile_hook` or `with_compile_hook` instead." @public compile_hook + + +## `deferred_codegen_jobs` + +# Deferred compilation used to be requested by registering a job (or a function and +# argument types) in this dictionary, under the id passed to the `deferred_codegen` marker, +# and looking it up by that id when linking. Choosing ids that way races with concurrent +# compilations, so back-ends should use `deferred_codegen!`, and device code +# `deferred_codegen(::Val, ::Val)`. Released versions of CUDA.jl, Metal.jl, OpenCL.jl and +# KernelAbstractions.jl (POCL) still write here, as does Enzyme.jl from a generated +# function, which has no replacement yet (EnzymeAD/Enzyme.jl#3511). It is therefore not +# marked with `@deprecate_binding`, which would warn those users. Remove in the next +# breaking release, together with `legacy_deferred_spec`, its use in `deferred_spec` and +# the remark about these ids next to `DeferredRequest`. +const deferred_codegen_jobs = Dict{Int, Any}() + +# the job registered under a marker's id, if any +legacy_deferred_spec(id::Int) = get(deferred_codegen_jobs, id, nothing) diff --git a/src/driver.jl b/src/driver.jl index e963c751..8e9ed0b1 100644 --- a/src/driver.jl +++ b/src/driver.jl @@ -180,13 +180,8 @@ end # Deferred compilation: code obtains the address of a function that the compilation it ends # up in compiles too (see `deferred_codegen` and `deferred_codegen!`), through calls to a -# `deferred_codegen` marker with an id that identifies what to compile. -# -# Jobs registered here directly, with the id of their marker as key, are the legacy way of -# requesting them, which Enzyme.jl and releases of back-ends that predate -# `deferred_codegen!` use. New code should use `deferred_codegen!` instead, which registers -# requests without racing with concurrent compilations. -const deferred_codegen_jobs = Dict{Int, Any}() +# `deferred_codegen` marker with an id that identifies what to compile. (Jobs can also be +# registered directly in the legacy `deferred_codegen_jobs`, see `deprecated.jl`.) # We make this function explicitly callable so that we can drive OrcJIT's # lazy compilation from, while also enabling recursive compilation. @@ -249,14 +244,13 @@ function register_deferred_request(@nospecialize(spec)) end end -# the request with a marker's id, or the job registered under it with `deferred_codegen_jobs` +# the request with a marker's id function deferred_spec(id::Int) request = Base.@lock deferred_requests_lock get(deferred_requests_by_id, id, nothing) if request !== nothing && request_id(request) == id return request.spec end - global deferred_codegen_jobs - spec = get(deferred_codegen_jobs, id, nothing) + spec = legacy_deferred_spec(id) spec === nothing && error("No deferred codegen request has id $id") return spec end diff --git a/test/helpers/enzyme.jl b/test/helpers/enzyme.jl index aafc56ae..4f559d9f 100644 --- a/test/helpers/enzyme.jl +++ b/test/helpers/enzyme.jl @@ -115,6 +115,7 @@ function GPUCompiler.compile_unhooked(output::Symbol, job::CompilerJob{<:EnzymeT return ir, (; entry, meta.compiled, meta.relocations) end +# like Enzyme.jl, this uses the legacy `deferred_codegen_jobs` (see deprecated.jl) import GPUCompiler: deferred_codegen_jobs # Enzyme's ids are word-sized values (pointers or hashes), passed as a `UInt`, rather than diff --git a/test/native.jl b/test/native.jl index 8a2db2ce..34c200b0 100644 --- a/test/native.jl +++ b/test/native.jl @@ -3495,6 +3495,7 @@ end @test !occursin("deferred_codegen", ir) @test child(ir, 1) !== nothing + # the legacy way of requesting deferred code generation (see deprecated.jl) GPUCompiler.deferred_codegen_jobs[mod.legacy_id] = (; ft=typeof(mod.b), tt=Tuple{Ptr{Int}}) try ir = llvm(mod.legacy)