A barrier after every dispatch
Honeykrisp, Mesa's Vulkan driver for Apple silicon, emits a full GPU barrier and cache invalidate after every compute dispatch, whether or not anything depends on it. For a 4B model decoding on an M2 Ultra that is 547 barriers per token at 18 microseconds each, 52% of the time. Removing the barriers the application never requested is worth 20.7% with correctness unchanged. A per-bit ablation shows one unnamed bit carries the entire cost, and the 2x ceiling from removing it computes garbage.

- Was called
- 52% of decode time
- Was
- a barrier after every dispatch
A Mac Studio running Linux decodes a 4B model on its GPU through Mesa's Vulkan driver. Earlier work on the shader compiler turned up three defects. The largest remaining cost is not in the compiler.
Honeykrisp follows every compute dispatch with a full AGX barrier and cache invalidate, whether or not anything depends on it. On this model that is 547 dispatches per token and 547 barriers, at about 18 microseconds each, which is 52% of the time to produce a token.
The driver documents the reason in a comment quoted below. Nobody knows what the bits in that packet mean, so all of them are set after every launch to be safe.
Transcript
Honeykrisp, Mesa's Vulkan driver for Apple silicon, emits a full GPU barrier after every compute dispatch, whether or not anything depends on it.
Picture a dispatch line. Each press is a dispatch, and the carriage is one token's work. After every press, a stop pin rises. That's the barrier. The carriage waits there while the caches flush.
On a 4B model, that's 547 barriers per token, at about 18 microseconds each. That's 52 percent of the time to produce a token.
But llama.cpp already knows which operations overlap. Emit the barrier only where Vulkan asks, and a token needs 370, not 547.
Decode goes from 52.4 to 63.3 tokens per second. Plus 20.7 percent, with correctness unchanged.
Then there's the packet itself. Every bit in it was set, to be safe. Clear them one at a time, and bit 7 alone carries 14 of the 18 microseconds.
But bit 7 is required. Clear it, and decode looks healthy, at 111 tokens per second. But perplexity is infinite. It was computing garbage.
So the barrier goes only where Vulkan asks, and bit 7 stays set. Plus 20.7 percent, on by default. The full write-up is at boracode.ai.
Transcript
An M2 Ultra on Linux stops its GPU after every job.
That's over half the time of every token.
Nobody knows what the barrier bits mean, so the driver sets them all.
So Honeykrisp now stops only where Vulkan asks.
Twenty percent faster, and the test results don't change.
Then each bit got tested alone. One carries the whole cost.
Clear it, and the GPU runs almost twice as fast.
Except every answer comes out as infinity.
So a benchmark that only counts speed will cheer for garbage.
547 stops. Full write-up on boracode.ai. Webale.
Test bench
One machine. There is no PCIe link table because the GPU is on the SoC.
Every arm below runs the same binary with one environment variable changed. The variable selects one branch in the driver and nothing else differs.
Where a token actually goes
The baseline is the fraction of the machine's own 800 GB/s that the model uses, not a ratio against another vendor's hardware. At the start of this work that was 122 GB/s, or 15.4%.
A token was decomposed by measuring each matrix-vector shape in the model on its own:
| shape | per layer | µs | MB | GB/s | % of 800 |
|---|---|---|---|---|---|
| 9728 x 2560 (gate, up) | 2 | 70.30 | 14.01 | 199.3 | 24.9% |
| 2560 x 9728 (down) | 1 | 74.28 | 14.01 | 188.6 | 23.6% |
| 4096 x 2560 (q) | 1 | 44.26 | 5.90 | 133.3 | 16.7% |
| 2560 x 4096 (o) | 1 | 45.10 | 5.90 | 130.8 | 16.3% |
| 1024 x 2560 (k, v) | 2 | 26.97 | 1.47 | 54.7 | 6.8% |
Two results follow from the table. First, bandwidth falls as the operation shrinks. That pattern indicates a fixed cost per operation and not a bandwidth limit. Fitting time against bytes gives about 21.5 microseconds of fixed cost and 282 GB/s at the margin.
Second, the shapes sum to 2049.9 MB while the file on disk is 2369.8 MB. The missing 320 MB is token_embd, which this model ties to its output head. It is a q6_K matvec of 151936 x 2560 that reads 319 MB every token, 13.5% of all bytes, and the first decomposition omitted it. Measured alone it runs at 369 GB/s, 46% of the part's peak. It is the fastest operation in the model, which shows that neither the hardware nor the kernel has a low ceiling.
Dispatches were then counted. The driver prints the counts under ASAHI_MESA_DEBUG=perf. That is a different variable from AGX_MESA_DEBUG, which controls the compiler, and using the wrong one produces an empty log:
| quantity | per token |
|---|---|
| queue submissions | 11 |
| compute dispatches | 547 |
| CDM barriers | 547 |
There is exactly one barrier per dispatch. Combined with the fit, the token time is accounted for: 547 x 21.5 µs of fixed cost is 11.76 ms, the weights at 282 GB/s are 7.27 ms, and the sum is 19.03 ms against 19.34 ms measured. The two figures were derived independently and agree within 2%.
The nobarrier flag does not remove the barrier
Honeykrisp ships a debug flag named nobarrier. It was the first test:
| arm | tok/s |
|---|---|
| stock | 51.8 |
| HK_PERFTEST=nobarrier | 52.2 |
The flag has no effect, and concluding from it that barriers are irrelevant would be wrong.
HK_PERFTEST=nobarrier skips hk_CmdPipelineBarrier2, which ends the compute control stream. But hk_EndCommandBuffer runs merge_control_streams(), which stitches adjacent compute streams back together. The driver's own comment calls the split "sloppiness" that is cheap to undo later. The flag therefore removes a split that is merged again anyway, and it never touches the packet that serializes the GPU.
Where the serialization happens
The serialization is in the dispatch path itself (src/asahi/vulkan/hk_cmd_dispatch.c):
hk_cdm_cache_flush emits an AGX CDM_BARRIER packet after every launch, unconditionally, without checking whether anything downstream reads what the launch wrote. The packet is defined in src/asahi/libagx/libagx_dgc.h, with the driver's own explanation:
The comment explains the design. The hardware is reverse-engineered and undocumented, so setting every bit was the safe choice, and the author recorded both the reason and the intent to revisit it. The motivating case was blits, which involve the pixel-backend and texture caches. That is a graphics path unrelated to a chain of matrix-vector products.
The barrier is therefore emitted too often and is too wide. Each half can be measured separately.
Upper bound
The driver has no switch for this, so one was added: an environment variable that makes hk_cdm_cache_flush return immediately. It is off by default and the stock path is byte-identical. Results are wrong with it set, which does not matter here because the measurement is only of what the barrier costs.
| arm | tok/s | correct |
|---|---|---|
| stock | 52.4 | yes |
| barrier skipped entirely | 109.0 | no |
The speedup is 2.08x. Spread over 547 barriers, one barrier costs 18.1 microseconds. The smallest matvec in the model takes 26.7 µs in total.
Two halves, measured separately
Frequency
The barrier belongs where the application asks for ordering. llama.cpp's Vulkan backend already tracks which operations alias. It compares byte ranges within a buffer and synchronizes only on a real overlap, so the number of barriers it requests is the number genuinely needed:
| quantity | per token |
|---|---|
| compute dispatches | 547 |
| barriers Honeykrisp emitted | 547 |
| barriers llama.cpp asked for | 366 |
The change emits the barrier where the Vulkan API asks for it. Application dispatches drop the unconditional flush. Driver-internal dispatches (draws, meta operations, queries, and the blit paths the comment was about) keep the existing behaviour exactly.
Placement matters. Every synchronization point in the driver funnels through hk_cmd_buffer_end_compute(): pipeline barriers, vkCmdWaitEvents2, vkCmdSetEvent2, the query paths, and end of command buffer. The first version emitted the barrier at only two of these sites, which left an application that orders its compute with events instead of barriers with no ordering at all. Emitting it in end_compute covers all eight sites by construction. It must be emitted before the stream is ended, because merge_control_streams() may rejoin that stream and only a barrier inside it survives the merge.
The measured effect:
| arm | dispatches/token | barriers/token | tok/s |
|---|---|---|---|
| stock | 547 | 547 | 52.5 |
| barrier where Vulkan asks | 547 | 370 | 63.4 |
Width
The second half is the packet. The bit pattern was made settable and swept, with bit N of the mask mapped to bit N of the packet, so the stock pattern is 0x000fffff. Speed first:
| mask | tok/s |
|---|---|
| 0x000fffff (stock) | 52.4 |
| 0x0000ffff | 52.7 |
| 0x000000ff | 56.1 |
| 0x0000007f | 99.3 |
| 0x0000000f | 100.0 |
| 0x00000000 (empty packet) | 108.9 |
One bit accounts for almost all of it. Going from 0x7f to 0xff sets bit 7 alone and drops throughput from 99.3 tok/s to 56.1, a factor of 1.77.
Speed is not the acceptance gate. Correctness is, and the same masks run against the test suite give:
| mask | tok/s | test-backend-ops |
|---|---|---|
| 0x000fffff (stock) | 52.4 | 15937/16613 |
| 0x000000ff | 56.1 | 15937/16613 |
| 0x000000f7 | 56.0 | 15937/16613 |
| 0x0000007f | 99.3 | segfault |
| 0x0000003f | 99.3 | segfault |
| 0x0000002f | 100.3 | segfault |
| 0x0000001f | - | segfault |
| 0x0000000f | 100.0 | segfault |
| 0x00000000 | 108.9 | segfault |
Bit 7 is load-bearing. Every mask that clears it crashes the process instead of merely computing wrong values, which indicates it protects something structural. Bits 8 through 19 are pure cost: dropping them is worth 7.0% with the suite unchanged. Bit 3, usc_cache_inval, is not needed for this workload (0xf7 passes) and is nearly free anyway.
What shipped
| model | stock | fixed | delta |
|---|---|---|---|
| Qwen3-4B Q4_0 | 52.41 | 63.26 | +20.7% |
| Qwen3-4B Q4_K_M | 49.86 | 58.40 | +17.1% |
Narrowing the bit pattern adds a further 1.6 tok/s, reaching 64.8 on Q4_0. That figure comes from a build carrying the sweep knob and is not the default, so it is not in the table above.
The barrier-frequency change is on by default, and HK_LAZY_BARRIER=0 restores the old behaviour. The narrowed bit pattern is not on by default. It is correct for 16613 compute cases, but the bits it drops were added for blits, and showing it safe needs a graphics conformance run that has not been done. It stays behind a flag until then.
What is still open
Three questions remain unanswered.
The function of bit 7 is unknown. It accounts for 14 of the 18 microseconds. Clearing it crashes the test suite, yet llama.cpp keeps decoding at 99 tok/s, so whatever hazard it covers is one the decode path does not create. Identifying it is the most valuable reverse-engineering task left in this driver, and it is worth roughly another 1.5x on this workload.
The marginal bandwidth is 282 GB/s, 35% of the part's peak. Barriers do not explain it: with every barrier removed the effective rate does not improve, and only the fixed cost disappears. The output head reaches 369 GB/s on the same hardware, so the layer matvecs are below what the hardware can do.
The gap to Apple's own driver is about 2.5x. Metal on the same machine is reported at around 160 tok/s for this model, which is ~380 GB/s or 47% of peak. The source of that figure is not given here. This work moved 52.4 to 64.8 tok/s, an improvement of 23.7%. The part still leaves most of its bandwidth unused.
One bit was the whole barrier
The sweep above walks cumulative prefixes: 0xffff, 0xff, 0x7f, 0x3f. Adjacent rows differ by a single bit only for bit 7 and no other, so the sweep cannot show which of bits 0–6 matter. An earlier version of this post implied that it could.
Clearing exactly one bit at a time from 0xff isolates each bit:
| clears | test-backend-ops | tok/s |
|---|---|---|
| nothing | 15937/16613 | 60.05 |
| bit 0 | 15937/16613 | 60.29 |
| bit 1 | 15937/16613 | 60.35 |
| bit 2 | 15937/16613 | 60.90 |
| bit 3 — usc_cache_inval | 15937/16613 | 60.09 |
| bit 4 | 13462/16613 | 60.34 |
| bit 5 | 15825/16613 | 60.04 |
| bit 6 | 12125/16613 | 60.46 |
| bit 7 | crash, no summary | 111.07 |
Bits 0 through 3 are each removable with no correctness change, and removable together. Bits 4, 5 and 6 are each load-bearing and each free: every arm sits at about 60 tok/s whether they are set or not. They fail by very different amounts. Clearing bit 6 loses 3812 cases, bit 4 loses 2475, and bit 5 loses only 112. Three independently required, independently free bits are consistent with three distinct cache domains.
Bit 7 is the entire cost. Clearing it gives +85%, while the other nineteen bits share 3.1% between them.
The asymmetry has a plausible reading, which these measurements do not prove. A bit that is required but costs nothing behaves like an invalidate, where some tags are dropped and no data moves. A bit that is required and costs 85% behaves like a writeback, where dirty data must reach the point of coherence and the barrier has to wait for it. Mesa's own comment names that pair: the PBE cache flushed and the texture cache invalidated. The blit fix set both classes, and the ablation separates them.
The per-event cost follows: 1/60.05 − 1/111.07 is 7.65 ms per token, spread over about 370 barriers, or 20.7 µs per bit-7 event, against the 18.1 µs attributed earlier to "a barrier". The cost belongs to bit 7 and not to the barrier as such.
The ceiling fails a perplexity check
llama-bench reports tokens per second and does not check the output. Every rate measured on a crashing mask therefore measures how fast a wrong answer arrives. Decode with bit 7 cleared does not crash. It runs at 111 tok/s and looks healthy.
llama-perplexity does check the output. The test used the same model, corpus and chunk count, with only the mask changing:
| mask | keeps | perplexity |
|---|---|---|
| 0x000fffff | stock, bits 0–19 | 2.4600 ± 0.12127 |
| 0x000000ff | bits 0–7 | 2.4600 ± 0.12127 |
| 0x000000f8 | bits 3–7 | 2.4600 ± 0.12127 |
| 0x000000f0 | bits 4–7 | 2.4600 ± 0.12127 |
| 0x0000007f | no bit 7 | inf ± inf |
| 0x00000080 | bit 7 only | inf ± inf |
There is no 85% to collect. Bit 7 is required for the outputs to be valid numbers. The 2.08x above remains an upper bound and was labelled results-incorrect from the start. This measurement confirms that label.
No cheaper primitive exists. The complete list of CDM packet types is Launch, Stream Link, Stream Terminate, Barrier and Stream Return, and the machine description contains no wait, fence or semaphore. There is no scoped barrier on this hardware, and the choice of bits is the only gradation available. The kernel-side barrier is a different layer: a stamp wait between whole control streams with no cache-domain fields, so it cannot substitute.
The remaining gain is small. 0x000000f0, bits 4 through 7, is the narrowest mask that holds. It passes the suite at 15937/16613 and returns perplexity bit-identical to stock. It is worth 58.51 to 60.30 tok/s, +3.1%. It is not the default, because both gates are compute-only and the wide mask was written for blits. It needs a graphics gate before it ships.
Credit
Honeykrisp is Alyssa Rosenzweig's and Asahi Lina's work, with Valve and Collabora behind much of it, and the AGX command stream in it was reverse engineered without documentation. The conservative barrier was a correct decision under incomplete information, and the source comment invites revisiting it. This post supplies measurements for that revisit. llama.cpp's Vulkan alias tracking made it possible to count how many barriers were actually needed.
Corrected 2026-10-10: the move from 52.4 to 64.8 tok/s was stated as a 19.2% improvement. It is 23.7% (64.8 / 52.4 = 1.237). The 19.2% figure is close to the same 12.4 tok/s gap taken as a share of 64.8, which is 19.1%.
