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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ AMDGPU = "2"
Adapt = "0.4, 1.0, 2.0, 3.0, 4"
Atomix = "1.5"
EnzymeCore = "0.8.25"
GPUCompiler = "2.24"
GPUCompiler = "2.25"
GPUToolbox = "3.6"
KernelInterface = "0.4.7"
LLVM = "10"
Expand Down
25 changes: 5 additions & 20 deletions src/pocl/compiler/compilation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,10 @@ function GPUCompiler.finish_module!(
ft, tt, job.world; method_table_view = GPUCompiler.method_table_view(job)
)
cfg = CompilerConfig(job.config; kernel = false, name = nothing)
job = CompilerJob(src, cfg, job.world)
id = length(GPUCompiler.deferred_codegen_jobs) + 1
GPUCompiler.deferred_codegen_jobs[id] = job
rng_job = CompilerJob(src, cfg, job.world)

# generate IR for calls to `deferred_codegen` and the resulting function pointer
# call `initialize_rng_state()` in a new entry block. it returns nothing: inferring
# its return type natively would leave host code for it in sysimages.
top_bb = entry.entry
bb = BasicBlock(LLVM.before(top_bb), "initialize_rng")
@dispose builder = IRBuilder() begin
Expand All @@ -117,29 +116,15 @@ function GPUCompiler.finish_module!(
builder.debug_location = loc
end

# call the `deferred_codegen` marker function
# (declared like GPUCompiler's `ccall("extern deferred_codegen", llvmcall, Ptr{Cvoid}, ...)`)
T_ptr = convert(LLVMType, Ptr{Cvoid})
T_id = convert(LLVMType, Int)
deferred_codegen_ft = LLVM.FunctionType(T_ptr, [T_id])
deferred_codegen = get!(mod.functions, "deferred_codegen") do
LLVM.Function(mod, "deferred_codegen", deferred_codegen_ft)
end
fptr = call!(builder, deferred_codegen_ft, deferred_codegen, [ConstantInt(id)])

# call the `initialize_rng_state` function, which returns nothing. inferring its
# return type natively would leave host code for it in sysimages.
llvm_ft = LLVM.FunctionType(LLVM.VoidType())
fptr = inttoptr!(builder, fptr, LLVM.PointerType(llvm_ft))
fptr = GPUCompiler.deferred_codegen!(builder, rng_job)
fptr = pointercast!(builder, fptr, LLVM.PointerType(llvm_ft))
call!(builder, llvm_ft, fptr)
br!(builder, top_bb)

# note the use of the device-side RNG in this kernel
push!(entry.function_attributes, StringAttribute("julia.opencl.rng", ""))
end

# XXX: put some of the above behind GPUCompiler abstractions
# (e.g., a compile-time version of `deferred_codegen`)
end
return entry
end
Expand Down
Loading