Resolve compiled CPU kernels through a fast path - #769
Conversation
b8c45de to
ef359b7
Compare
Benchmark ResultsShow table
Benchmark PlotsA plot of the benchmark results have been uploaded as an artifact to the workflow run for this PR. |
ef359b7 to
15be7fd
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #769 +/- ##
==========================================
- Coverage 63.73% 61.28% -2.45%
==========================================
Files 23 23
Lines 1941 2162 +221
==========================================
+ Hits 1237 1325 +88
- Misses 704 837 +133 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Every launch went through `clfunction`, which built a compiler config,
looked up the method instance, allocated a `CompilerJob`, queried
GPUCompiler's cache and hashed its way into `_kernel_instances` before
returning the `HostKernel` it had returned last time. Keep the resolved
`HostKernel` per `HostKernel{F, tt}` type together with the world age and
context it was resolved in, and return it directly while no method has
been defined since and the context is unchanged. Reflection (a set
`compile_hook`) and explicit compiler keywords bypass the fast path.
Reading the `compile_hook` scoped value allocates, so it is only read
when a dynamic scope is active. The `Ref` used to find the kernel for the
current context and the `@something` in `compile_or_lookup` are replaced
with plain control flow, which also removes a boxed variable captured by
the `get!` closure.
A warm launch now allocates once, for the event handle.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VHciC8x39gm97sABrSvBkt
15be7fd to
4cf9918
Compare
maleadt
left a comment
There was a problem hiding this comment.
This looks questionable. AFAIU, it adds an ad-hoc caching layer over GPUCompiler, for the sake of saving 2 tiny (and thus fast) allocations? That doesn't seem worth it. It's also wrong: _kernel_fastpath is only caching on HostKernel{F,tt}, so distinct callable objects with the same type therefore return the first cached HostKernel, including its stored f.
Avoid duplicating GPUCompiler cache invalidation in a separate fast path. Instead, let compile_or_lookup specialize on the bounded back-end job type so CompilerJob remains allocation-free, and keep the method out of line to avoid duplicating it per kernel. This also preserves distinct HostKernel instances for same-type callables carrying different state.
Use a separate recursive helper so a leading Int kernel argument is not interpreted as the argument index.
|
I don't think this needs a secondary cache, just some tweaks on how things are specialized. |
|
Benchmarks look good. |
|
Is this good to go now? 👀 |
Part 2 of the redo of #766 in this repo