Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
14 changes: 4 additions & 10 deletions src/driver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/helpers/enzyme.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/native.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading