]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commit
metal : tighten input-position loop in kernel_conv_transpose_1d (ggml/1477)
authorCrispStrobe <redacted>
Sun, 10 May 2026 14:45:00 +0000 (16:45 +0200)
committerGeorgi Gerganov <redacted>
Sat, 16 May 2026 13:11:29 +0000 (16:11 +0300)
commit560445bf34c87356ad0f8d80fb03ec5488850b65
treefe3903f8dde0cea6052f0c3f9548667169c85afa
parent2eb3e6b2428c035dd24f996c7dfc48654dc19a6b
metal : tighten input-position loop in kernel_conv_transpose_1d (ggml/1477)

For a given output position j on the time axis, only input positions
i such that i*s0 <= j < i*s0 + K contribute -- i.e.
i in [ceil((j - K + 1)/s0), floor(j/s0)] intersected with [0, IL-1].
That's at most ceil(K/s0) values (typically 2 for stride==K/2
transposed convs).

The current kernel iterates the full IL range and filters with an
`if`, amplifying per-thread work by IL/ceil(K/s0) (~160x for IL=320,
K=10, s0=5 -- a representative codec-decoder shape). On Apple M1
the wasted work trips the macOS GPU watchdog
(kIOGPUCommandBufferCallbackErrorImpactingInteractivity) on long
graphs.

Compute i_min, i_max analytically before the inner loop and iterate
only [i_min, i_max]. Output is bit-identical (same multiplies and
adds in the same order); loop bound shrinks by IL/ceil(K/s0).

Tested on M1 with a downstream consumer running a TTS codec at full
T_codec; end-to-end codec decode ~3-4x faster, zero watchdog hits
across long synthesis runs vs ~30% pre-patch.
ggml/src/ggml-metal/ggml-metal.metal