pipeline-cache-bench

command
v0.6.21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2026 License: MIT Imports: 15 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

pipeline-cache-bench

Zero-cgo benchmark and verification example for github.com/tmc/apple/x/metalcache (MTLBinaryArchive and Metal 4 MTL4PipelineDataSetSerializer + MTL4Archive).

What it does

  1. Generates 16 templated MSL compute kernels (4 tile/unroll factors 1, 2, 4, 8 × 4 activations relu, gelu, silu, tanh) stamped with a fresh source nonce so cold compilation bypasses Metal's system-wide shader cache.
  2. Computes a cache key via metalcache.CacheKey(dev, msl, opts) (GPU name + macOS build + MSL SHA-256 + specialization constants), compiles all 16 compute pipelines into a metalcache.Archive, and atomically serializes the archive to $TMPDIR.
  3. Spawns a fresh child process (METALCACHE_BENCH_RELOAD=1, also available via -reload-only) so Metal's in-process pipeline cache is completely cold, opens the serialized archive, and instantiates all 16 pipelines strictly from the archive (NewComputePipelineStrict with MTLPipelineOptionFailOnBinaryArchiveMiss).
  4. Dispatches all 16 kernels on the GPU in both processes and verifies 16/16 bit-identical SHA-256 output digests.
  5. Mutates the MSL source and confirms metalcache.Open automatically invalidates the stale archive (Loaded() == false, Invalidated() == true, and strict lookup fails with a miss).
  6. On Metal 4 devices (metalcache.SupportsMetal4(dev)), runs the same cold compile vs. fresh-subprocess reload comparison using MTL4PipelineDataSetSerializer and MTL4Archive.

Usage

CGO_ENABLED=0 go run ./examples/metal/pipeline-cache-bench
CGO_ENABLED=0 go run ./examples/metal/pipeline-cache-bench -elems 131072
CGO_ENABLED=0 go test -v -count=1 ./examples/metal/pipeline-cache-bench

Live Results (Apple M4 Max, macOS 26.6.2)

Recorded on Apple M4 Max, macOS 26.6.2 (Build 25G83), Go 1.27.0 (darwin/arm64), CGO_ENABLED=0, 16 templated compute kernels, 65,536 float32 elements:

MTLBinaryArchive (x/metalcache.Archive)
Phase Time Notes
Cold compile (total) 1.687 s lib=186.8 ms, 16x pipelines=1.377 s, serialize=123.0 ms
Warm fresh subprocess (total) 107.2 ms open=1.17 ms, lib=96.9 ms, 16x strict load=9.11 ms
Pipeline creation speedup 151.12x 1.377 s -> 9.11 ms (15.74x total end-to-end)
  • Serialized archive size: 233,152 bytes (227.7 KiB)
  • Bit-identical GPU outputs: 16/16 kernels matched (SHA-256)
  • MSL mutation invalidation: invalidated=true, strict_miss=true
Metal 4 (MTL4PipelineDataSetSerializer + MTL4Archive)
Phase Time Notes
Cold compile (total) 507.1 ms includes serialize=64.4 ms
Warm fresh subprocess (total) 102.9 ms open=1.13 ms, 16x archive load=2.39 ms
Pipeline creation speedup 184.64x 16x archive load=2.39 ms in fresh subprocess
  • Serialized Metal 4 archive size: 228,928 bytes (223.6 KiB)
  • Bit-identical GPU outputs: 16/16 kernels matched (SHA-256)

Documentation

Rendered for darwin/amd64
The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL