Skip to content

Cache the kernel lookup of clfunction with GPUCompiler's cached_lookup - #590

Merged
maleadt merged 2 commits into
mainfrom
tb/cached-lookup
Oct 26, 2026
Merged

maleadt merged 2 commits into
mainfrom
tb/cached-lookup

Conversation

@maleadt

@maleadt maleadt commented Oct 26, 2026

Copy link
Copy Markdown
Member

Every launch takes a global lock, builds the compiler configuration and job and queries GPUCompiler's cache. This wraps that lookup in GPUCompiler.cached_lookup (JuliaGPU/GPUCompiler.jl#1061). The key holds the context, the device, the task-local program backend and the compiler options, with copies of array options like extensions; tests cover switching the program backend and mutating an option.

A separate commit makes clfunction specialize on the type of source, which it didn't as the keyword is only passed on: every launch constructed the HostKernel dynamically, for about 3100 instructions.

PoCL before PoCL after NVIDIA before NVIDIA after
clfunction (hit) 247 ns, ~6600 insns 17.5 ns, ~580 insns 238 ns, ~6700 insns 18.5 ns, ~580 insns
@opencl 1795 ns 1567 ns 4358 ns 4042 ns
KernelAbstractions launch 2104 ns 1745 ns 3098 ns 2710 ns

Julia doesn't specialize on keyword arguments that are only passed on, so
`source` was a `Function`, and every launch constructed the `HostKernel` with
`apply_type` and a dynamic `new`: about 3100 instructions.
…okup`

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, the program backend and the compiler options. The
program backend is task-local state that selects the compiler configuration, so
a test checks that switching it doesn't return the kernel compiled for the other
one. Together with the previous commit, a hit goes from about 6600 to 580
instructions, and a KernelAbstractions launch gets 13-17% faster on PoCL.
@maleadt maleadt added the performance Runtime performance. label Oct 26, 2026
@codecov

codecov Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.85%. Comparing base (a721863) to head (8e3b8a1).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #590      +/-   ##
==========================================
+ Coverage   88.86%   90.85%   +1.98%     
==========================================
  Files          18       18              
  Lines        1778     1782       +4     
==========================================
+ Hits         1580     1619      +39     
+ Misses        198      163      -35     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@maleadt
maleadt merged commit f3627a1 into main Oct 26, 2026
18 checks passed
@maleadt
maleadt deleted the tb/cached-lookup branch October 26, 2026 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Runtime performance.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant