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 @@ -59,7 +59,7 @@ ChainRulesCore = "1"
EnzymeCore = "0.8"
ExprTools = "0.1"
GPUArrays = "12.1"
GPUCompiler = "2.13"
GPUCompiler = "2.18"
GPUToolbox = "3.3.1"
KernelAbstractions = "0.10"
KernelInterface = "0.4"
Expand Down
29 changes: 14 additions & 15 deletions src/compiler/codegen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ mutable struct HIPResults
Tuple{HIP.HIPDevice,HIP.HIPFunction}[])
end

# (objectid(source), hash(fun), f) => HIPKernel
const _kernel_instances = Dict{Any, Any}()

GPUCompiler.runtime_module(@nospecialize(::HIPCompilerJob)) = AMDGPU

GPUCompiler.method_table(@nospecialize(::HIPCompilerJob)) = AMDGPU.method_table
Expand Down Expand Up @@ -296,19 +293,21 @@ The following kwargs are supported:
values throw an `ArgumentError`.
"""
function hipfunction(f::F, tt::TT = Tuple{}; kwargs...) where {F <: Core.Function, TT}
kw = values(kwargs)
dev = AMDGPU.device()
fun = GPUCompiler.cached_lookup(HIP.HIPFunction, F, tt, (dev, kw)) do
hipfunction_link(methodinstance(F, tt), dev, kw)
end
return Runtime.HIPKernel{F, tt}(f, fun)
end

# the part of `hipfunction` that doesn't depend on the kernel's types, kept out of the code
# compiled for every kernel
@noinline function hipfunction_link(source::Core.MethodInstance, dev::HIP.HIPDevice,
kw::NamedTuple)
Base.@lock hipfunction_lock begin
dev = AMDGPU.device()
config = compiler_config(dev; kwargs...)
source = methodinstance(F, tt)
fun = hipfunction_lookup(source, config, dev)

key = (objectid(source), hash(fun), f)
kernel = get(_kernel_instances, key, nothing)
if kernel === nothing
kernel = Runtime.HIPKernel{F, tt}(f, fun)
_kernel_instances[key] = kernel
end
return kernel::Runtime.HIPKernel{F, tt}
config = compiler_config(dev; kw...)
return hipfunction_lookup(source, config, dev)
end
end

Expand Down
3 changes: 3 additions & 0 deletions test/kernelabstractions_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ Testsuite.testsuite(

# launching should not be much more expensive than with few arguments
# (Julia 1.11 and older allocate a little per argument)
# warm up in the world of the measurement, as defining this closure advances the world
# on Julia 1.10, and the first launch in a new world looks up the kernel again
Base.invokelatest() do
many_args_launch(kernel, out)
few_args_launch(few_kernel, out)
@test @allocated(many_args_launch(kernel, out)) <=
@allocated(few_args_launch(few_kernel, out)) + 40*32
Expand Down
Loading