dispatch-profiler

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: 10 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

dispatch-profiler

Zero-cgo per-dispatch GPU timestamp profiler for a 32-dispatch synthetic transformer micro-layer built on github.com/tmc/apple/x/metalcounters.

What it measures

The profiler encodes a 32-dispatch transformer micro-layer (4 stages × 8 independent heads/tiles: rmsnorm_tile, qkv_proj_head, attn_score_head, mlp_swiglu_tile) and compares barrier-serialized vs. concurrent/overlapped execution across both Metal counter backends:

  1. Metal 3 (MTLCounterSampleBuffer):
    • Barrier-serialized (per-dispatch sampled): samples each dispatch's GPU start/end timestamps (64 samples across 32 passes when DispatchBoundary=false on Apple Silicon; or 33 samples via SampleCountersInBufferAtSampleIndexWithBarrier when DispatchBoundary=true).
    • Unsampled baseline: runs the identical 32-pass workload without sample buffer attachments to isolate per-sample GPU overhead.
    • Single serial vs. single concurrent pass: compares MTLDispatchTypeSerial against MTLDispatchTypeConcurrent with pass-boundary attachments, and checks the counter span delta against MTLCommandBuffer.GPUEndTime - GPUStartTime.
  2. Metal 4 (MTL4CounterHeap) (when supported):
    • Barrier-serialized (33 samples, MTL4TimestampGranularityPrecise): all 32 dispatches in a single MTL4ComputeCommandEncoder separated by dispatch-stage barriers and in-encoder WriteTimestamp.
    • Barrier-serialized (2 samples, start/end only): isolates per-sample WriteTimestamp overhead.
    • Concurrent/overlapped (no barriers): runs all 32 independent dispatches in one MTL4ComputeCommandEncoder without inter-dispatch barriers to measure hardware overlap speedup.

Usage

CGO_ENABLED=0 go run ./examples/metal/dispatch-profiler
CGO_ENABLED=0 go run ./examples/metal/dispatch-profiler -threads 8192 -work 128 -iters 9
CGO_ENABLED=0 go test -v -count=1 ./examples/metal/dispatch-profiler

Live Results (Apple M4 Max)

Recorded on Apple M4 Max, CGO_ENABLED=0, default configuration (dispatches=32, threads=4096, work=96, iters=7, warmup=2), Capabilities: timestamp=true stage=true dispatch=false m3=true m4=true freq=24000000Hz:

Metal 3 (MTLCounterSampleBuffer)
Mode Counter Span CmdBuf GPU Delta Notes
Barrier-serialized (64 samples) 498.29 µs 498.33 µs -0.00 µs Sum of 32 dispatch medians: 469.17 µs
Barrier-serialized (unsampled) — 379.25 µs — Overhead: +1.861 µs/sample
Single serial pass (MTLDispatchTypeSerial) 378.88 µs 378.88 µs 0.00 µs 2 pass-boundary samples
Single concurrent pass (MTLDispatchTypeConcurrent) 74.79 µs 74.75 µs +0.00 µs 5.07x overlap speedup vs. serial pass
Metal 4 (MTL4CounterHeap, in-encoder WriteTimestamp)
Mode Counter Span Notes
Barrier-serialized (33 samples, precise) 520.29 µs Exact telescoping sum of 32 dispatches: 520.29 µs
Barrier-serialized (2 samples, start/end) 392.54 µs Overhead: +4.121 µs/sample (31 extra precise samples)
Concurrent/overlapped (no barriers) 74.38 µs 7.00x overlap speedup vs. barrier-serialized
Per-Stage Dispatch Durations (Median µs across 8 heads/tiles)
Stage (8 dispatches each) Metal 3 (µs) Metal 4 (µs)
rmsnorm_tile[0..7] 12.00 – 12.29 12.17 – 13.38
qkv_proj_head[0..7] 14.04 – 14.33 15.12 – 15.67
attn_score_head[0..7] 13.67 – 13.92 14.62 – 15.08
mlp_swiglu_tile[0..7] 18.46 – 18.62 19.54 – 20.21

Documentation

Rendered for darwin/amd64

Overview

Command dispatch-profiler benchmarks per-dispatch GPU timestamp sampling on a 32-dispatch synthetic transformer micro-layer using github.com/tmc/apple/x/metalcounters.

It compares barrier-serialized vs. concurrent/overlapped execution across both Metal 3 (MTLCounterSampleBuffer) and Metal 4 (MTL4CounterHeap), reporting per-dispatch GPU durations, per-sample overhead, and the delta against MTLCommandBuffer GPUStartTime/GPUEndTime.

Jump to

Keyboard shortcuts

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