From 7ff700541fff15db00b26df5478a409338e43415 Mon Sep 17 00:00:00 2001 From: Tim Besard Date: Tue, 6 Oct 2026 10:35:16 +0200 Subject: [PATCH] Report kernel lookups to the compile hook instead of recompiling The @device_code macros observe kernels through GPUCompiler's compile hook. To report cached kernels to it, compile_or_lookup bypassed the cache whenever a hook was installed, so every launch inside one of these macros recompiled its kernel. GPUCompiler 2.13 adds run_compile_hook, which reports a job without compiling it; call it on every lookup and keep using the cache. --- src/compiler/execution.jl | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/compiler/execution.jl b/src/compiler/execution.jl index 1500fcb54..c5fb4b927 100644 --- a/src/compiler/execution.jl +++ b/src/compiler/execution.jl @@ -326,14 +326,15 @@ end # by `GPUCompiler.cached_results` (Julia's integrated code cache on 1.11+, which also # persists artifacts through precompilation; a session-local store on 1.10). # -# `image === nothing` identifies a `oneAPIResults` that hasn't been compiled yet. The -# `compile_hook` check additionally forces the compile path so reflection-style -# consumers (`@device_code_*`) observe the compilation even on a cache hit. +# `image === nothing` identifies a `oneAPIResults` that hasn't been compiled yet. Every +# lookup is reported to the `@device_code_*` hook, so reflection observes cached kernels +# without recompiling them. # Specialize on the target/parameter types so callers can avoid boxing CompilerJob. # Keep the body out of callers that specialize per kernel. @noinline function compile_or_lookup(job::CompilerJob)::oneAPIResults + GPUCompiler.run_compile_hook(job) res = GPUCompiler.cached_results(oneAPIResults, job) - if res === nothing || res.image === nothing || GPUCompiler.compile_hook[] !== nothing + if res === nothing || res.image === nothing compiled = compile_to_obj(job) res = @something res GPUCompiler.cached_results(oneAPIResults, job) res.image = compiled.image