icb-decode-graph

command
v0.6.20 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 11 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

icb-decode-graph

Zero-cgo Metal Indirect Command Buffer (ICB) decode-graph benchmark built on github.com/tmc/apple/x/metalicb and github.com/tmc/apple/x/metalcounters.

What it measures

The benchmark constructs an N-layer sequential synthetic transformer decode step alternating between two compute kernels across ping-pong activation buffers (actA ↔ actB) and a 256-byte-aligned per-layer parameter table:

  • Even layers: rmsnorm_scale (RMSNorm + affine scale + residual mix)
  • Odd layers: ffn_swiglu_residual (SwiGLU gated FFN micro-op + residual add)

Every layer consumes the output of the previous layer, exercising inter-command barriers (MTLIndirectComputeCommand.SetBarrier) inside the indirect command buffer.

It compares two execution paths from the identical initial activation state across 128 measured decode steps:

  1. Traditional per-dispatch CPU encoding: encodes all N dispatches individually (SetComputePipelineState, SetBufferWithOffsetAtIndex ×3, DispatchThreadgroupsThreadsPerThreadgroup) on every step.
  2. ICB single-replay (x/metalicb.Graph): encodes the N-layer graph once on the CPU, runs Graph.Optimize once on a blit encoder, and replays the entire graph on each step with a single Graph.Replay (UseResourceUsage + ExecuteCommandsInBufferWithRange).

Both paths are timed for CPU encode latency, GPU execution time (via x/metalcounters pass-boundary timestamps cross-checked against MTLCommandBuffer.GPUEndTime - GPUStartTime), and end-to-end wall time, and checked for exact bit-for-bit floating-point parity (maxAbsDiff == 0).

Usage

CGO_ENABLED=0 go run ./examples/metal/icb-decode-graph
CGO_ENABLED=0 go run ./examples/metal/icb-decode-graph -layers 128 -steps 128
CGO_ENABLED=0 go test -v -count=1 ./examples/metal/icb-decode-graph

Live Results (Apple M4 Max)

Recorded on Apple M4 Max, CGO_ENABLED=0, dim=4096, work=16, steps=128, warmup=8, metalcounters=true:

32 Layers (32 dispatches/step)

ICB one-time setup: build=384.25 µs, optimize=2845.29 µs.

Mode CPU Encode (µs/step) GPU Counter (µs/step) GPU CmdBuf (µs/step) Wall (µs/step)
Traditional (per-dispatch) 330.02 172.27 172.27 1255.19
ICB (single-replay) 51.67 219.54 219.54 650.71
Speedup (ICB vs Traditional) 6.39x 0.78x 0.78x 1.93x

Numerical parity: maxAbsDiff=0, exactBitMatch=true.

128 Layers (128 dispatches/step)

ICB one-time setup: build=2282.50 µs, optimize=2046.29 µs.

Mode CPU Encode (µs/step) GPU Counter (µs/step) GPU CmdBuf (µs/step) Wall (µs/step)
Traditional (per-dispatch) 1633.65 679.56 679.58 7969.31
ICB (single-replay) 61.48 840.83 840.85 2238.90
Speedup (ICB vs Traditional) 26.57x 0.81x 0.81x 3.56x

Numerical parity: maxAbsDiff=0, exactBitMatch=true.

Documentation

Rendered for darwin/amd64

Overview

Command icb-decode-graph benchmarks a synthetic N-layer transformer decode graph replayed via github.com/tmc/apple/x/metalicb (MTLIndirectCommandBuffer) against traditional per-dispatch CPU encoding.

It verifies exact numerical parity between both execution paths and measures CPU encode time, GPU execution time (via github.com/tmc/apple/x/metalcounters and MTLCommandBuffer GPUStartTime/GPUEndTime), and wall time across 100+ decode steps.

Jump to

Keyboard shortcuts

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