Skip to content

Switch to CompilerCaching.jl#777

Draft
maleadt wants to merge 6 commits into
mainfrom
tb/compilercaching
Draft

Switch to CompilerCaching.jl#777
maleadt wants to merge 6 commits into
mainfrom
tb/compilercaching

Conversation

@maleadt
Copy link
Copy Markdown
Member

@maleadt maleadt commented May 12, 2026

maleadt and others added 6 commits May 12, 2026 11:28
Replace `cached_compilation` with a `MetalResults` struct attached to
each `CodeInstance` via `CompilerCaching`: `metallib` + entry name are
session-portable (cached through precompilation), and the
`MTLComputePipelineState` is materialized lazily per session.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Adds a `bitcode` field to `MetalResults` and overrides
`GPUCompiler.bitcode` / `bitcode!`. Per-function runtime library bitcode
now rides on the same precompilation path as `metallib`/`entry`, so
cross-session loads can skip the runtime rebuild.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Replace the single `pipeline` slot on `MetalResults` with a small linear
cache of `(MTLDevice, MTLComputePipelineState)` pairs. The cache partition
already covers the macOS / AIR / Metal versions that affect codegen, but
two `MTLDevice`s on a single Mac (e.g. integrated + discrete) share the
same `metallib` and need separate `MTLComputePipelineState`s.

Hot-path cost is unchanged: one field load + one `===` compare. The
common case (single device) stays at n=1.

`link_pipeline` now takes the target `MTLDevice` explicitly instead of
calling `device()` internally, so the call site captures the device once
under `mtlfunction_lock`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
`something(lookup(...), compile_metal!(...))` evaluated `compile_metal!`
eagerly even on a cache hit, so every kernel launch silently re-ran the
full LLVM compile pipeline. Branch explicitly on the lookup result.

Warm-cache `mtlfunction` cost: ~3.4 ms → ~380 ns.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant