﻿# llama.cpp Metal SOLVE_TRI: invalid lanes must not read future output elements

The b12307 Metal SOLVE_TRI fix guards bounds and earlier-output reads; numerical checks and shader validation cover different failure signals.

Author: Retrivium team
Updated: 2026-11-15
Canonical URL: https://retrivium.ai/journal/week46-engine-metal-solve-tri-uncomputed-lanes/
Language: en

The b12307 llama.cpp prerelease adds bounds checks to Metal SOLVE_TRI. The upstream analysis covers both out-of-range accesses and reads of output elements not yet computed. Its NaN-filled regression buffers make the latter visible, illustrating why ordinary zero-filled tests can give incomplete evidence for a triangular solve.

## Allocation validity is not dependency validity

A read can fall within the output allocation yet still be wrong because that element has not been computed at the current step. The PR adds a condition on the output index in addition to bounds checks against the problem size. These protect different contracts. For an ordered solve, earlier-result availability matters alongside address legality, so a memory-capacity check cannot substitute for reviewing the algorithm’s dependency direction.

## Poisoning reveals accidental assumptions

The upstream regression initializes output buffers with NaN to expose invalid SIMD lanes consuming uncomputed output. A zero-initialized buffer can conceal such a dependency by providing a benign value. For independent qualification, use a sentinel that makes unintended consumption visible, then compare the completed solve with a trusted reference. The sentinel itself is test instrumentation, not a change to the mathematical input or an expected production output.

## Remainders need direct coverage

The PR includes non-round problem sizes in its regression tests. Such cases exercise partially occupied SIMD work that an aligned size may avoid. A local suite should retain those tail shapes and include a regular control, rather than scaling only powers of two. Shader validation provides evidence about invalid device loads, while a reference comparison provides evidence about the computed solution. Neither result makes the other redundant.

## Attribute the reported verification

Upstream reports validation before and after the repair on a specified Apple device and macOS version. Those results support the documented reproducer and should remain attributed to the PR. They are not new measurements on every Metal device. The release gives a concrete reason to keep bounds, partial-lane and dependency tests together when qualifying this operator on another system, with the actual executable revision preserved.

## Sources

- [llama.cpp b12307 release](https://github.com/ggml-org/llama.cpp/releases/tag/b12307)
- [llama.cpp pull request #32103](https://github.com/ggml-org/llama.cpp/pull/32103)

## Related reading

- [What does llama.cpp b12221 fix in Metal flash attention scratch writes?](/journal/news-llamacpp-metal-flash-attention-scratch-guard/)
- [CUDA block barriers: participation is part of correctness](/journal/learn-block-barrier-participation/)
