From 714140b0657b4eb5cf8e3921746a8b2caf76a75e Mon Sep 17 00:00:00 2001 From: Tim Besard Date: Mon, 26 Oct 2026 08:19:04 +0100 Subject: [PATCH] Cache the kernel lookup of `zefunction` with GPUCompiler's `cached_lookup` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Every launch took a global lock, built the compiler configuration and job and queried GPUCompiler's cache. Wrap that in `GPUCompiler.cached_lookup`, keyed on the context, the device and the compiler options. A hit goes from 3437 to 390 instructions, and `@oneapi` from 1.73 to 1.47 µs on an Arc A770. --- Project.toml | 2 +- src/compiler/execution.jl | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index a34cc83b..134da1ec 100644 --- a/Project.toml +++ b/Project.toml @@ -48,7 +48,7 @@ CEnum = "0.5, 1" Crayons = "4" ExprTools = "0.1" GPUArrays = "12.1" -GPUCompiler = "2.17" +GPUCompiler = "2.18" GPUToolbox = "3.4" IntelITT = "0.2" KernelAbstractions = "0.10" diff --git a/src/compiler/execution.jl b/src/compiler/execution.jl index f39bd4b7..aaab7794 100644 --- a/src/compiler/execution.jl +++ b/src/compiler/execution.jl @@ -326,7 +326,11 @@ end const zefunction_lock = ReentrantLock() function zefunction(f::F, tt::TT=Tuple{}; kwargs...) where {F,TT} - fun = zefunction_link(methodinstance(F, tt); kwargs...) + # the kernel also depends on the task's context and device, see `zefunction_link` + kw = values(kwargs) + fun = GPUCompiler.cached_lookup(ZeKernel, F, tt, (context(), device(), kw)) do + zefunction_link(methodinstance(F, tt); kw...) + end return HostKernel{F,tt}(f, fun) end