Skip to content

Add RMS norm and use it - #187

Merged
ggerganov merged 2 commits into
masterfrom
rms_norm
Mar 15, 2023
Merged

ggerganov merged 2 commits into
masterfrom
rms_norm

Conversation

@hoangmit

Copy link
Copy Markdown
Contributor

To resolve issue #173

@hoangmit hoangmit changed the title Add Rms norm Add RMS norm and use it Mar 15, 2023

@ggerganov ggerganov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🦙

@ggerganov
ggerganov merged commit 6eac39b into master Mar 15, 2023
@ggerganov
ggerganov deleted the rms_norm branch March 15, 2023 22:42
blackhole89 pushed a commit that referenced this pull request Mar 15, 2023
* add ggml_rms_norm

* update op num
Deadsg pushed a commit to Deadsg/llama.cpp that referenced this pull request Dec 19, 2023
Seunghhon pushed a commit to Seunghhon/llama.cpp that referenced this pull request Apr 26, 2026
* add ggml_rms_norm

* update op num
phuongncn pushed a commit to phuongncn/llama.cpp-gx10-dgx-sparks-deepseekv4 that referenced this pull request Apr 28, 2026
* iq1_m_r4: basics (quantize/dequantize)

* iq1_m_r4: Zen4 gemm

* iq1_m_r4: neon gemm

* iq1_m_r4: switch to q8_0_x4 also on AVX2/Zen4

With the deltas being per group of 8, we cannot make use
of the q8 sums stored in q8_1, so we get a tiny gain by
using q8_0_x4.

* iq1_m_r4: rename mul_mat_iq1_m_r4_q8_1 to mul_mat_iq1_m_r4_q8_0

---------

Co-authored-by: Iwan Kawrakow <[email protected]>
ljubomirj pushed a commit to ljubomirj/llama.cpp that referenced this pull request May 6, 2026
* add ggml_rms_norm

* update op num
Soket1 pushed a commit to Soket1/llama.cpp-xdna that referenced this pull request Aug 21, 2026
…ive cache key

Host mirror of the #267k-n finding: the 16-wide block exp2 loop in the
flowkv score tile is an AIE2P codegen defect at HEAD_DIM=128 (correct at
64), so the production arm is chosen BY GEOMETRY and the native cache key
must select exactly what op.py selects, or the probe silently links a
different FlowKV object than the xclbin name claims.

- make_cache_key: the FlowKV object fingerprint is now COMPUTED here with
  the same canonical form and FNV-1a constants as
  flowkv_tuning_fingerprint (contract.py) instead of being a hardcoded hex
  string. A hardcoded string desynchronizes from op.py the moment a tuning
  macro is added, which is exactly how ggml-org#266's first A/B came back
  bit-identical. Adds the F3BEST_VALUE_LEGACY / F3BEST_DOT_MULINIT /
  F3BEST_RAWSCORE / F3BEST_SCALAR_EXP / F3BEST_VEC_EXP arms to the key.
- f3best forensics (all under F3BEST_SDUMP, and ggml-org#266's severing rule still
  applies — post_attention and ffn_contribution are void under SDUMP):
  [f3best-sdump-cmp] NPU exp-weights vs a CPU online-bf16 replica,
  [f3best-perhead] the same per q-head of the group (h=1,2 had never been
  measured), [f3best-denom], [f3best-logfit] (affine fit in the log domain
  with the known slope 1.4427, invariant to the running max),
  [f3best-rawscore] (raw scores under FLOWKV_NOEXP, free of both the
  sparsity artifact and the running-max coupling), [f3best-dropone] /
  [f3best-maxdrop] / [f3best-stale0] (pos-0 corruption localizers),
  [f3best-hid].
- Fix the SDUMP tail offset: scores_size is chunk_size*num_q_heads from the
  %sC constant, not from eff_chunk, so cbase = 128*AG = 384 and the guard
  must be the relayed buffer length ITC = CHUNK*AG + 2*AG = 390, not
  PT = E/NH = 384, which rejected exactly that index.
- ggml-org#260 trace BO: d3_bo is allocated at 64KB and reused as the trace BO
  (arg_idx 6), created fresh per entry, so drop the reset().
- compile.py: stage the lowered MLIR that aie.utils.trace.parse needs
  (input_with_addresses.mlir from the .mlir.prj tree) ONLY when
  F3BEST_AIE_TRACE is set — ggml-org#234 requires the default path to leave
  nothing beside the public artifact.
- test_flowkv_contract.py: pin the geometry selection in both op.py and the
  native key, and forbid the refuted FLOWKV_VEC_EXP_DIRECT arm from
  returning.

Measured on 3B (28 layers, post_attention): 0.63-0.92 -> 0.33/0.14/0.20
early, 0.04-0.10 late; final 0.369 -> 0.069. 1B unchanged and still links
the vectorized object (flowkv_64d_h4_c256_tfe2d60c9196a71df.o),
post_attention 0.0072-0.0184. Release build clean, ctest -R '^test-f3best-abi'
green, f3best contract tests pass.

Co-Authored-By: Claude Fable 5 <[email protected]>
Nathanw1014 added a commit to Nathanw1014/llama.cpp that referenced this pull request Oct 21, 2026
qwen4exp : read the gated delta net state in place, and bf16 twins of the small f32 decode weights
Nathanw1014 added a commit to Nathanw1014/llama.cpp that referenced this pull request Oct 21, 2026
…g#193)

# Conflicts:
#	ggml/src/ggml-vulkan/ggml-vulkan.cpp
#	ggml/src/ggml-vulkan/vulkan-shaders/mul_mm.comp
#	src/models/models.h
#	tests/CMakeLists.txt
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Oct 22, 2026
…rastructure)

The infrastructure half of the old block 10.  qwen4exp, QSA and the
hyper-connection ops now live in their own block (11); this block is what they
are built on, and it no longer references them.

Contents:

- The movable-boundary slab and its arena (ggml-cuda-slab.cu,
  ggml-cuda-arena.cu, ggml-cuda-vmm.h, ggml-cuda-moe-cache-hooks.cu): one VMM
  reserve per device split by a movable boundary -- compute below, MoE arena
  above, no HIP call at runtime.  Plus the narrow-band learning, the wide-phase
  auxiliary region, pool-wide routing, and the slab transient absorption.
- The fusion dispatcher (ggml-cuda-try-fuse.cu): the matcher arms moved out of
  ggml-cuda.cu, with every arm implemented inside the kernel TU that owns it.
- The async graph-input ring: batched uploads + lazy done event (PR ggml-org#182), the
  r90 snapshot fix (the scheduler's set_tensor_async path is used for a CPU
  split's output, which the next ubatch rewrites), default-on, and the per-origin
  (per host thread) ordering state of issue ggml-org#201.
- Rope/FWHT fusions: M-ROPE and IMROPE in the RMS_NORM + MUL + ROPE (+ FWHT)
  matcher, BF16 SET_ROWS kept off the 5-op fusion, the q8_0 K/V cache writes
  folded into the rope + FWHT kernel, and the paired GDN q/k norms.
- GDN / attention-gate decode fusions: the BF16 alpha/beta pair with
  softplus(alpha + dt) * a in one mul_mat_vec_f launch (with the r108
  multi-sequence fix and its model-free regression test), the q/k norm pair in
  the direct conv kernel, the attention gate's row-strided view read in place by
  the gate -> Q8_1 kernel, the GDN output norm inside the gate kernel, and
  GGML_CUDA_GDN_TAIL (the sequential tail that writes the rollback snapshots).
- MMB and the HC16 BF16 streams: the per-context MMB state (two contexts
  interleaving must not share the activation cache or the marks), the BF16
  activation copies, DOWN16, and the graph-optimize marking passes.
- The MoE/MMQ decode fusions: mmvq-moe (the dedicated MoE multi-token kernel),
  the gate+up pair fold, silu(gate)*up into the mmq quantize, the dual-output
  matmul, the MoE down fold, and the weighted-down reduction.
- The verify-band arch extension: RDNA3_0 joins RDNA4 in the Q8_1 pre-quantize
  predicate and in the direct GDN conv.
- Meta/scheduler/allocator: the split-state refusals for a straddling split,
  the two-pass graph-optimize protocol (allocs_only / marks_only), graph-memory
  generations so a graph is recaptured when the pool / FA staging / H2D ring
  memory it captured is freed -- including the slab work-boundary shrink of
  issue ggml-org#187 -- the KV prefill pad (LLAMA_KV_N_PAD_PREFILL), and the FA accuracy
  instrument (LLAMA_TEST_OP_NMSE / LLAMA_TEST_SEED).
- bf16 RoPE destinations (TODO ggml-org#83): the missing NORMAL/NEOX bf16
  instantiations, so -ctk bf16 -ctv bf16 prefill does not abort in rope.cu.

Env-read hygiene (no behaviour change): resolve GGML_CUDA_GDN_CHUNKED /
GGML_CUDA_GDN_CHUNKED_BF16 and the GDN_DBG_SKIP_* diagnostics once into values
rather than caching the getenv() pointer: the MSVC CRT returns a buffer that the
next getenv() call overwrites, so a cached pointer is unsafe on Windows.

Build fix: the GGML_CUDA_WORK_ALLOC_DEBUG read in llama_context::graph_reserve
lives in src/ (not linked against the CUDA common.cuh), so it uses a local
static instead of the CUDA helper.

Split note (r109): this commit plus block 11 carries exactly the tree the old
block 10 carried -- the net set is unchanged.  What moved to block 11 is the
qwen4exp model graph, the QSA/indexer ops and their kernels, the
hyper-connection ops, the managed lazy reader and the keys-only indexer cache,
i.e. everything that exists only because of that architecture.  The pieces of
the old block 10 that exist for qwen4exp but are implemented inside a general
kernel TU (the GDN gate/beta fusion, the HC16 MMB BF16 streams, the qwen4exp
weighted-down reduction, the PLE conv fusion) stay here with the TU that owns
them; the HC_BLK16/RES16 marking pass and the indexer relu-sum alloc-dep moved
to block 11 with the matchers they call.
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Oct 22, 2026
…rastructure)

The infrastructure half of the old block 10.  qwen4exp, QSA and the
hyper-connection ops now live in their own block (11); this block is what they
are built on, and it no longer references them.

Contents:

- The movable-boundary slab and its arena (ggml-cuda-slab.cu,
  ggml-cuda-arena.cu, ggml-cuda-vmm.h, ggml-cuda-moe-cache-hooks.cu): one VMM
  reserve per device split by a movable boundary -- compute below, MoE arena
  above, no HIP call at runtime.  Plus the narrow-band learning, the wide-phase
  auxiliary region, pool-wide routing, and the slab transient absorption.
- The fusion dispatcher (ggml-cuda-try-fuse.cu): the matcher arms moved out of
  ggml-cuda.cu, with every arm implemented inside the kernel TU that owns it.
- The async graph-input ring: batched uploads + lazy done event (PR ggml-org#182), the
  r90 snapshot fix (the scheduler's set_tensor_async path is used for a CPU
  split's output, which the next ubatch rewrites), default-on, and the per-origin
  (per host thread) ordering state of issue ggml-org#201.
- Rope/FWHT fusions: M-ROPE and IMROPE in the RMS_NORM + MUL + ROPE (+ FWHT)
  matcher, BF16 SET_ROWS kept off the 5-op fusion, the q8_0 K/V cache writes
  folded into the rope + FWHT kernel, and the paired GDN q/k norms.
- GDN / attention-gate decode fusions: the BF16 alpha/beta pair with
  softplus(alpha + dt) * a in one mul_mat_vec_f launch (with the r108
  multi-sequence fix and its model-free regression test), the q/k norm pair in
  the direct conv kernel, the attention gate's row-strided view read in place by
  the gate -> Q8_1 kernel, the GDN output norm inside the gate kernel, and
  GGML_CUDA_GDN_TAIL (the sequential tail that writes the rollback snapshots).
- MMB and the HC16 BF16 streams: the per-context MMB state (two contexts
  interleaving must not share the activation cache or the marks), the BF16
  activation copies, DOWN16, and the graph-optimize marking passes.
- The MoE/MMQ decode fusions: mmvq-moe (the dedicated MoE multi-token kernel),
  the gate+up pair fold, silu(gate)*up into the mmq quantize, the dual-output
  matmul, the MoE down fold, and the weighted-down reduction.
- The verify-band arch extension: RDNA3_0 joins RDNA4 in the Q8_1 pre-quantize
  predicate and in the direct GDN conv.
- Meta/scheduler/allocator: the split-state refusals for a straddling split,
  the two-pass graph-optimize protocol (allocs_only / marks_only), graph-memory
  generations so a graph is recaptured when the pool / FA staging / H2D ring
  memory it captured is freed -- including the slab work-boundary shrink of
  issue ggml-org#187 -- the KV prefill pad (LLAMA_KV_N_PAD_PREFILL), and the FA accuracy
  instrument (LLAMA_TEST_OP_NMSE / LLAMA_TEST_SEED).
- bf16 RoPE destinations (TODO ggml-org#83): the missing NORMAL/NEOX bf16
  instantiations, so -ctk bf16 -ctv bf16 prefill does not abort in rope.cu.

Env-read hygiene (no behaviour change): resolve GGML_CUDA_GDN_CHUNKED /
GGML_CUDA_GDN_CHUNKED_BF16 and the GDN_DBG_SKIP_* diagnostics once into values
rather than caching the getenv() pointer: the MSVC CRT returns a buffer that the
next getenv() call overwrites, so a cached pointer is unsafe on Windows.

Build fix: the GGML_CUDA_WORK_ALLOC_DEBUG read in llama_context::graph_reserve
lives in src/ (not linked against the CUDA common.cuh), so it uses a local
static instead of the CUDA helper.

Split note (r109): this commit plus block 11 carries exactly the tree the old
block 10 carried -- the net set is unchanged.  What moved to block 11 is the
qwen4exp model graph, the QSA/indexer ops and their kernels, the
hyper-connection ops, the managed lazy reader and the keys-only indexer cache,
i.e. everything that exists only because of that architecture.  The pieces of
the old block 10 that exist for qwen4exp but are implemented inside a general
kernel TU (the GDN gate/beta fusion, the HC16 MMB BF16 streams, the qwen4exp
weighted-down reduction, the PLE conv fusion) stay here with the TU that owns
them; the HC_BLK16/RES16 marking pass and the indexer relu-sum alloc-dep moved
to block 11 with the matchers they call.
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Oct 22, 2026
…rastructure)

The infrastructure half of the old block 10.  qwen4exp, QSA and the
hyper-connection ops now live in their own block (11); this block is what they
are built on, and it no longer references them.

Contents:

- The movable-boundary slab and its arena (ggml-cuda-slab.cu,
  ggml-cuda-arena.cu, ggml-cuda-vmm.h, ggml-cuda-moe-cache-hooks.cu): one VMM
  reserve per device split by a movable boundary -- compute below, MoE arena
  above, no HIP call at runtime.  Plus the narrow-band learning, the wide-phase
  auxiliary region, pool-wide routing, and the slab transient absorption.
- The fusion dispatcher (ggml-cuda-try-fuse.cu): the matcher arms moved out of
  ggml-cuda.cu, with every arm implemented inside the kernel TU that owns it.
- The async graph-input ring: batched uploads + lazy done event (PR ggml-org#182), the
  r90 snapshot fix (the scheduler's set_tensor_async path is used for a CPU
  split's output, which the next ubatch rewrites), default-on, and the per-origin
  (per host thread) ordering state of issue ggml-org#201.
- Rope/FWHT fusions: M-ROPE and IMROPE in the RMS_NORM + MUL + ROPE (+ FWHT)
  matcher, BF16 SET_ROWS kept off the 5-op fusion, the q8_0 K/V cache writes
  folded into the rope + FWHT kernel, and the paired GDN q/k norms.
- GDN / attention-gate decode fusions: the BF16 alpha/beta pair with
  softplus(alpha + dt) * a in one mul_mat_vec_f launch (with the r108
  multi-sequence fix and its model-free regression test), the q/k norm pair in
  the direct conv kernel, the attention gate's row-strided view read in place by
  the gate -> Q8_1 kernel, the GDN output norm inside the gate kernel, and
  GGML_CUDA_GDN_TAIL (the sequential tail that writes the rollback snapshots).
- MMB and the HC16 BF16 streams: the per-context MMB state (two contexts
  interleaving must not share the activation cache or the marks), the BF16
  activation copies, DOWN16, and the graph-optimize marking passes.
- The MoE/MMQ decode fusions: mmvq-moe (the dedicated MoE multi-token kernel),
  the gate+up pair fold, silu(gate)*up into the mmq quantize, the dual-output
  matmul, the MoE down fold, and the weighted-down reduction.
- The verify-band arch extension: RDNA3_0 joins RDNA4 in the Q8_1 pre-quantize
  predicate and in the direct GDN conv.
- Meta/scheduler/allocator: the split-state refusals for a straddling split,
  the two-pass graph-optimize protocol (allocs_only / marks_only), graph-memory
  generations so a graph is recaptured when the pool / FA staging / H2D ring
  memory it captured is freed -- including the slab work-boundary shrink of
  issue ggml-org#187 -- the KV prefill pad (LLAMA_KV_N_PAD_PREFILL), and the FA accuracy
  instrument (LLAMA_TEST_OP_NMSE / LLAMA_TEST_SEED).
- bf16 RoPE destinations (TODO ggml-org#83): the missing NORMAL/NEOX bf16
  instantiations, so -ctk bf16 -ctv bf16 prefill does not abort in rope.cu.

Env-read hygiene (no behaviour change): resolve GGML_CUDA_GDN_CHUNKED /
GGML_CUDA_GDN_CHUNKED_BF16 and the GDN_DBG_SKIP_* diagnostics once into values
rather than caching the getenv() pointer: the MSVC CRT returns a buffer that the
next getenv() call overwrites, so a cached pointer is unsafe on Windows.

Build fix: the GGML_CUDA_WORK_ALLOC_DEBUG read in llama_context::graph_reserve
lives in src/ (not linked against the CUDA common.cuh), so it uses a local
static instead of the CUDA helper.

Split note (r109): this commit plus block 11 carries exactly the tree the old
block 10 carried -- the net set is unchanged.  What moved to block 11 is the
qwen4exp model graph, the QSA/indexer ops and their kernels, the
hyper-connection ops, the managed lazy reader and the keys-only indexer cache,
i.e. everything that exists only because of that architecture.  The pieces of
the old block 10 that exist for qwen4exp but are implemented inside a general
kernel TU (the GDN gate/beta fusion, the HC16 MMB BF16 streams, the qwen4exp
weighted-down reduction, the PLE conv fusion) stay here with the TU that owns
them; the HC_BLK16/RES16 marking pass and the indexer relu-sum alloc-dep moved
to block 11 with the matchers they call.
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Oct 22, 2026
…rastructure)

The infrastructure half of the old block 10.  qwen4exp, QSA and the
hyper-connection ops now live in their own block (11); this block is what they
are built on, and it no longer references them.

Contents:

- The movable-boundary slab and its arena (ggml-cuda-slab.cu,
  ggml-cuda-arena.cu, ggml-cuda-vmm.h, ggml-cuda-moe-cache-hooks.cu): one VMM
  reserve per device split by a movable boundary -- compute below, MoE arena
  above, no HIP call at runtime.  Plus the narrow-band learning, the wide-phase
  auxiliary region, pool-wide routing, and the slab transient absorption.
- The fusion dispatcher (ggml-cuda-try-fuse.cu): the matcher arms moved out of
  ggml-cuda.cu, with every arm implemented inside the kernel TU that owns it.
- The async graph-input ring: batched uploads + lazy done event (PR ggml-org#182), the
  r90 snapshot fix (the scheduler's set_tensor_async path is used for a CPU
  split's output, which the next ubatch rewrites), default-on, and the per-origin
  (per host thread) ordering state of issue ggml-org#201.
- Rope/FWHT fusions: M-ROPE and IMROPE in the RMS_NORM + MUL + ROPE (+ FWHT)
  matcher, BF16 SET_ROWS kept off the 5-op fusion, the q8_0 K/V cache writes
  folded into the rope + FWHT kernel, and the paired GDN q/k norms.
- GDN / attention-gate decode fusions: the BF16 alpha/beta pair with
  softplus(alpha + dt) * a in one mul_mat_vec_f launch (with the r108
  multi-sequence fix and its model-free regression test), the q/k norm pair in
  the direct conv kernel, the attention gate's row-strided view read in place by
  the gate -> Q8_1 kernel, the GDN output norm inside the gate kernel, and
  GGML_CUDA_GDN_TAIL (the sequential tail that writes the rollback snapshots).
- MMB and the HC16 BF16 streams: the per-context MMB state (two contexts
  interleaving must not share the activation cache or the marks), the BF16
  activation copies, DOWN16, and the graph-optimize marking passes.
- The MoE/MMQ decode fusions: mmvq-moe (the dedicated MoE multi-token kernel),
  the gate+up pair fold, silu(gate)*up into the mmq quantize, the dual-output
  matmul, the MoE down fold, and the weighted-down reduction.
- The verify-band arch extension: RDNA3_0 joins RDNA4 in the Q8_1 pre-quantize
  predicate and in the direct GDN conv.
- Meta/scheduler/allocator: the split-state refusals for a straddling split,
  the two-pass graph-optimize protocol (allocs_only / marks_only), graph-memory
  generations so a graph is recaptured when the pool / FA staging / H2D ring
  memory it captured is freed -- including the slab work-boundary shrink of
  issue ggml-org#187 -- the KV prefill pad (LLAMA_KV_N_PAD_PREFILL), and the FA accuracy
  instrument (LLAMA_TEST_OP_NMSE / LLAMA_TEST_SEED).
- bf16 RoPE destinations (TODO ggml-org#83): the missing NORMAL/NEOX bf16
  instantiations, so -ctk bf16 -ctv bf16 prefill does not abort in rope.cu.

Env-read hygiene (no behaviour change): resolve GGML_CUDA_GDN_CHUNKED /
GGML_CUDA_GDN_CHUNKED_BF16 and the GDN_DBG_SKIP_* diagnostics once into values
rather than caching the getenv() pointer: the MSVC CRT returns a buffer that the
next getenv() call overwrites, so a cached pointer is unsafe on Windows.

Build fix: the GGML_CUDA_WORK_ALLOC_DEBUG read in llama_context::graph_reserve
lives in src/ (not linked against the CUDA common.cuh), so it uses a local
static instead of the CUDA helper.

Split note (r109): this commit plus block 11 carries exactly the tree the old
block 10 carried -- the net set is unchanged.  What moved to block 11 is the
qwen4exp model graph, the QSA/indexer ops and their kernels, the
hyper-connection ops, the managed lazy reader and the keys-only indexer cache,
i.e. everything that exists only because of that architecture.  The pieces of
the old block 10 that exist for qwen4exp but are implemented inside a general
kernel TU (the GDN gate/beta fusion, the HC16 MMB BF16 streams, the qwen4exp
weighted-down reduction, the PLE conv fusion) stay here with the TU that owns
them; the HC_BLK16/RES16 marking pass and the indexer relu-sum alloc-dep moved
to block 11 with the matchers they call.
pwilkin added a commit to pwilkin/llama.cpp that referenced this pull request Oct 22, 2026
Brings in PRs ggml-org#185, ggml-org#187-ggml-org#194, ggml-org#200 and ggml-org#207. Two conflicts in qwen4exp
set_input, both with the asynchronous PLE gather of ggml-org#191, and one in
models.h, where ggml-org#194 adds fields next to the EXL3 n-gram table fields
(both kept).

ggml-org#191 moves the host gather into qwen4exp_ple_host_gather and the
on-disk one behind qwen4exp_ple_gather_sync, which a worker thread now
also calls one ubatch ahead. The EXL3 n-gram decode moves there: the
sync gather builds one row decoder (same head lookup, bias and decoder
as before) and hands it to llama_ple_disk (lazy) or to the host gather
(resident). The bias and head offsets are copied per call instead of
held in the graph input, since two threads may gather at once.

ggml-org#194's f16 activation paths (GDN output norm, MoE experts, hc mixed
stream) hand an f16 B to matmuls that EXL3 linears take only in f32: a
qwen4exp EXL3 model with its layers on the GPU aborted in
ggml_exl3_mul_mat while the context probed the fused ops. These paths
now skip EXL3 weights, as they skip bf16 ones.

Assisted-by: Claude Opus 5.5
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Oct 23, 2026
…rastructure)

The infrastructure half of the old block 10.  qwen4exp, QSA and the
hyper-connection ops now live in their own block (11); this block is what they
are built on, and it no longer references them.

Contents:

- The movable-boundary slab and its arena (ggml-cuda-slab.cu,
  ggml-cuda-arena.cu, ggml-cuda-vmm.h, ggml-cuda-moe-cache-hooks.cu): one VMM
  reserve per device split by a movable boundary -- compute below, MoE arena
  above, no HIP call at runtime.  Plus the narrow-band learning, the wide-phase
  auxiliary region, pool-wide routing, and the slab transient absorption.
- The fusion dispatcher (ggml-cuda-try-fuse.cu): the matcher arms moved out of
  ggml-cuda.cu, with every arm implemented inside the kernel TU that owns it.
- The async graph-input ring: batched uploads + lazy done event (PR ggml-org#182), the
  r90 snapshot fix (the scheduler's set_tensor_async path is used for a CPU
  split's output, which the next ubatch rewrites), default-on, and the per-origin
  (per host thread) ordering state of issue ggml-org#201.
- Rope/FWHT fusions: M-ROPE and IMROPE in the RMS_NORM + MUL + ROPE (+ FWHT)
  matcher, BF16 SET_ROWS kept off the 5-op fusion, the q8_0 K/V cache writes
  folded into the rope + FWHT kernel, and the paired GDN q/k norms.
- GDN / attention-gate decode fusions: the BF16 alpha/beta pair with
  softplus(alpha + dt) * a in one mul_mat_vec_f launch (with the r108
  multi-sequence fix and its model-free regression test), the q/k norm pair in
  the direct conv kernel, the attention gate's row-strided view read in place by
  the gate -> Q8_1 kernel, the GDN output norm inside the gate kernel, and
  GGML_CUDA_GDN_TAIL (the sequential tail that writes the rollback snapshots).
- MMB and the HC16 BF16 streams: the per-context MMB state (two contexts
  interleaving must not share the activation cache or the marks), the BF16
  activation copies, DOWN16, and the graph-optimize marking passes.
- The MoE/MMQ decode fusions: mmvq-moe (the dedicated MoE multi-token kernel),
  the gate+up pair fold, silu(gate)*up into the mmq quantize, the dual-output
  matmul, the MoE down fold, and the weighted-down reduction.
- The verify-band arch extension: RDNA3_0 joins RDNA4 in the Q8_1 pre-quantize
  predicate and in the direct GDN conv.
- Meta/scheduler/allocator: the split-state refusals for a straddling split,
  the two-pass graph-optimize protocol (allocs_only / marks_only), graph-memory
  generations so a graph is recaptured when the pool / FA staging / H2D ring
  memory it captured is freed -- including the slab work-boundary shrink of
  issue ggml-org#187 -- the KV prefill pad (LLAMA_KV_N_PAD_PREFILL), and the FA accuracy
  instrument (LLAMA_TEST_OP_NMSE / LLAMA_TEST_SEED).
- bf16 RoPE destinations (TODO ggml-org#83): the missing NORMAL/NEOX bf16
  instantiations, so -ctk bf16 -ctv bf16 prefill does not abort in rope.cu.

Env-read hygiene (no behaviour change): resolve GGML_CUDA_GDN_CHUNKED /
GGML_CUDA_GDN_CHUNKED_BF16 and the GDN_DBG_SKIP_* diagnostics once into values
rather than caching the getenv() pointer: the MSVC CRT returns a buffer that the
next getenv() call overwrites, so a cached pointer is unsafe on Windows.

Build fix: the GGML_CUDA_WORK_ALLOC_DEBUG read in llama_context::graph_reserve
lives in src/ (not linked against the CUDA common.cuh), so it uses a local
static instead of the CUDA helper.

Split note (r109): this commit plus block 11 carries exactly the tree the old
block 10 carried -- the net set is unchanged.  What moved to block 11 is the
qwen4exp model graph, the QSA/indexer ops and their kernels, the
hyper-connection ops, the managed lazy reader and the keys-only indexer cache,
i.e. everything that exists only because of that architecture.  The pieces of
the old block 10 that exist for qwen4exp but are implemented inside a general
kernel TU (the GDN gate/beta fusion, the HC16 MMB BF16 streams, the qwen4exp
weighted-down reduction, the PLE conv fusion) stay here with the TU that owns
them; the HC_BLK16/RES16 marking pass and the indexer relu-sum alloc-dep moved
to block 11 with the matchers they call.
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Oct 23, 2026
…rastructure)

The infrastructure half of the old block 10.  qwen4exp, QSA and the
hyper-connection ops now live in their own block (11); this block is what they
are built on, and it no longer references them.

Contents:

- The movable-boundary slab and its arena (ggml-cuda-slab.cu,
  ggml-cuda-arena.cu, ggml-cuda-vmm.h, ggml-cuda-moe-cache-hooks.cu): one VMM
  reserve per device split by a movable boundary -- compute below, MoE arena
  above, no HIP call at runtime.  Plus the narrow-band learning, the wide-phase
  auxiliary region, pool-wide routing, and the slab transient absorption.
- The fusion dispatcher (ggml-cuda-try-fuse.cu): the matcher arms moved out of
  ggml-cuda.cu, with every arm implemented inside the kernel TU that owns it.
- The async graph-input ring: batched uploads + lazy done event (PR ggml-org#182), the
  r90 snapshot fix (the scheduler's set_tensor_async path is used for a CPU
  split's output, which the next ubatch rewrites), default-on, and the per-origin
  (per host thread) ordering state of issue ggml-org#201.
- Rope/FWHT fusions: M-ROPE and IMROPE in the RMS_NORM + MUL + ROPE (+ FWHT)
  matcher, BF16 SET_ROWS kept off the 5-op fusion, the q8_0 K/V cache writes
  folded into the rope + FWHT kernel, and the paired GDN q/k norms.
- GDN / attention-gate decode fusions: the BF16 alpha/beta pair with
  softplus(alpha + dt) * a in one mul_mat_vec_f launch (with the r108
  multi-sequence fix and its model-free regression test), the q/k norm pair in
  the direct conv kernel, the attention gate's row-strided view read in place by
  the gate -> Q8_1 kernel, the GDN output norm inside the gate kernel, and
  GGML_CUDA_GDN_TAIL (the sequential tail that writes the rollback snapshots).
- MMB and the HC16 BF16 streams: the per-context MMB state (two contexts
  interleaving must not share the activation cache or the marks), the BF16
  activation copies, DOWN16, and the graph-optimize marking passes.
- The MoE/MMQ decode fusions: mmvq-moe (the dedicated MoE multi-token kernel),
  the gate+up pair fold, silu(gate)*up into the mmq quantize, the dual-output
  matmul, the MoE down fold, and the weighted-down reduction.
- The verify-band arch extension: RDNA3_0 joins RDNA4 in the Q8_1 pre-quantize
  predicate and in the direct GDN conv.
- Meta/scheduler/allocator: the split-state refusals for a straddling split,
  the two-pass graph-optimize protocol (allocs_only / marks_only), graph-memory
  generations so a graph is recaptured when the pool / FA staging / H2D ring
  memory it captured is freed -- including the slab work-boundary shrink of
  issue ggml-org#187 -- the KV prefill pad (LLAMA_KV_N_PAD_PREFILL), and the FA accuracy
  instrument (LLAMA_TEST_OP_NMSE / LLAMA_TEST_SEED).
- bf16 RoPE destinations (TODO ggml-org#83): the missing NORMAL/NEOX bf16
  instantiations, so -ctk bf16 -ctv bf16 prefill does not abort in rope.cu.

Env-read hygiene (no behaviour change): resolve GGML_CUDA_GDN_CHUNKED /
GGML_CUDA_GDN_CHUNKED_BF16 and the GDN_DBG_SKIP_* diagnostics once into values
rather than caching the getenv() pointer: the MSVC CRT returns a buffer that the
next getenv() call overwrites, so a cached pointer is unsafe on Windows.

Build fix: the GGML_CUDA_WORK_ALLOC_DEBUG read in llama_context::graph_reserve
lives in src/ (not linked against the CUDA common.cuh), so it uses a local
static instead of the CUDA helper.

Split note (r109): this commit plus block 11 carries exactly the tree the old
block 10 carried -- the net set is unchanged.  What moved to block 11 is the
qwen4exp model graph, the QSA/indexer ops and their kernels, the
hyper-connection ops, the managed lazy reader and the keys-only indexer cache,
i.e. everything that exists only because of that architecture.  The pieces of
the old block 10 that exist for qwen4exp but are implemented inside a general
kernel TU (the GDN gate/beta fusion, the HC16 MMB BF16 streams, the qwen4exp
weighted-down reduction, the PLE conv fusion) stay here with the TU that owns
them; the HC_BLK16/RES16 marking pass and the indexer relu-sum alloc-dep moved
to block 11 with the matchers they call.
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Oct 23, 2026
…rastructure)

The infrastructure half of the old block 10.  qwen4exp, QSA and the
hyper-connection ops now live in their own block (11); this block is what they
are built on, and it no longer references them.

Contents:

- The movable-boundary slab and its arena (ggml-cuda-slab.cu,
  ggml-cuda-arena.cu, ggml-cuda-vmm.h, ggml-cuda-moe-cache-hooks.cu): one VMM
  reserve per device split by a movable boundary -- compute below, MoE arena
  above, no HIP call at runtime.  Plus the narrow-band learning, the wide-phase
  auxiliary region, pool-wide routing, and the slab transient absorption.
- The fusion dispatcher (ggml-cuda-try-fuse.cu): the matcher arms moved out of
  ggml-cuda.cu, with every arm implemented inside the kernel TU that owns it.
- The async graph-input ring: batched uploads + lazy done event (PR ggml-org#182), the
  r90 snapshot fix (the scheduler's set_tensor_async path is used for a CPU
  split's output, which the next ubatch rewrites), default-on, and the per-origin
  (per host thread) ordering state of issue ggml-org#201.
- Rope/FWHT fusions: M-ROPE and IMROPE in the RMS_NORM + MUL + ROPE (+ FWHT)
  matcher, BF16 SET_ROWS kept off the 5-op fusion, the q8_0 K/V cache writes
  folded into the rope + FWHT kernel, and the paired GDN q/k norms.
- GDN / attention-gate decode fusions: the BF16 alpha/beta pair with
  softplus(alpha + dt) * a in one mul_mat_vec_f launch (with the r108
  multi-sequence fix and its model-free regression test), the q/k norm pair in
  the direct conv kernel, the attention gate's row-strided view read in place by
  the gate -> Q8_1 kernel, the GDN output norm inside the gate kernel, and
  GGML_CUDA_GDN_TAIL (the sequential tail that writes the rollback snapshots).
- MMB and the HC16 BF16 streams: the per-context MMB state (two contexts
  interleaving must not share the activation cache or the marks), the BF16
  activation copies, DOWN16, and the graph-optimize marking passes.
- The MoE/MMQ decode fusions: mmvq-moe (the dedicated MoE multi-token kernel),
  the gate+up pair fold, silu(gate)*up into the mmq quantize, the dual-output
  matmul, the MoE down fold, and the weighted-down reduction.
- The verify-band arch extension: RDNA3_0 joins RDNA4 in the Q8_1 pre-quantize
  predicate and in the direct GDN conv.
- Meta/scheduler/allocator: the split-state refusals for a straddling split,
  the two-pass graph-optimize protocol (allocs_only / marks_only), graph-memory
  generations so a graph is recaptured when the pool / FA staging / H2D ring
  memory it captured is freed -- including the slab work-boundary shrink of
  issue ggml-org#187 -- the KV prefill pad (LLAMA_KV_N_PAD_PREFILL), and the FA accuracy
  instrument (LLAMA_TEST_OP_NMSE / LLAMA_TEST_SEED).
- bf16 RoPE destinations (TODO ggml-org#83): the missing NORMAL/NEOX bf16
  instantiations, so -ctk bf16 -ctv bf16 prefill does not abort in rope.cu.

Env-read hygiene (no behaviour change): resolve GGML_CUDA_GDN_CHUNKED /
GGML_CUDA_GDN_CHUNKED_BF16 and the GDN_DBG_SKIP_* diagnostics once into values
rather than caching the getenv() pointer: the MSVC CRT returns a buffer that the
next getenv() call overwrites, so a cached pointer is unsafe on Windows.

Build fix: the GGML_CUDA_WORK_ALLOC_DEBUG read in llama_context::graph_reserve
lives in src/ (not linked against the CUDA common.cuh), so it uses a local
static instead of the CUDA helper.

Split note (r109): this commit plus block 11 carries exactly the tree the old
block 10 carried -- the net set is unchanged.  What moved to block 11 is the
qwen4exp model graph, the QSA/indexer ops and their kernels, the
hyper-connection ops, the managed lazy reader and the keys-only indexer cache,
i.e. everything that exists only because of that architecture.  The pieces of
the old block 10 that exist for qwen4exp but are implemented inside a general
kernel TU (the GDN gate/beta fusion, the HC16 MMB BF16 streams, the qwen4exp
weighted-down reduction, the PLE conv fusion) stay here with the TU that owns
them; the HC_BLK16/RES16 marking pass and the indexer relu-sum alloc-dep moved
to block 11 with the matchers they call.
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Oct 23, 2026
…rastructure)

The infrastructure half of the old block 10.  qwen4exp, QSA and the
hyper-connection ops now live in their own block (11); this block is what they
are built on, and it no longer references them.

Contents:

- The movable-boundary slab and its arena (ggml-cuda-slab.cu,
  ggml-cuda-arena.cu, ggml-cuda-vmm.h, ggml-cuda-moe-cache-hooks.cu): one VMM
  reserve per device split by a movable boundary -- compute below, MoE arena
  above, no HIP call at runtime.  Plus the narrow-band learning, the wide-phase
  auxiliary region, pool-wide routing, and the slab transient absorption.
- The fusion dispatcher (ggml-cuda-try-fuse.cu): the matcher arms moved out of
  ggml-cuda.cu, with every arm implemented inside the kernel TU that owns it.
- The async graph-input ring: batched uploads + lazy done event (PR ggml-org#182), the
  r90 snapshot fix (the scheduler's set_tensor_async path is used for a CPU
  split's output, which the next ubatch rewrites), default-on, and the per-origin
  (per host thread) ordering state of issue ggml-org#201.
- Rope/FWHT fusions: M-ROPE and IMROPE in the RMS_NORM + MUL + ROPE (+ FWHT)
  matcher, BF16 SET_ROWS kept off the 5-op fusion, the q8_0 K/V cache writes
  folded into the rope + FWHT kernel, and the paired GDN q/k norms.
- GDN / attention-gate decode fusions: the BF16 alpha/beta pair with
  softplus(alpha + dt) * a in one mul_mat_vec_f launch (with the r108
  multi-sequence fix and its model-free regression test), the q/k norm pair in
  the direct conv kernel, the attention gate's row-strided view read in place by
  the gate -> Q8_1 kernel, the GDN output norm inside the gate kernel, and
  GGML_CUDA_GDN_TAIL (the sequential tail that writes the rollback snapshots).
- MMB and the HC16 BF16 streams: the per-context MMB state (two contexts
  interleaving must not share the activation cache or the marks), the BF16
  activation copies, DOWN16, and the graph-optimize marking passes.
- The MoE/MMQ decode fusions: mmvq-moe (the dedicated MoE multi-token kernel),
  the gate+up pair fold, silu(gate)*up into the mmq quantize, the dual-output
  matmul, the MoE down fold, and the weighted-down reduction.
- The verify-band arch extension: RDNA3_0 joins RDNA4 in the Q8_1 pre-quantize
  predicate and in the direct GDN conv.
- Meta/scheduler/allocator: the split-state refusals for a straddling split,
  the two-pass graph-optimize protocol (allocs_only / marks_only), graph-memory
  generations so a graph is recaptured when the pool / FA staging / H2D ring
  memory it captured is freed -- including the slab work-boundary shrink of
  issue ggml-org#187 -- the KV prefill pad (LLAMA_KV_N_PAD_PREFILL), and the FA accuracy
  instrument (LLAMA_TEST_OP_NMSE / LLAMA_TEST_SEED).
- bf16 RoPE destinations (TODO ggml-org#83): the missing NORMAL/NEOX bf16
  instantiations, so -ctk bf16 -ctv bf16 prefill does not abort in rope.cu.

Env-read hygiene (no behaviour change): resolve GGML_CUDA_GDN_CHUNKED /
GGML_CUDA_GDN_CHUNKED_BF16 and the GDN_DBG_SKIP_* diagnostics once into values
rather than caching the getenv() pointer: the MSVC CRT returns a buffer that the
next getenv() call overwrites, so a cached pointer is unsafe on Windows.

Build fix: the GGML_CUDA_WORK_ALLOC_DEBUG read in llama_context::graph_reserve
lives in src/ (not linked against the CUDA common.cuh), so it uses a local
static instead of the CUDA helper.

Split note (r109): this commit plus block 11 carries exactly the tree the old
block 10 carried -- the net set is unchanged.  What moved to block 11 is the
qwen4exp model graph, the QSA/indexer ops and their kernels, the
hyper-connection ops, the managed lazy reader and the keys-only indexer cache,
i.e. everything that exists only because of that architecture.  The pieces of
the old block 10 that exist for qwen4exp but are implemented inside a general
kernel TU (the GDN gate/beta fusion, the HC16 MMB BF16 streams, the qwen4exp
weighted-down reduction, the PLE conv fusion) stay here with the TU that owns
them; the HC_BLK16/RES16 marking pass and the indexer relu-sum alloc-dep moved
to block 11 with the matchers they call.
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Oct 23, 2026
…rastructure)

The infrastructure half of the old block 10.  qwen4exp, QSA and the
hyper-connection ops now live in their own block (11); this block is what they
are built on, and it no longer references them.

Contents:

- The movable-boundary slab and its arena (ggml-cuda-slab.cu,
  ggml-cuda-arena.cu, ggml-cuda-vmm.h, ggml-cuda-moe-cache-hooks.cu): one VMM
  reserve per device split by a movable boundary -- compute below, MoE arena
  above, no HIP call at runtime.  Plus the narrow-band learning, the wide-phase
  auxiliary region, pool-wide routing, and the slab transient absorption.
- The fusion dispatcher (ggml-cuda-try-fuse.cu): the matcher arms moved out of
  ggml-cuda.cu, with every arm implemented inside the kernel TU that owns it.
- The async graph-input ring: batched uploads + lazy done event (PR ggml-org#182), the
  r90 snapshot fix (the scheduler's set_tensor_async path is used for a CPU
  split's output, which the next ubatch rewrites), default-on, and the per-origin
  (per host thread) ordering state of issue ggml-org#201.
- Rope/FWHT fusions: M-ROPE and IMROPE in the RMS_NORM + MUL + ROPE (+ FWHT)
  matcher, BF16 SET_ROWS kept off the 5-op fusion, the q8_0 K/V cache writes
  folded into the rope + FWHT kernel, and the paired GDN q/k norms.
- GDN / attention-gate decode fusions: the BF16 alpha/beta pair with
  softplus(alpha + dt) * a in one mul_mat_vec_f launch (with the r108
  multi-sequence fix and its model-free regression test), the q/k norm pair in
  the direct conv kernel, the attention gate's row-strided view read in place by
  the gate -> Q8_1 kernel, the GDN output norm inside the gate kernel, and
  GGML_CUDA_GDN_TAIL (the sequential tail that writes the rollback snapshots).
- MMB and the HC16 BF16 streams: the per-context MMB state (two contexts
  interleaving must not share the activation cache or the marks), the BF16
  activation copies, DOWN16, and the graph-optimize marking passes.
- The MoE/MMQ decode fusions: mmvq-moe (the dedicated MoE multi-token kernel),
  the gate+up pair fold, silu(gate)*up into the mmq quantize, the dual-output
  matmul, the MoE down fold, and the weighted-down reduction.
- The verify-band arch extension: RDNA3_0 joins RDNA4 in the Q8_1 pre-quantize
  predicate and in the direct GDN conv.
- Meta/scheduler/allocator: the split-state refusals for a straddling split,
  the two-pass graph-optimize protocol (allocs_only / marks_only), graph-memory
  generations so a graph is recaptured when the pool / FA staging / H2D ring
  memory it captured is freed -- including the slab work-boundary shrink of
  issue ggml-org#187 -- the KV prefill pad (LLAMA_KV_N_PAD_PREFILL), and the FA accuracy
  instrument (LLAMA_TEST_OP_NMSE / LLAMA_TEST_SEED).
- bf16 RoPE destinations (TODO ggml-org#83): the missing NORMAL/NEOX bf16
  instantiations, so -ctk bf16 -ctv bf16 prefill does not abort in rope.cu.

Env-read hygiene (no behaviour change): resolve GGML_CUDA_GDN_CHUNKED /
GGML_CUDA_GDN_CHUNKED_BF16 and the GDN_DBG_SKIP_* diagnostics once into values
rather than caching the getenv() pointer: the MSVC CRT returns a buffer that the
next getenv() call overwrites, so a cached pointer is unsafe on Windows.

Build fix: the GGML_CUDA_WORK_ALLOC_DEBUG read in llama_context::graph_reserve
lives in src/ (not linked against the CUDA common.cuh), so it uses a local
static instead of the CUDA helper.

Split note (r109): this commit plus block 11 carries exactly the tree the old
block 10 carried -- the net set is unchanged.  What moved to block 11 is the
qwen4exp model graph, the QSA/indexer ops and their kernels, the
hyper-connection ops, the managed lazy reader and the keys-only indexer cache,
i.e. everything that exists only because of that architecture.  The pieces of
the old block 10 that exist for qwen4exp but are implemented inside a general
kernel TU (the GDN gate/beta fusion, the HC16 MMB BF16 streams, the qwen4exp
weighted-down reduction, the PLE conv fusion) stay here with the TU that owns
them; the HC_BLK16/RES16 marking pass and the indexer relu-sum alloc-dep moved
to block 11 with the matchers they call.
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Oct 23, 2026
…rastructure)

The infrastructure half of the old block 10.  qwen4exp, QSA and the
hyper-connection ops now live in their own block (11); this block is what they
are built on, and it no longer references them.

Contents:

- The movable-boundary slab and its arena (ggml-cuda-slab.cu,
  ggml-cuda-arena.cu, ggml-cuda-vmm.h, ggml-cuda-moe-cache-hooks.cu): one VMM
  reserve per device split by a movable boundary -- compute below, MoE arena
  above, no HIP call at runtime.  Plus the narrow-band learning, the wide-phase
  auxiliary region, pool-wide routing, and the slab transient absorption.
- The fusion dispatcher (ggml-cuda-try-fuse.cu): the matcher arms moved out of
  ggml-cuda.cu, with every arm implemented inside the kernel TU that owns it.
- The async graph-input ring: batched uploads + lazy done event (PR ggml-org#182), the
  r90 snapshot fix (the scheduler's set_tensor_async path is used for a CPU
  split's output, which the next ubatch rewrites), default-on, and the per-origin
  (per host thread) ordering state of issue ggml-org#201.
- Rope/FWHT fusions: M-ROPE and IMROPE in the RMS_NORM + MUL + ROPE (+ FWHT)
  matcher, BF16 SET_ROWS kept off the 5-op fusion, the q8_0 K/V cache writes
  folded into the rope + FWHT kernel, and the paired GDN q/k norms.
- GDN / attention-gate decode fusions: the BF16 alpha/beta pair with
  softplus(alpha + dt) * a in one mul_mat_vec_f launch (with the r108
  multi-sequence fix and its model-free regression test), the q/k norm pair in
  the direct conv kernel, the attention gate's row-strided view read in place by
  the gate -> Q8_1 kernel, the GDN output norm inside the gate kernel, and
  GGML_CUDA_GDN_TAIL (the sequential tail that writes the rollback snapshots).
- MMB and the HC16 BF16 streams: the per-context MMB state (two contexts
  interleaving must not share the activation cache or the marks), the BF16
  activation copies, DOWN16, and the graph-optimize marking passes.
- The MoE/MMQ decode fusions: mmvq-moe (the dedicated MoE multi-token kernel),
  the gate+up pair fold, silu(gate)*up into the mmq quantize, the dual-output
  matmul, the MoE down fold, and the weighted-down reduction.
- The verify-band arch extension: RDNA3_0 joins RDNA4 in the Q8_1 pre-quantize
  predicate and in the direct GDN conv.
- Meta/scheduler/allocator: the split-state refusals for a straddling split,
  the two-pass graph-optimize protocol (allocs_only / marks_only), graph-memory
  generations so a graph is recaptured when the pool / FA staging / H2D ring
  memory it captured is freed -- including the slab work-boundary shrink of
  issue ggml-org#187 -- the KV prefill pad (LLAMA_KV_N_PAD_PREFILL), and the FA accuracy
  instrument (LLAMA_TEST_OP_NMSE / LLAMA_TEST_SEED).
- bf16 RoPE destinations (TODO ggml-org#83): the missing NORMAL/NEOX bf16
  instantiations, so -ctk bf16 -ctv bf16 prefill does not abort in rope.cu.

Env-read hygiene (no behaviour change): resolve GGML_CUDA_GDN_CHUNKED /
GGML_CUDA_GDN_CHUNKED_BF16 and the GDN_DBG_SKIP_* diagnostics once into values
rather than caching the getenv() pointer: the MSVC CRT returns a buffer that the
next getenv() call overwrites, so a cached pointer is unsafe on Windows.

Build fix: the GGML_CUDA_WORK_ALLOC_DEBUG read in llama_context::graph_reserve
lives in src/ (not linked against the CUDA common.cuh), so it uses a local
static instead of the CUDA helper.

Split note (r109): this commit plus block 11 carries exactly the tree the old
block 10 carried -- the net set is unchanged.  What moved to block 11 is the
qwen4exp model graph, the QSA/indexer ops and their kernels, the
hyper-connection ops, the managed lazy reader and the keys-only indexer cache,
i.e. everything that exists only because of that architecture.  The pieces of
the old block 10 that exist for qwen4exp but are implemented inside a general
kernel TU (the GDN gate/beta fusion, the HC16 MMB BF16 streams, the qwen4exp
weighted-down reduction, the PLE conv fusion) stay here with the TU that owns
them; the HC_BLK16/RES16 marking pass and the indexer relu-sum alloc-dep moved
to block 11 with the matchers they call.
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Oct 24, 2026
…rastructure)

The infrastructure half of the old block 10.  qwen4exp, QSA and the
hyper-connection ops now live in their own block (11); this block is what they
are built on, and it no longer references them.

Contents:

- The movable-boundary slab and its arena (ggml-cuda-slab.cu,
  ggml-cuda-arena.cu, ggml-cuda-vmm.h, ggml-cuda-moe-cache-hooks.cu): one VMM
  reserve per device split by a movable boundary -- compute below, MoE arena
  above, no HIP call at runtime.  Plus the narrow-band learning, the wide-phase
  auxiliary region, pool-wide routing, and the slab transient absorption.
- The fusion dispatcher (ggml-cuda-try-fuse.cu): the matcher arms moved out of
  ggml-cuda.cu, with every arm implemented inside the kernel TU that owns it.
- The async graph-input ring: batched uploads + lazy done event (PR ggml-org#182), the
  r90 snapshot fix (the scheduler's set_tensor_async path is used for a CPU
  split's output, which the next ubatch rewrites), default-on, and the per-origin
  (per host thread) ordering state of issue ggml-org#201.
- Rope/FWHT fusions: M-ROPE and IMROPE in the RMS_NORM + MUL + ROPE (+ FWHT)
  matcher, BF16 SET_ROWS kept off the 5-op fusion, the q8_0 K/V cache writes
  folded into the rope + FWHT kernel, and the paired GDN q/k norms.
- GDN / attention-gate decode fusions: the BF16 alpha/beta pair with
  softplus(alpha + dt) * a in one mul_mat_vec_f launch (with the r108
  multi-sequence fix and its model-free regression test), the q/k norm pair in
  the direct conv kernel, the attention gate's row-strided view read in place by
  the gate -> Q8_1 kernel, the GDN output norm inside the gate kernel, and
  GGML_CUDA_GDN_TAIL (the sequential tail that writes the rollback snapshots).
- MMB and the HC16 BF16 streams: the per-context MMB state (two contexts
  interleaving must not share the activation cache or the marks), the BF16
  activation copies, DOWN16, and the graph-optimize marking passes.
- The MoE/MMQ decode fusions: mmvq-moe (the dedicated MoE multi-token kernel),
  the gate+up pair fold, silu(gate)*up into the mmq quantize, the dual-output
  matmul, the MoE down fold, and the weighted-down reduction.
- The verify-band arch extension: RDNA3_0 joins RDNA4 in the Q8_1 pre-quantize
  predicate and in the direct GDN conv.
- Meta/scheduler/allocator: the split-state refusals for a straddling split,
  the two-pass graph-optimize protocol (allocs_only / marks_only), graph-memory
  generations so a graph is recaptured when the pool / FA staging / H2D ring
  memory it captured is freed -- including the slab work-boundary shrink of
  issue ggml-org#187 -- the KV prefill pad (LLAMA_KV_N_PAD_PREFILL), and the FA accuracy
  instrument (LLAMA_TEST_OP_NMSE / LLAMA_TEST_SEED).
- bf16 RoPE destinations (TODO ggml-org#83): the missing NORMAL/NEOX bf16
  instantiations, so -ctk bf16 -ctv bf16 prefill does not abort in rope.cu.

Env-read hygiene (no behaviour change): resolve GGML_CUDA_GDN_CHUNKED /
GGML_CUDA_GDN_CHUNKED_BF16 and the GDN_DBG_SKIP_* diagnostics once into values
rather than caching the getenv() pointer: the MSVC CRT returns a buffer that the
next getenv() call overwrites, so a cached pointer is unsafe on Windows.

Build fix: the GGML_CUDA_WORK_ALLOC_DEBUG read in llama_context::graph_reserve
lives in src/ (not linked against the CUDA common.cuh), so it uses a local
static instead of the CUDA helper.

Split note (r109): this commit plus block 11 carries exactly the tree the old
block 10 carried -- the net set is unchanged.  What moved to block 11 is the
qwen4exp model graph, the QSA/indexer ops and their kernels, the
hyper-connection ops, the managed lazy reader and the keys-only indexer cache,
i.e. everything that exists only because of that architecture.  The pieces of
the old block 10 that exist for qwen4exp but are implemented inside a general
kernel TU (the GDN gate/beta fusion, the HC16 MMB BF16 streams, the qwen4exp
weighted-down reduction, the PLE conv fusion) stay here with the TU that owns
them; the HC_BLK16/RES16 marking pass and the indexer relu-sum alloc-dep moved
to block 11 with the matchers they call.
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Oct 25, 2026
…rastructure)

The infrastructure half of the old block 10.  qwen4exp, QSA and the
hyper-connection ops now live in their own block (11); this block is what they
are built on, and it no longer references them.

Contents:

- The movable-boundary slab and its arena (ggml-cuda-slab.cu,
  ggml-cuda-arena.cu, ggml-cuda-vmm.h, ggml-cuda-moe-cache-hooks.cu): one VMM
  reserve per device split by a movable boundary -- compute below, MoE arena
  above, no HIP call at runtime.  Plus the narrow-band learning, the wide-phase
  auxiliary region, pool-wide routing, and the slab transient absorption.
- The fusion dispatcher (ggml-cuda-try-fuse.cu): the matcher arms moved out of
  ggml-cuda.cu, with every arm implemented inside the kernel TU that owns it.
- The async graph-input ring: batched uploads + lazy done event (PR ggml-org#182), the
  r90 snapshot fix (the scheduler's set_tensor_async path is used for a CPU
  split's output, which the next ubatch rewrites), default-on, and the per-origin
  (per host thread) ordering state of issue ggml-org#201.
- Rope/FWHT fusions: M-ROPE and IMROPE in the RMS_NORM + MUL + ROPE (+ FWHT)
  matcher, BF16 SET_ROWS kept off the 5-op fusion, the q8_0 K/V cache writes
  folded into the rope + FWHT kernel, and the paired GDN q/k norms.
- GDN / attention-gate decode fusions: the BF16 alpha/beta pair with
  softplus(alpha + dt) * a in one mul_mat_vec_f launch (with the r108
  multi-sequence fix and its model-free regression test), the q/k norm pair in
  the direct conv kernel, the attention gate's row-strided view read in place by
  the gate -> Q8_1 kernel, the GDN output norm inside the gate kernel, and
  GGML_CUDA_GDN_TAIL (the sequential tail that writes the rollback snapshots).
- MMB and the HC16 BF16 streams: the per-context MMB state (two contexts
  interleaving must not share the activation cache or the marks), the BF16
  activation copies, DOWN16, and the graph-optimize marking passes.
- The MoE/MMQ decode fusions: mmvq-moe (the dedicated MoE multi-token kernel),
  the gate+up pair fold, silu(gate)*up into the mmq quantize, the dual-output
  matmul, the MoE down fold, and the weighted-down reduction.
- The verify-band arch extension: RDNA3_0 joins RDNA4 in the Q8_1 pre-quantize
  predicate and in the direct GDN conv.
- Meta/scheduler/allocator: the split-state refusals for a straddling split,
  the two-pass graph-optimize protocol (allocs_only / marks_only), graph-memory
  generations so a graph is recaptured when the pool / FA staging / H2D ring
  memory it captured is freed -- including the slab work-boundary shrink of
  issue ggml-org#187 -- the KV prefill pad (LLAMA_KV_N_PAD_PREFILL), and the FA accuracy
  instrument (LLAMA_TEST_OP_NMSE / LLAMA_TEST_SEED).
- bf16 RoPE destinations (TODO ggml-org#83): the missing NORMAL/NEOX bf16
  instantiations, so -ctk bf16 -ctv bf16 prefill does not abort in rope.cu.

Env-read hygiene (no behaviour change): resolve GGML_CUDA_GDN_CHUNKED /
GGML_CUDA_GDN_CHUNKED_BF16 and the GDN_DBG_SKIP_* diagnostics once into values
rather than caching the getenv() pointer: the MSVC CRT returns a buffer that the
next getenv() call overwrites, so a cached pointer is unsafe on Windows.

Build fix: the GGML_CUDA_WORK_ALLOC_DEBUG read in llama_context::graph_reserve
lives in src/ (not linked against the CUDA common.cuh), so it uses a local
static instead of the CUDA helper.

Split note (r109): this commit plus block 11 carries exactly the tree the old
block 10 carried -- the net set is unchanged.  What moved to block 11 is the
qwen4exp model graph, the QSA/indexer ops and their kernels, the
hyper-connection ops, the managed lazy reader and the keys-only indexer cache,
i.e. everything that exists only because of that architecture.  The pieces of
the old block 10 that exist for qwen4exp but are implemented inside a general
kernel TU (the GDN gate/beta fusion, the HC16 MMB BF16 streams, the qwen4exp
weighted-down reduction, the PLE conv fusion) stay here with the TU that owns
them; the HC_BLK16/RES16 marking pass and the indexer relu-sum alloc-dep moved
to block 11 with the matchers they call.

Windows HIP build (issue ggml-org#217): the tables-registration slack guard uses the int64_t min/max helpers
block 09 defines instead of `std::min<int64_t>`/`std::max<int64_t>`.  With HIP on Windows (clang + the
MSVC STL) clang's force-included `cuda_wrappers/algorithm` and the MSVC STL `<utility>` each define an
inline `std::min<long long>` (`int64_t` is `__int64` there, and the `enable_if` that makes clang's
version win overload resolution is not part of the mangled name), so a translation unit that
instantiates both fails to codegen with "definition with same mangled name".  Behaviour is unchanged.

Amended (r132): the block-10 arms of the Q8_1 cache fix that block 08 introduces.  The fused GLU -> Q8_1 site's
key walk stops at the first pointer change (the fused write is keyed by the matmul's src1, and must not take the
root's entry for an offset view), and both of this block's gated-q8_1 launch arms -- the fused norm+gate kernel
and the GLU write -- validate their sources with q8_1_src_range_ok() before launching.  From PR ggml-org#218 (@slavap);
the rule and the validation are recorded with block 08.

Co-authored-by: Slava P. <[email protected]>
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Oct 25, 2026
…rastructure)

The infrastructure half of the old block 10.  qwen4exp, QSA and the
hyper-connection ops now live in their own block (11); this block is what they
are built on, and it no longer references them.

Contents:

- The movable-boundary slab and its arena (ggml-cuda-slab.cu,
  ggml-cuda-arena.cu, ggml-cuda-vmm.h, ggml-cuda-moe-cache-hooks.cu): one VMM
  reserve per device split by a movable boundary -- compute below, MoE arena
  above, no HIP call at runtime.  Plus the narrow-band learning, the wide-phase
  auxiliary region, pool-wide routing, and the slab transient absorption.
- The fusion dispatcher (ggml-cuda-try-fuse.cu): the matcher arms moved out of
  ggml-cuda.cu, with every arm implemented inside the kernel TU that owns it.
- The async graph-input ring: batched uploads + lazy done event (PR ggml-org#182), the
  r90 snapshot fix (the scheduler's set_tensor_async path is used for a CPU
  split's output, which the next ubatch rewrites), default-on, and the per-origin
  (per host thread) ordering state of issue ggml-org#201.
- Rope/FWHT fusions: M-ROPE and IMROPE in the RMS_NORM + MUL + ROPE (+ FWHT)
  matcher, BF16 SET_ROWS kept off the 5-op fusion, the q8_0 K/V cache writes
  folded into the rope + FWHT kernel, and the paired GDN q/k norms.
- GDN / attention-gate decode fusions: the BF16 alpha/beta pair with
  softplus(alpha + dt) * a in one mul_mat_vec_f launch (with the r108
  multi-sequence fix and its model-free regression test), the q/k norm pair in
  the direct conv kernel, the attention gate's row-strided view read in place by
  the gate -> Q8_1 kernel, the GDN output norm inside the gate kernel, and
  GGML_CUDA_GDN_TAIL (the sequential tail that writes the rollback snapshots).
- MMB and the HC16 BF16 streams: the per-context MMB state (two contexts
  interleaving must not share the activation cache or the marks), the BF16
  activation copies, DOWN16, and the graph-optimize marking passes.
- The MoE/MMQ decode fusions: mmvq-moe (the dedicated MoE multi-token kernel),
  the gate+up pair fold, silu(gate)*up into the mmq quantize, the dual-output
  matmul, the MoE down fold, and the weighted-down reduction.
- The verify-band arch extension: RDNA3_0 joins RDNA4 in the Q8_1 pre-quantize
  predicate and in the direct GDN conv.
- Meta/scheduler/allocator: the split-state refusals for a straddling split,
  the two-pass graph-optimize protocol (allocs_only / marks_only), graph-memory
  generations so a graph is recaptured when the pool / FA staging / H2D ring
  memory it captured is freed -- including the slab work-boundary shrink of
  issue ggml-org#187 -- the KV prefill pad (LLAMA_KV_N_PAD_PREFILL), and the FA accuracy
  instrument (LLAMA_TEST_OP_NMSE / LLAMA_TEST_SEED).
- bf16 RoPE destinations (TODO ggml-org#83): the missing NORMAL/NEOX bf16
  instantiations, so -ctk bf16 -ctv bf16 prefill does not abort in rope.cu.

Env-read hygiene (no behaviour change): resolve GGML_CUDA_GDN_CHUNKED /
GGML_CUDA_GDN_CHUNKED_BF16 and the GDN_DBG_SKIP_* diagnostics once into values
rather than caching the getenv() pointer: the MSVC CRT returns a buffer that the
next getenv() call overwrites, so a cached pointer is unsafe on Windows.

Build fix: the GGML_CUDA_WORK_ALLOC_DEBUG read in llama_context::graph_reserve
lives in src/ (not linked against the CUDA common.cuh), so it uses a local
static instead of the CUDA helper.

Split note (r109): this commit plus block 11 carries exactly the tree the old
block 10 carried -- the net set is unchanged.  What moved to block 11 is the
qwen4exp model graph, the QSA/indexer ops and their kernels, the
hyper-connection ops, the managed lazy reader and the keys-only indexer cache,
i.e. everything that exists only because of that architecture.  The pieces of
the old block 10 that exist for qwen4exp but are implemented inside a general
kernel TU (the GDN gate/beta fusion, the HC16 MMB BF16 streams, the qwen4exp
weighted-down reduction, the PLE conv fusion) stay here with the TU that owns
them; the HC_BLK16/RES16 marking pass and the indexer relu-sum alloc-dep moved
to block 11 with the matchers they call.

Windows HIP build (issue ggml-org#217): the tables-registration slack guard uses the int64_t min/max helpers
block 09 defines instead of `std::min<int64_t>`/`std::max<int64_t>`.  With HIP on Windows (clang + the
MSVC STL) clang's force-included `cuda_wrappers/algorithm` and the MSVC STL `<utility>` each define an
inline `std::min<long long>` (`int64_t` is `__int64` there, and the `enable_if` that makes clang's
version win overload resolution is not part of the mangled name), so a translation unit that
instantiates both fails to codegen with "definition with same mangled name".  Behaviour is unchanged.

Amended (r132): the block-10 arms of the Q8_1 cache fix that block 08 introduces.  The fused GLU -> Q8_1 site's
key walk stops at the first pointer change (the fused write is keyed by the matmul's src1, and must not take the
root's entry for an offset view), and both of this block's gated-q8_1 launch arms -- the fused norm+gate kernel
and the GLU write -- validate their sources with q8_1_src_range_ok() before launching.  From PR ggml-org#218 (@slavap);
the rule and the validation are recorded with block 08.

Co-authored-by: Slava P. <[email protected]>
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Oct 25, 2026
…rastructure)

The infrastructure half of the old block 10.  qwen4exp, QSA and the
hyper-connection ops now live in their own block (11); this block is what they
are built on, and it no longer references them.

Contents:

- The movable-boundary slab and its arena (ggml-cuda-slab.cu,
  ggml-cuda-arena.cu, ggml-cuda-vmm.h, ggml-cuda-moe-cache-hooks.cu): one VMM
  reserve per device split by a movable boundary -- compute below, MoE arena
  above, no HIP call at runtime.  Plus the narrow-band learning, the wide-phase
  auxiliary region, pool-wide routing, and the slab transient absorption.
- The fusion dispatcher (ggml-cuda-try-fuse.cu): the matcher arms moved out of
  ggml-cuda.cu, with every arm implemented inside the kernel TU that owns it.
- The async graph-input ring: batched uploads + lazy done event (PR ggml-org#182), the
  r90 snapshot fix (the scheduler's set_tensor_async path is used for a CPU
  split's output, which the next ubatch rewrites), default-on, and the per-origin
  (per host thread) ordering state of issue ggml-org#201.
- Rope/FWHT fusions: M-ROPE and IMROPE in the RMS_NORM + MUL + ROPE (+ FWHT)
  matcher, BF16 SET_ROWS kept off the 5-op fusion, the q8_0 K/V cache writes
  folded into the rope + FWHT kernel, and the paired GDN q/k norms.
- GDN / attention-gate decode fusions: the BF16 alpha/beta pair with
  softplus(alpha + dt) * a in one mul_mat_vec_f launch (with the r108
  multi-sequence fix and its model-free regression test), the q/k norm pair in
  the direct conv kernel, the attention gate's row-strided view read in place by
  the gate -> Q8_1 kernel, the GDN output norm inside the gate kernel, and
  GGML_CUDA_GDN_TAIL (the sequential tail that writes the rollback snapshots).
- MMB and the HC16 BF16 streams: the per-context MMB state (two contexts
  interleaving must not share the activation cache or the marks), the BF16
  activation copies, DOWN16, and the graph-optimize marking passes.
- The MoE/MMQ decode fusions: mmvq-moe (the dedicated MoE multi-token kernel),
  the gate+up pair fold, silu(gate)*up into the mmq quantize, the dual-output
  matmul, the MoE down fold, and the weighted-down reduction.
- The verify-band arch extension: RDNA3_0 joins RDNA4 in the Q8_1 pre-quantize
  predicate and in the direct GDN conv.
- Meta/scheduler/allocator: the split-state refusals for a straddling split,
  the two-pass graph-optimize protocol (allocs_only / marks_only), graph-memory
  generations so a graph is recaptured when the pool / FA staging / H2D ring
  memory it captured is freed -- including the slab work-boundary shrink of
  issue ggml-org#187 -- the KV prefill pad (LLAMA_KV_N_PAD_PREFILL), and the FA accuracy
  instrument (LLAMA_TEST_OP_NMSE / LLAMA_TEST_SEED).
- bf16 RoPE destinations (TODO ggml-org#83): the missing NORMAL/NEOX bf16
  instantiations, so -ctk bf16 -ctv bf16 prefill does not abort in rope.cu.

Env-read hygiene (no behaviour change): resolve GGML_CUDA_GDN_CHUNKED /
GGML_CUDA_GDN_CHUNKED_BF16 and the GDN_DBG_SKIP_* diagnostics once into values
rather than caching the getenv() pointer: the MSVC CRT returns a buffer that the
next getenv() call overwrites, so a cached pointer is unsafe on Windows.

Build fix: the GGML_CUDA_WORK_ALLOC_DEBUG read in llama_context::graph_reserve
lives in src/ (not linked against the CUDA common.cuh), so it uses a local
static instead of the CUDA helper.

Split note (r109): this commit plus block 11 carries exactly the tree the old
block 10 carried -- the net set is unchanged.  What moved to block 11 is the
qwen4exp model graph, the QSA/indexer ops and their kernels, the
hyper-connection ops, the managed lazy reader and the keys-only indexer cache,
i.e. everything that exists only because of that architecture.  The pieces of
the old block 10 that exist for qwen4exp but are implemented inside a general
kernel TU (the GDN gate/beta fusion, the HC16 MMB BF16 streams, the qwen4exp
weighted-down reduction, the PLE conv fusion) stay here with the TU that owns
them; the HC_BLK16/RES16 marking pass and the indexer relu-sum alloc-dep moved
to block 11 with the matchers they call.

Windows HIP build (issue ggml-org#217): the tables-registration slack guard uses the int64_t min/max helpers
block 09 defines instead of `std::min<int64_t>`/`std::max<int64_t>`.  With HIP on Windows (clang + the
MSVC STL) clang's force-included `cuda_wrappers/algorithm` and the MSVC STL `<utility>` each define an
inline `std::min<long long>` (`int64_t` is `__int64` there, and the `enable_if` that makes clang's
version win overload resolution is not part of the mangled name), so a translation unit that
instantiates both fails to codegen with "definition with same mangled name".  Behaviour is unchanged.

Amended (r132): the block-10 arms of the Q8_1 cache fix that block 08 introduces.  The fused GLU -> Q8_1 site's
key walk stops at the first pointer change (the fused write is keyed by the matmul's src1, and must not take the
root's entry for an offset view), and both of this block's gated-q8_1 launch arms -- the fused norm+gate kernel
and the GLU write -- validate their sources with q8_1_src_range_ok() before launching.  From PR ggml-org#218 (@slavap);
the rule and the validation are recorded with block 08.

Co-authored-by: Slava P. <[email protected]>
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Oct 25, 2026
…rastructure)

The infrastructure half of the old block 10.  qwen4exp, QSA and the
hyper-connection ops now live in their own block (11); this block is what they
are built on, and it no longer references them.

Contents:

- The movable-boundary slab and its arena (ggml-cuda-slab.cu,
  ggml-cuda-arena.cu, ggml-cuda-vmm.h, ggml-cuda-moe-cache-hooks.cu): one VMM
  reserve per device split by a movable boundary -- compute below, MoE arena
  above, no HIP call at runtime.  Plus the narrow-band learning, the wide-phase
  auxiliary region, pool-wide routing, and the slab transient absorption.
- The fusion dispatcher (ggml-cuda-try-fuse.cu): the matcher arms moved out of
  ggml-cuda.cu, with every arm implemented inside the kernel TU that owns it.
- The async graph-input ring: batched uploads + lazy done event (PR ggml-org#182), the
  r90 snapshot fix (the scheduler's set_tensor_async path is used for a CPU
  split's output, which the next ubatch rewrites), default-on, and the per-origin
  (per host thread) ordering state of issue ggml-org#201.
- Rope/FWHT fusions: M-ROPE and IMROPE in the RMS_NORM + MUL + ROPE (+ FWHT)
  matcher, BF16 SET_ROWS kept off the 5-op fusion, the q8_0 K/V cache writes
  folded into the rope + FWHT kernel, and the paired GDN q/k norms.
- GDN / attention-gate decode fusions: the BF16 alpha/beta pair with
  softplus(alpha + dt) * a in one mul_mat_vec_f launch (with the r108
  multi-sequence fix and its model-free regression test), the q/k norm pair in
  the direct conv kernel, the attention gate's row-strided view read in place by
  the gate -> Q8_1 kernel, the GDN output norm inside the gate kernel, and
  GGML_CUDA_GDN_TAIL (the sequential tail that writes the rollback snapshots).
- MMB and the HC16 BF16 streams: the per-context MMB state (two contexts
  interleaving must not share the activation cache or the marks), the BF16
  activation copies, DOWN16, and the graph-optimize marking passes.
- The MoE/MMQ decode fusions: mmvq-moe (the dedicated MoE multi-token kernel),
  the gate+up pair fold, silu(gate)*up into the mmq quantize, the dual-output
  matmul, the MoE down fold, and the weighted-down reduction.
- The verify-band arch extension: RDNA3_0 joins RDNA4 in the Q8_1 pre-quantize
  predicate and in the direct GDN conv.
- Meta/scheduler/allocator: the split-state refusals for a straddling split,
  the two-pass graph-optimize protocol (allocs_only / marks_only), graph-memory
  generations so a graph is recaptured when the pool / FA staging / H2D ring
  memory it captured is freed -- including the slab work-boundary shrink of
  issue ggml-org#187 -- the KV prefill pad (LLAMA_KV_N_PAD_PREFILL), and the FA accuracy
  instrument (LLAMA_TEST_OP_NMSE / LLAMA_TEST_SEED).
- bf16 RoPE destinations (TODO ggml-org#83): the missing NORMAL/NEOX bf16
  instantiations, so -ctk bf16 -ctv bf16 prefill does not abort in rope.cu.

Env-read hygiene (no behaviour change): resolve GGML_CUDA_GDN_CHUNKED /
GGML_CUDA_GDN_CHUNKED_BF16 and the GDN_DBG_SKIP_* diagnostics once into values
rather than caching the getenv() pointer: the MSVC CRT returns a buffer that the
next getenv() call overwrites, so a cached pointer is unsafe on Windows.

Build fix: the GGML_CUDA_WORK_ALLOC_DEBUG read in llama_context::graph_reserve
lives in src/ (not linked against the CUDA common.cuh), so it uses a local
static instead of the CUDA helper.

Split note (r109): this commit plus block 11 carries exactly the tree the old
block 10 carried -- the net set is unchanged.  What moved to block 11 is the
qwen4exp model graph, the QSA/indexer ops and their kernels, the
hyper-connection ops, the managed lazy reader and the keys-only indexer cache,
i.e. everything that exists only because of that architecture.  The pieces of
the old block 10 that exist for qwen4exp but are implemented inside a general
kernel TU (the GDN gate/beta fusion, the HC16 MMB BF16 streams, the qwen4exp
weighted-down reduction, the PLE conv fusion) stay here with the TU that owns
them; the HC_BLK16/RES16 marking pass and the indexer relu-sum alloc-dep moved
to block 11 with the matchers they call.

Windows HIP build (issue ggml-org#217): the tables-registration slack guard uses the int64_t min/max helpers
block 09 defines instead of `std::min<int64_t>`/`std::max<int64_t>`.  With HIP on Windows (clang + the
MSVC STL) clang's force-included `cuda_wrappers/algorithm` and the MSVC STL `<utility>` each define an
inline `std::min<long long>` (`int64_t` is `__int64` there, and the `enable_if` that makes clang's
version win overload resolution is not part of the mangled name), so a translation unit that
instantiates both fails to codegen with "definition with same mangled name".  Behaviour is unchanged.

Amended (r132): the block-10 arms of the Q8_1 cache fix that block 08 introduces.  The fused GLU -> Q8_1 site's
key walk stops at the first pointer change (the fused write is keyed by the matmul's src1, and must not take the
root's entry for an offset view), and both of this block's gated-q8_1 launch arms -- the fused norm+gate kernel
and the GLU write -- validate their sources with q8_1_src_range_ok() before launching.  From PR ggml-org#218 (@slavap);
the rule and the validation are recorded with block 08.

Co-authored-by: Slava P. <[email protected]>
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Oct 26, 2026
…rastructure)

The infrastructure half of the old block 10.  qwen4exp, QSA and the
hyper-connection ops now live in their own block (11); this block is what they
are built on, and it no longer references them.

Contents:

- The movable-boundary slab and its arena (ggml-cuda-slab.cu,
  ggml-cuda-arena.cu, ggml-cuda-vmm.h, ggml-cuda-moe-cache-hooks.cu): one VMM
  reserve per device split by a movable boundary -- compute below, MoE arena
  above, no HIP call at runtime.  Plus the narrow-band learning, the wide-phase
  auxiliary region, pool-wide routing, and the slab transient absorption.
- The fusion dispatcher (ggml-cuda-try-fuse.cu): the matcher arms moved out of
  ggml-cuda.cu, with every arm implemented inside the kernel TU that owns it.
- The async graph-input ring: batched uploads + lazy done event (PR ggml-org#182), the
  r90 snapshot fix (the scheduler's set_tensor_async path is used for a CPU
  split's output, which the next ubatch rewrites), default-on, and the per-origin
  (per host thread) ordering state of issue ggml-org#201.
- Rope/FWHT fusions: M-ROPE and IMROPE in the RMS_NORM + MUL + ROPE (+ FWHT)
  matcher, BF16 SET_ROWS kept off the 5-op fusion, the q8_0 K/V cache writes
  folded into the rope + FWHT kernel, and the paired GDN q/k norms.
- GDN / attention-gate decode fusions: the BF16 alpha/beta pair with
  softplus(alpha + dt) * a in one mul_mat_vec_f launch (with the r108
  multi-sequence fix and its model-free regression test), the q/k norm pair in
  the direct conv kernel, the attention gate's row-strided view read in place by
  the gate -> Q8_1 kernel, the GDN output norm inside the gate kernel, and
  GGML_CUDA_GDN_TAIL (the sequential tail that writes the rollback snapshots).
- MMB and the HC16 BF16 streams: the per-context MMB state (two contexts
  interleaving must not share the activation cache or the marks), the BF16
  activation copies, DOWN16, and the graph-optimize marking passes.
- The MoE/MMQ decode fusions: mmvq-moe (the dedicated MoE multi-token kernel),
  the gate+up pair fold, silu(gate)*up into the mmq quantize, the dual-output
  matmul, the MoE down fold, and the weighted-down reduction.
- The verify-band arch extension: RDNA3_0 joins RDNA4 in the Q8_1 pre-quantize
  predicate and in the direct GDN conv.
- Meta/scheduler/allocator: the split-state refusals for a straddling split,
  the two-pass graph-optimize protocol (allocs_only / marks_only), graph-memory
  generations so a graph is recaptured when the pool / FA staging / H2D ring
  memory it captured is freed -- including the slab work-boundary shrink of
  issue ggml-org#187 -- the KV prefill pad (LLAMA_KV_N_PAD_PREFILL), and the FA accuracy
  instrument (LLAMA_TEST_OP_NMSE / LLAMA_TEST_SEED).
- bf16 RoPE destinations (TODO ggml-org#83): the missing NORMAL/NEOX bf16
  instantiations, so -ctk bf16 -ctv bf16 prefill does not abort in rope.cu.

Env-read hygiene (no behaviour change): resolve GGML_CUDA_GDN_CHUNKED /
GGML_CUDA_GDN_CHUNKED_BF16 and the GDN_DBG_SKIP_* diagnostics once into values
rather than caching the getenv() pointer: the MSVC CRT returns a buffer that the
next getenv() call overwrites, so a cached pointer is unsafe on Windows.

Build fix: the GGML_CUDA_WORK_ALLOC_DEBUG read in llama_context::graph_reserve
lives in src/ (not linked against the CUDA common.cuh), so it uses a local
static instead of the CUDA helper.

Split note (r109): this commit plus block 11 carries exactly the tree the old
block 10 carried -- the net set is unchanged.  What moved to block 11 is the
qwen4exp model graph, the QSA/indexer ops and their kernels, the
hyper-connection ops, the managed lazy reader and the keys-only indexer cache,
i.e. everything that exists only because of that architecture.  The pieces of
the old block 10 that exist for qwen4exp but are implemented inside a general
kernel TU (the GDN gate/beta fusion, the HC16 MMB BF16 streams, the qwen4exp
weighted-down reduction, the PLE conv fusion) stay here with the TU that owns
them; the HC_BLK16/RES16 marking pass and the indexer relu-sum alloc-dep moved
to block 11 with the matchers they call.

Windows HIP build (issue ggml-org#217): the tables-registration slack guard uses the int64_t min/max helpers
block 09 defines instead of `std::min<int64_t>`/`std::max<int64_t>`.  With HIP on Windows (clang + the
MSVC STL) clang's force-included `cuda_wrappers/algorithm` and the MSVC STL `<utility>` each define an
inline `std::min<long long>` (`int64_t` is `__int64` there, and the `enable_if` that makes clang's
version win overload resolution is not part of the mangled name), so a translation unit that
instantiates both fails to codegen with "definition with same mangled name".  Behaviour is unchanged.

Amended (r132): the block-10 arms of the Q8_1 cache fix that block 08 introduces.  The fused GLU -> Q8_1 site's
key walk stops at the first pointer change (the fused write is keyed by the matmul's src1, and must not take the
root's entry for an offset view), and both of this block's gated-q8_1 launch arms -- the fused norm+gate kernel
and the GLU write -- validate their sources with q8_1_src_range_ok() before launching.  From PR ggml-org#218 (@slavap);
the rule and the validation are recorded with block 08.

Co-authored-by: Slava P. <[email protected]>
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Oct 26, 2026
…rastructure)

The infrastructure half of the old block 10.  qwen4exp, QSA and the
hyper-connection ops now live in their own block (11); this block is what they
are built on, and it no longer references them.

Contents:

- The movable-boundary slab and its arena (ggml-cuda-slab.cu,
  ggml-cuda-arena.cu, ggml-cuda-vmm.h, ggml-cuda-moe-cache-hooks.cu): one VMM
  reserve per device split by a movable boundary -- compute below, MoE arena
  above, no HIP call at runtime.  Plus the narrow-band learning, the wide-phase
  auxiliary region, pool-wide routing, and the slab transient absorption.
- The fusion dispatcher (ggml-cuda-try-fuse.cu): the matcher arms moved out of
  ggml-cuda.cu, with every arm implemented inside the kernel TU that owns it.
- The async graph-input ring: batched uploads + lazy done event (PR ggml-org#182), the
  r90 snapshot fix (the scheduler's set_tensor_async path is used for a CPU
  split's output, which the next ubatch rewrites), default-on, and the per-origin
  (per host thread) ordering state of issue ggml-org#201.
- Rope/FWHT fusions: M-ROPE and IMROPE in the RMS_NORM + MUL + ROPE (+ FWHT)
  matcher, BF16 SET_ROWS kept off the 5-op fusion, the q8_0 K/V cache writes
  folded into the rope + FWHT kernel, and the paired GDN q/k norms.
- GDN / attention-gate decode fusions: the BF16 alpha/beta pair with
  softplus(alpha + dt) * a in one mul_mat_vec_f launch (with the r108
  multi-sequence fix and its model-free regression test), the q/k norm pair in
  the direct conv kernel, the attention gate's row-strided view read in place by
  the gate -> Q8_1 kernel, the GDN output norm inside the gate kernel, and
  GGML_CUDA_GDN_TAIL (the sequential tail that writes the rollback snapshots).
- MMB and the HC16 BF16 streams: the per-context MMB state (two contexts
  interleaving must not share the activation cache or the marks), the BF16
  activation copies, DOWN16, and the graph-optimize marking passes.
- The MoE/MMQ decode fusions: mmvq-moe (the dedicated MoE multi-token kernel),
  the gate+up pair fold, silu(gate)*up into the mmq quantize, the dual-output
  matmul, the MoE down fold, and the weighted-down reduction.
- The verify-band arch extension: RDNA3_0 joins RDNA4 in the Q8_1 pre-quantize
  predicate and in the direct GDN conv.
- Meta/scheduler/allocator: the split-state refusals for a straddling split,
  the two-pass graph-optimize protocol (allocs_only / marks_only), graph-memory
  generations so a graph is recaptured when the pool / FA staging / H2D ring
  memory it captured is freed -- including the slab work-boundary shrink of
  issue ggml-org#187 -- the KV prefill pad (LLAMA_KV_N_PAD_PREFILL), and the FA accuracy
  instrument (LLAMA_TEST_OP_NMSE / LLAMA_TEST_SEED).
- bf16 RoPE destinations (TODO ggml-org#83): the missing NORMAL/NEOX bf16
  instantiations, so -ctk bf16 -ctv bf16 prefill does not abort in rope.cu.

Env-read hygiene (no behaviour change): resolve GGML_CUDA_GDN_CHUNKED /
GGML_CUDA_GDN_CHUNKED_BF16 and the GDN_DBG_SKIP_* diagnostics once into values
rather than caching the getenv() pointer: the MSVC CRT returns a buffer that the
next getenv() call overwrites, so a cached pointer is unsafe on Windows.

Build fix: the GGML_CUDA_WORK_ALLOC_DEBUG read in llama_context::graph_reserve
lives in src/ (not linked against the CUDA common.cuh), so it uses a local
static instead of the CUDA helper.

Split note (r109): this commit plus block 11 carries exactly the tree the old
block 10 carried -- the net set is unchanged.  What moved to block 11 is the
qwen4exp model graph, the QSA/indexer ops and their kernels, the
hyper-connection ops, the managed lazy reader and the keys-only indexer cache,
i.e. everything that exists only because of that architecture.  The pieces of
the old block 10 that exist for qwen4exp but are implemented inside a general
kernel TU (the GDN gate/beta fusion, the HC16 MMB BF16 streams, the qwen4exp
weighted-down reduction, the PLE conv fusion) stay here with the TU that owns
them; the HC_BLK16/RES16 marking pass and the indexer relu-sum alloc-dep moved
to block 11 with the matchers they call.

Windows HIP build (issue ggml-org#217): the tables-registration slack guard uses the int64_t min/max helpers
block 09 defines instead of `std::min<int64_t>`/`std::max<int64_t>`.  With HIP on Windows (clang + the
MSVC STL) clang's force-included `cuda_wrappers/algorithm` and the MSVC STL `<utility>` each define an
inline `std::min<long long>` (`int64_t` is `__int64` there, and the `enable_if` that makes clang's
version win overload resolution is not part of the mangled name), so a translation unit that
instantiates both fails to codegen with "definition with same mangled name".  Behaviour is unchanged.

Amended (r132): the block-10 arms of the Q8_1 cache fix that block 08 introduces.  The fused GLU -> Q8_1 site's
key walk stops at the first pointer change (the fused write is keyed by the matmul's src1, and must not take the
root's entry for an offset view), and both of this block's gated-q8_1 launch arms -- the fused norm+gate kernel
and the GLU write -- validate their sources with q8_1_src_range_ok() before launching.  From PR ggml-org#218 (@slavap);
the rule and the validation are recorded with block 08.

Co-authored-by: Slava P. <[email protected]>
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Oct 26, 2026
…rastructure)

The infrastructure half of the old block 10.  qwen4exp, QSA and the
hyper-connection ops now live in their own block (11); this block is what they
are built on, and it no longer references them.

Contents:

- The movable-boundary slab and its arena (ggml-cuda-slab.cu,
  ggml-cuda-arena.cu, ggml-cuda-vmm.h, ggml-cuda-moe-cache-hooks.cu): one VMM
  reserve per device split by a movable boundary -- compute below, MoE arena
  above, no HIP call at runtime.  Plus the narrow-band learning, the wide-phase
  auxiliary region, pool-wide routing, and the slab transient absorption.
- The fusion dispatcher (ggml-cuda-try-fuse.cu): the matcher arms moved out of
  ggml-cuda.cu, with every arm implemented inside the kernel TU that owns it.
- The async graph-input ring: batched uploads + lazy done event (PR ggml-org#182), the
  r90 snapshot fix (the scheduler's set_tensor_async path is used for a CPU
  split's output, which the next ubatch rewrites), default-on, and the per-origin
  (per host thread) ordering state of issue ggml-org#201.
- Rope/FWHT fusions: M-ROPE and IMROPE in the RMS_NORM + MUL + ROPE (+ FWHT)
  matcher, BF16 SET_ROWS kept off the 5-op fusion, the q8_0 K/V cache writes
  folded into the rope + FWHT kernel, and the paired GDN q/k norms.
- GDN / attention-gate decode fusions: the BF16 alpha/beta pair with
  softplus(alpha + dt) * a in one mul_mat_vec_f launch (with the r108
  multi-sequence fix and its model-free regression test), the q/k norm pair in
  the direct conv kernel, the attention gate's row-strided view read in place by
  the gate -> Q8_1 kernel, the GDN output norm inside the gate kernel, and
  GGML_CUDA_GDN_TAIL (the sequential tail that writes the rollback snapshots).
- MMB and the HC16 BF16 streams: the per-context MMB state (two contexts
  interleaving must not share the activation cache or the marks), the BF16
  activation copies, DOWN16, and the graph-optimize marking passes.
- The MoE/MMQ decode fusions: mmvq-moe (the dedicated MoE multi-token kernel),
  the gate+up pair fold, silu(gate)*up into the mmq quantize, the dual-output
  matmul, the MoE down fold, and the weighted-down reduction.
- The verify-band arch extension: RDNA3_0 joins RDNA4 in the Q8_1 pre-quantize
  predicate and in the direct GDN conv.
- Meta/scheduler/allocator: the split-state refusals for a straddling split,
  the two-pass graph-optimize protocol (allocs_only / marks_only), graph-memory
  generations so a graph is recaptured when the pool / FA staging / H2D ring
  memory it captured is freed -- including the slab work-boundary shrink of
  issue ggml-org#187 -- the KV prefill pad (LLAMA_KV_N_PAD_PREFILL), and the FA accuracy
  instrument (LLAMA_TEST_OP_NMSE / LLAMA_TEST_SEED).
- bf16 RoPE destinations (TODO ggml-org#83): the missing NORMAL/NEOX bf16
  instantiations, so -ctk bf16 -ctv bf16 prefill does not abort in rope.cu.

Env-read hygiene (no behaviour change): resolve GGML_CUDA_GDN_CHUNKED /
GGML_CUDA_GDN_CHUNKED_BF16 and the GDN_DBG_SKIP_* diagnostics once into values
rather than caching the getenv() pointer: the MSVC CRT returns a buffer that the
next getenv() call overwrites, so a cached pointer is unsafe on Windows.

Build fix: the GGML_CUDA_WORK_ALLOC_DEBUG read in llama_context::graph_reserve
lives in src/ (not linked against the CUDA common.cuh), so it uses a local
static instead of the CUDA helper.

Split note (r109): this commit plus block 11 carries exactly the tree the old
block 10 carried -- the net set is unchanged.  What moved to block 11 is the
qwen4exp model graph, the QSA/indexer ops and their kernels, the
hyper-connection ops, the managed lazy reader and the keys-only indexer cache,
i.e. everything that exists only because of that architecture.  The pieces of
the old block 10 that exist for qwen4exp but are implemented inside a general
kernel TU (the GDN gate/beta fusion, the HC16 MMB BF16 streams, the qwen4exp
weighted-down reduction, the PLE conv fusion) stay here with the TU that owns
them; the HC_BLK16/RES16 marking pass and the indexer relu-sum alloc-dep moved
to block 11 with the matchers they call.

Windows HIP build (issue ggml-org#217): the tables-registration slack guard uses the int64_t min/max helpers
block 09 defines instead of `std::min<int64_t>`/`std::max<int64_t>`.  With HIP on Windows (clang + the
MSVC STL) clang's force-included `cuda_wrappers/algorithm` and the MSVC STL `<utility>` each define an
inline `std::min<long long>` (`int64_t` is `__int64` there, and the `enable_if` that makes clang's
version win overload resolution is not part of the mangled name), so a translation unit that
instantiates both fails to codegen with "definition with same mangled name".  Behaviour is unchanged.

Amended (r132): the block-10 arms of the Q8_1 cache fix that block 08 introduces.  The fused GLU -> Q8_1 site's
key walk stops at the first pointer change (the fused write is keyed by the matmul's src1, and must not take the
root's entry for an offset view), and both of this block's gated-q8_1 launch arms -- the fused norm+gate kernel
and the GLU write -- validate their sources with q8_1_src_range_ok() before launching.  From PR ggml-org#218 (@slavap);
the rule and the validation are recorded with block 08.

Co-authored-by: Slava P. <[email protected]>
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Oct 26, 2026
…rastructure)

The infrastructure half of the old block 10.  qwen4exp, QSA and the
hyper-connection ops now live in their own block (11); this block is what they
are built on, and it no longer references them.

Contents:

- The movable-boundary slab and its arena (ggml-cuda-slab.cu,
  ggml-cuda-arena.cu, ggml-cuda-vmm.h, ggml-cuda-moe-cache-hooks.cu): one VMM
  reserve per device split by a movable boundary -- compute below, MoE arena
  above, no HIP call at runtime.  Plus the narrow-band learning, the wide-phase
  auxiliary region, pool-wide routing, and the slab transient absorption.
- The fusion dispatcher (ggml-cuda-try-fuse.cu): the matcher arms moved out of
  ggml-cuda.cu, with every arm implemented inside the kernel TU that owns it.
- The async graph-input ring: batched uploads + lazy done event (PR ggml-org#182), the
  r90 snapshot fix (the scheduler's set_tensor_async path is used for a CPU
  split's output, which the next ubatch rewrites), default-on, and the per-origin
  (per host thread) ordering state of issue ggml-org#201.
- Rope/FWHT fusions: M-ROPE and IMROPE in the RMS_NORM + MUL + ROPE (+ FWHT)
  matcher, BF16 SET_ROWS kept off the 5-op fusion, the q8_0 K/V cache writes
  folded into the rope + FWHT kernel, and the paired GDN q/k norms.
- GDN / attention-gate decode fusions: the BF16 alpha/beta pair with
  softplus(alpha + dt) * a in one mul_mat_vec_f launch (with the r108
  multi-sequence fix and its model-free regression test), the q/k norm pair in
  the direct conv kernel, the attention gate's row-strided view read in place by
  the gate -> Q8_1 kernel, the GDN output norm inside the gate kernel, and
  GGML_CUDA_GDN_TAIL (the sequential tail that writes the rollback snapshots).
- MMB and the HC16 BF16 streams: the per-context MMB state (two contexts
  interleaving must not share the activation cache or the marks), the BF16
  activation copies, DOWN16, and the graph-optimize marking passes.
- The MoE/MMQ decode fusions: mmvq-moe (the dedicated MoE multi-token kernel),
  the gate+up pair fold, silu(gate)*up into the mmq quantize, the dual-output
  matmul, the MoE down fold, and the weighted-down reduction.
- The verify-band arch extension: RDNA3_0 joins RDNA4 in the Q8_1 pre-quantize
  predicate and in the direct GDN conv.
- Meta/scheduler/allocator: the split-state refusals for a straddling split,
  the two-pass graph-optimize protocol (allocs_only / marks_only), graph-memory
  generations so a graph is recaptured when the pool / FA staging / H2D ring
  memory it captured is freed -- including the slab work-boundary shrink of
  issue ggml-org#187 -- the KV prefill pad (LLAMA_KV_N_PAD_PREFILL), and the FA accuracy
  instrument (LLAMA_TEST_OP_NMSE / LLAMA_TEST_SEED).
- bf16 RoPE destinations (TODO ggml-org#83): the missing NORMAL/NEOX bf16
  instantiations, so -ctk bf16 -ctv bf16 prefill does not abort in rope.cu.

Env-read hygiene (no behaviour change): resolve GGML_CUDA_GDN_CHUNKED /
GGML_CUDA_GDN_CHUNKED_BF16 and the GDN_DBG_SKIP_* diagnostics once into values
rather than caching the getenv() pointer: the MSVC CRT returns a buffer that the
next getenv() call overwrites, so a cached pointer is unsafe on Windows.

Build fix: the GGML_CUDA_WORK_ALLOC_DEBUG read in llama_context::graph_reserve
lives in src/ (not linked against the CUDA common.cuh), so it uses a local
static instead of the CUDA helper.

Split note (r109): this commit plus block 11 carries exactly the tree the old
block 10 carried -- the net set is unchanged.  What moved to block 11 is the
qwen4exp model graph, the QSA/indexer ops and their kernels, the
hyper-connection ops, the managed lazy reader and the keys-only indexer cache,
i.e. everything that exists only because of that architecture.  The pieces of
the old block 10 that exist for qwen4exp but are implemented inside a general
kernel TU (the GDN gate/beta fusion, the HC16 MMB BF16 streams, the qwen4exp
weighted-down reduction, the PLE conv fusion) stay here with the TU that owns
them; the HC_BLK16/RES16 marking pass and the indexer relu-sum alloc-dep moved
to block 11 with the matchers they call.

Windows HIP build (issue ggml-org#217): the tables-registration slack guard uses the int64_t min/max helpers
block 09 defines instead of `std::min<int64_t>`/`std::max<int64_t>`.  With HIP on Windows (clang + the
MSVC STL) clang's force-included `cuda_wrappers/algorithm` and the MSVC STL `<utility>` each define an
inline `std::min<long long>` (`int64_t` is `__int64` there, and the `enable_if` that makes clang's
version win overload resolution is not part of the mangled name), so a translation unit that
instantiates both fails to codegen with "definition with same mangled name".  Behaviour is unchanged.

Amended (r132): the block-10 arms of the Q8_1 cache fix that block 08 introduces.  The fused GLU -> Q8_1 site's
key walk stops at the first pointer change (the fused write is keyed by the matmul's src1, and must not take the
root's entry for an offset view), and both of this block's gated-q8_1 launch arms -- the fused norm+gate kernel
and the GLU write -- validate their sources with q8_1_src_range_ok() before launching.  From PR ggml-org#218 (@slavap);
the rule and the validation are recorded with block 08.

Co-authored-by: Slava P. <[email protected]>
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Oct 27, 2026
…rastructure)

The infrastructure half of the old block 10.  qwen4exp, QSA and the
hyper-connection ops now live in their own block (11); this block is what they
are built on, and it no longer references them.

Contents:

- The movable-boundary slab and its arena (ggml-cuda-slab.cu,
  ggml-cuda-arena.cu, ggml-cuda-vmm.h, ggml-cuda-moe-cache-hooks.cu): one VMM
  reserve per device split by a movable boundary -- compute below, MoE arena
  above, no HIP call at runtime.  Plus the narrow-band learning, the wide-phase
  auxiliary region, pool-wide routing, and the slab transient absorption.
- The fusion dispatcher (ggml-cuda-try-fuse.cu): the matcher arms moved out of
  ggml-cuda.cu, with every arm implemented inside the kernel TU that owns it.
- The async graph-input ring: batched uploads + lazy done event (PR ggml-org#182), the
  r90 snapshot fix (the scheduler's set_tensor_async path is used for a CPU
  split's output, which the next ubatch rewrites), default-on, and the per-origin
  (per host thread) ordering state of issue ggml-org#201.
- Rope/FWHT fusions: M-ROPE and IMROPE in the RMS_NORM + MUL + ROPE (+ FWHT)
  matcher, BF16 SET_ROWS kept off the 5-op fusion, the q8_0 K/V cache writes
  folded into the rope + FWHT kernel, and the paired GDN q/k norms.
- GDN / attention-gate decode fusions: the BF16 alpha/beta pair with
  softplus(alpha + dt) * a in one mul_mat_vec_f launch (with the r108
  multi-sequence fix and its model-free regression test), the q/k norm pair in
  the direct conv kernel, the attention gate's row-strided view read in place by
  the gate -> Q8_1 kernel, the GDN output norm inside the gate kernel, and
  GGML_CUDA_GDN_TAIL (the sequential tail that writes the rollback snapshots).
- MMB and the HC16 BF16 streams: the per-context MMB state (two contexts
  interleaving must not share the activation cache or the marks), the BF16
  activation copies, DOWN16, and the graph-optimize marking passes.
- The MoE/MMQ decode fusions: mmvq-moe (the dedicated MoE multi-token kernel),
  the gate+up pair fold, silu(gate)*up into the mmq quantize, the dual-output
  matmul, the MoE down fold, and the weighted-down reduction.
- The verify-band arch extension: RDNA3_0 joins RDNA4 in the Q8_1 pre-quantize
  predicate and in the direct GDN conv.
- Meta/scheduler/allocator: the split-state refusals for a straddling split,
  the two-pass graph-optimize protocol (allocs_only / marks_only), graph-memory
  generations so a graph is recaptured when the pool / FA staging / H2D ring
  memory it captured is freed -- including the slab work-boundary shrink of
  issue ggml-org#187 -- the KV prefill pad (LLAMA_KV_N_PAD_PREFILL), and the FA accuracy
  instrument (LLAMA_TEST_OP_NMSE / LLAMA_TEST_SEED).
- bf16 RoPE destinations (TODO ggml-org#83): the missing NORMAL/NEOX bf16
  instantiations, so -ctk bf16 -ctv bf16 prefill does not abort in rope.cu.

Env-read hygiene (no behaviour change): resolve GGML_CUDA_GDN_CHUNKED /
GGML_CUDA_GDN_CHUNKED_BF16 and the GDN_DBG_SKIP_* diagnostics once into values
rather than caching the getenv() pointer: the MSVC CRT returns a buffer that the
next getenv() call overwrites, so a cached pointer is unsafe on Windows.

Build fix: the GGML_CUDA_WORK_ALLOC_DEBUG read in llama_context::graph_reserve
lives in src/ (not linked against the CUDA common.cuh), so it uses a local
static instead of the CUDA helper.

Split note (r109): this commit plus block 11 carries exactly the tree the old
block 10 carried -- the net set is unchanged.  What moved to block 11 is the
qwen4exp model graph, the QSA/indexer ops and their kernels, the
hyper-connection ops, the managed lazy reader and the keys-only indexer cache,
i.e. everything that exists only because of that architecture.  The pieces of
the old block 10 that exist for qwen4exp but are implemented inside a general
kernel TU (the GDN gate/beta fusion, the HC16 MMB BF16 streams, the qwen4exp
weighted-down reduction, the PLE conv fusion) stay here with the TU that owns
them; the HC_BLK16/RES16 marking pass and the indexer relu-sum alloc-dep moved
to block 11 with the matchers they call.

Windows HIP build (issue ggml-org#217): the tables-registration slack guard uses the int64_t min/max helpers
block 09 defines instead of `std::min<int64_t>`/`std::max<int64_t>`.  With HIP on Windows (clang + the
MSVC STL) clang's force-included `cuda_wrappers/algorithm` and the MSVC STL `<utility>` each define an
inline `std::min<long long>` (`int64_t` is `__int64` there, and the `enable_if` that makes clang's
version win overload resolution is not part of the mangled name), so a translation unit that
instantiates both fails to codegen with "definition with same mangled name".  Behaviour is unchanged.

Amended (r132): the block-10 arms of the Q8_1 cache fix that block 08 introduces.  The fused GLU -> Q8_1 site's
key walk stops at the first pointer change (the fused write is keyed by the matmul's src1, and must not take the
root's entry for an offset view), and both of this block's gated-q8_1 launch arms -- the fused norm+gate kernel
and the GLU write -- validate their sources with q8_1_src_range_ok() before launching.  From PR ggml-org#218 (@slavap);
the rule and the validation are recorded with block 08.

Co-authored-by: Slava P. <[email protected]>
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Oct 27, 2026
…rastructure)

The infrastructure half of the old block 10.  qwen4exp, QSA and the
hyper-connection ops now live in their own block (11); this block is what they
are built on, and it no longer references them.

Contents:

- The movable-boundary slab and its arena (ggml-cuda-slab.cu,
  ggml-cuda-arena.cu, ggml-cuda-vmm.h, ggml-cuda-moe-cache-hooks.cu): one VMM
  reserve per device split by a movable boundary -- compute below, MoE arena
  above, no HIP call at runtime.  Plus the narrow-band learning, the wide-phase
  auxiliary region, pool-wide routing, and the slab transient absorption.
- The fusion dispatcher (ggml-cuda-try-fuse.cu): the matcher arms moved out of
  ggml-cuda.cu, with every arm implemented inside the kernel TU that owns it.
- The async graph-input ring: batched uploads + lazy done event (PR ggml-org#182), the
  r90 snapshot fix (the scheduler's set_tensor_async path is used for a CPU
  split's output, which the next ubatch rewrites), default-on, and the per-origin
  (per host thread) ordering state of issue ggml-org#201.
- Rope/FWHT fusions: M-ROPE and IMROPE in the RMS_NORM + MUL + ROPE (+ FWHT)
  matcher, BF16 SET_ROWS kept off the 5-op fusion, the q8_0 K/V cache writes
  folded into the rope + FWHT kernel, and the paired GDN q/k norms.
- GDN / attention-gate decode fusions: the BF16 alpha/beta pair with
  softplus(alpha + dt) * a in one mul_mat_vec_f launch (with the r108
  multi-sequence fix and its model-free regression test), the q/k norm pair in
  the direct conv kernel, the attention gate's row-strided view read in place by
  the gate -> Q8_1 kernel, the GDN output norm inside the gate kernel, and
  GGML_CUDA_GDN_TAIL (the sequential tail that writes the rollback snapshots).
- MMB and the HC16 BF16 streams: the per-context MMB state (two contexts
  interleaving must not share the activation cache or the marks), the BF16
  activation copies, DOWN16, and the graph-optimize marking passes.
- The MoE/MMQ decode fusions: mmvq-moe (the dedicated MoE multi-token kernel),
  the gate+up pair fold, silu(gate)*up into the mmq quantize, the dual-output
  matmul, the MoE down fold, and the weighted-down reduction.
- The verify-band arch extension: RDNA3_0 joins RDNA4 in the Q8_1 pre-quantize
  predicate and in the direct GDN conv.
- Meta/scheduler/allocator: the split-state refusals for a straddling split,
  the two-pass graph-optimize protocol (allocs_only / marks_only), graph-memory
  generations so a graph is recaptured when the pool / FA staging / H2D ring
  memory it captured is freed -- including the slab work-boundary shrink of
  issue ggml-org#187 -- the KV prefill pad (LLAMA_KV_N_PAD_PREFILL), and the FA accuracy
  instrument (LLAMA_TEST_OP_NMSE / LLAMA_TEST_SEED).
- bf16 RoPE destinations (TODO ggml-org#83): the missing NORMAL/NEOX bf16
  instantiations, so -ctk bf16 -ctv bf16 prefill does not abort in rope.cu.

Env-read hygiene (no behaviour change): resolve GGML_CUDA_GDN_CHUNKED /
GGML_CUDA_GDN_CHUNKED_BF16 and the GDN_DBG_SKIP_* diagnostics once into values
rather than caching the getenv() pointer: the MSVC CRT returns a buffer that the
next getenv() call overwrites, so a cached pointer is unsafe on Windows.

Build fix: the GGML_CUDA_WORK_ALLOC_DEBUG read in llama_context::graph_reserve
lives in src/ (not linked against the CUDA common.cuh), so it uses a local
static instead of the CUDA helper.

Split note (r109): this commit plus block 11 carries exactly the tree the old
block 10 carried -- the net set is unchanged.  What moved to block 11 is the
qwen4exp model graph, the QSA/indexer ops and their kernels, the
hyper-connection ops, the managed lazy reader and the keys-only indexer cache,
i.e. everything that exists only because of that architecture.  The pieces of
the old block 10 that exist for qwen4exp but are implemented inside a general
kernel TU (the GDN gate/beta fusion, the HC16 MMB BF16 streams, the qwen4exp
weighted-down reduction, the PLE conv fusion) stay here with the TU that owns
them; the HC_BLK16/RES16 marking pass and the indexer relu-sum alloc-dep moved
to block 11 with the matchers they call.

Windows HIP build (issue ggml-org#217): the tables-registration slack guard uses the int64_t min/max helpers
block 09 defines instead of `std::min<int64_t>`/`std::max<int64_t>`.  With HIP on Windows (clang + the
MSVC STL) clang's force-included `cuda_wrappers/algorithm` and the MSVC STL `<utility>` each define an
inline `std::min<long long>` (`int64_t` is `__int64` there, and the `enable_if` that makes clang's
version win overload resolution is not part of the mangled name), so a translation unit that
instantiates both fails to codegen with "definition with same mangled name".  Behaviour is unchanged.

Amended (r132): the block-10 arms of the Q8_1 cache fix that block 08 introduces.  The fused GLU -> Q8_1 site's
key walk stops at the first pointer change (the fused write is keyed by the matmul's src1, and must not take the
root's entry for an offset view), and both of this block's gated-q8_1 launch arms -- the fused norm+gate kernel
and the GLU write -- validate their sources with q8_1_src_range_ok() before launching.  From PR ggml-org#218 (@slavap);
the rule and the validation are recorded with block 08.

Co-authored-by: Slava P. <[email protected]>
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Oct 27, 2026
…rastructure)

The infrastructure half of the old block 10.  qwen4exp, QSA and the
hyper-connection ops now live in their own block (11); this block is what they
are built on, and it no longer references them.

Contents:

- The movable-boundary slab and its arena (ggml-cuda-slab.cu,
  ggml-cuda-arena.cu, ggml-cuda-vmm.h, ggml-cuda-moe-cache-hooks.cu): one VMM
  reserve per device split by a movable boundary -- compute below, MoE arena
  above, no HIP call at runtime.  Plus the narrow-band learning, the wide-phase
  auxiliary region, pool-wide routing, and the slab transient absorption.
- The fusion dispatcher (ggml-cuda-try-fuse.cu): the matcher arms moved out of
  ggml-cuda.cu, with every arm implemented inside the kernel TU that owns it.
- The async graph-input ring: batched uploads + lazy done event (PR ggml-org#182), the
  r90 snapshot fix (the scheduler's set_tensor_async path is used for a CPU
  split's output, which the next ubatch rewrites), default-on, and the per-origin
  (per host thread) ordering state of issue ggml-org#201.
- Rope/FWHT fusions: M-ROPE and IMROPE in the RMS_NORM + MUL + ROPE (+ FWHT)
  matcher, BF16 SET_ROWS kept off the 5-op fusion, the q8_0 K/V cache writes
  folded into the rope + FWHT kernel, and the paired GDN q/k norms.
- GDN / attention-gate decode fusions: the BF16 alpha/beta pair with
  softplus(alpha + dt) * a in one mul_mat_vec_f launch (with the r108
  multi-sequence fix and its model-free regression test), the q/k norm pair in
  the direct conv kernel, the attention gate's row-strided view read in place by
  the gate -> Q8_1 kernel, the GDN output norm inside the gate kernel, and
  GGML_CUDA_GDN_TAIL (the sequential tail that writes the rollback snapshots).
- MMB and the HC16 BF16 streams: the per-context MMB state (two contexts
  interleaving must not share the activation cache or the marks), the BF16
  activation copies, DOWN16, and the graph-optimize marking passes.
- The MoE/MMQ decode fusions: mmvq-moe (the dedicated MoE multi-token kernel),
  the gate+up pair fold, silu(gate)*up into the mmq quantize, the dual-output
  matmul, the MoE down fold, and the weighted-down reduction.
- The verify-band arch extension: RDNA3_0 joins RDNA4 in the Q8_1 pre-quantize
  predicate and in the direct GDN conv.
- Meta/scheduler/allocator: the split-state refusals for a straddling split,
  the two-pass graph-optimize protocol (allocs_only / marks_only), graph-memory
  generations so a graph is recaptured when the pool / FA staging / H2D ring
  memory it captured is freed -- including the slab work-boundary shrink of
  issue ggml-org#187 -- the KV prefill pad (LLAMA_KV_N_PAD_PREFILL), and the FA accuracy
  instrument (LLAMA_TEST_OP_NMSE / LLAMA_TEST_SEED).
- bf16 RoPE destinations (TODO ggml-org#83): the missing NORMAL/NEOX bf16
  instantiations, so -ctk bf16 -ctv bf16 prefill does not abort in rope.cu.

Env-read hygiene (no behaviour change): resolve GGML_CUDA_GDN_CHUNKED /
GGML_CUDA_GDN_CHUNKED_BF16 and the GDN_DBG_SKIP_* diagnostics once into values
rather than caching the getenv() pointer: the MSVC CRT returns a buffer that the
next getenv() call overwrites, so a cached pointer is unsafe on Windows.

Build fix: the GGML_CUDA_WORK_ALLOC_DEBUG read in llama_context::graph_reserve
lives in src/ (not linked against the CUDA common.cuh), so it uses a local
static instead of the CUDA helper.

Split note (r109): this commit plus block 11 carries exactly the tree the old
block 10 carried -- the net set is unchanged.  What moved to block 11 is the
qwen4exp model graph, the QSA/indexer ops and their kernels, the
hyper-connection ops, the managed lazy reader and the keys-only indexer cache,
i.e. everything that exists only because of that architecture.  The pieces of
the old block 10 that exist for qwen4exp but are implemented inside a general
kernel TU (the GDN gate/beta fusion, the HC16 MMB BF16 streams, the qwen4exp
weighted-down reduction, the PLE conv fusion) stay here with the TU that owns
them; the HC_BLK16/RES16 marking pass and the indexer relu-sum alloc-dep moved
to block 11 with the matchers they call.

Windows HIP build (issue ggml-org#217): the tables-registration slack guard uses the int64_t min/max helpers
block 09 defines instead of `std::min<int64_t>`/`std::max<int64_t>`.  With HIP on Windows (clang + the
MSVC STL) clang's force-included `cuda_wrappers/algorithm` and the MSVC STL `<utility>` each define an
inline `std::min<long long>` (`int64_t` is `__int64` there, and the `enable_if` that makes clang's
version win overload resolution is not part of the mangled name), so a translation unit that
instantiates both fails to codegen with "definition with same mangled name".  Behaviour is unchanged.

Amended (r132): the block-10 arms of the Q8_1 cache fix that block 08 introduces.  The fused GLU -> Q8_1 site's
key walk stops at the first pointer change (the fused write is keyed by the matmul's src1, and must not take the
root's entry for an offset view), and both of this block's gated-q8_1 launch arms -- the fused norm+gate kernel
and the GLU write -- validate their sources with q8_1_src_range_ok() before launching.  From PR ggml-org#218 (@slavap);
the rule and the validation are recorded with block 08.

Co-authored-by: Slava P. <[email protected]>
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Oct 27, 2026
…rastructure)

The infrastructure half of the old block 10.  qwen4exp, QSA and the
hyper-connection ops now live in their own block (11); this block is what they
are built on, and it no longer references them.

Contents:

- The movable-boundary slab and its arena (ggml-cuda-slab.cu,
  ggml-cuda-arena.cu, ggml-cuda-vmm.h, ggml-cuda-moe-cache-hooks.cu): one VMM
  reserve per device split by a movable boundary -- compute below, MoE arena
  above, no HIP call at runtime.  Plus the narrow-band learning, the wide-phase
  auxiliary region, pool-wide routing, and the slab transient absorption.
- The fusion dispatcher (ggml-cuda-try-fuse.cu): the matcher arms moved out of
  ggml-cuda.cu, with every arm implemented inside the kernel TU that owns it.
- The async graph-input ring: batched uploads + lazy done event (PR ggml-org#182), the
  r90 snapshot fix (the scheduler's set_tensor_async path is used for a CPU
  split's output, which the next ubatch rewrites), default-on, and the per-origin
  (per host thread) ordering state of issue ggml-org#201.
- Rope/FWHT fusions: M-ROPE and IMROPE in the RMS_NORM + MUL + ROPE (+ FWHT)
  matcher, BF16 SET_ROWS kept off the 5-op fusion, the q8_0 K/V cache writes
  folded into the rope + FWHT kernel, and the paired GDN q/k norms.
- GDN / attention-gate decode fusions: the BF16 alpha/beta pair with
  softplus(alpha + dt) * a in one mul_mat_vec_f launch (with the r108
  multi-sequence fix and its model-free regression test), the q/k norm pair in
  the direct conv kernel, the attention gate's row-strided view read in place by
  the gate -> Q8_1 kernel, the GDN output norm inside the gate kernel, and
  GGML_CUDA_GDN_TAIL (the sequential tail that writes the rollback snapshots).
- MMB and the HC16 BF16 streams: the per-context MMB state (two contexts
  interleaving must not share the activation cache or the marks), the BF16
  activation copies, DOWN16, and the graph-optimize marking passes.
- The MoE/MMQ decode fusions: mmvq-moe (the dedicated MoE multi-token kernel),
  the gate+up pair fold, silu(gate)*up into the mmq quantize, the dual-output
  matmul, the MoE down fold, and the weighted-down reduction.
- The verify-band arch extension: RDNA3_0 joins RDNA4 in the Q8_1 pre-quantize
  predicate and in the direct GDN conv.
- Meta/scheduler/allocator: the split-state refusals for a straddling split,
  the two-pass graph-optimize protocol (allocs_only / marks_only), graph-memory
  generations so a graph is recaptured when the pool / FA staging / H2D ring
  memory it captured is freed -- including the slab work-boundary shrink of
  issue ggml-org#187 -- the KV prefill pad (LLAMA_KV_N_PAD_PREFILL), and the FA accuracy
  instrument (LLAMA_TEST_OP_NMSE / LLAMA_TEST_SEED).
- bf16 RoPE destinations (TODO ggml-org#83): the missing NORMAL/NEOX bf16
  instantiations, so -ctk bf16 -ctv bf16 prefill does not abort in rope.cu.

Env-read hygiene (no behaviour change): resolve GGML_CUDA_GDN_CHUNKED /
GGML_CUDA_GDN_CHUNKED_BF16 and the GDN_DBG_SKIP_* diagnostics once into values
rather than caching the getenv() pointer: the MSVC CRT returns a buffer that the
next getenv() call overwrites, so a cached pointer is unsafe on Windows.

Build fix: the GGML_CUDA_WORK_ALLOC_DEBUG read in llama_context::graph_reserve
lives in src/ (not linked against the CUDA common.cuh), so it uses a local
static instead of the CUDA helper.

Split note (r109): this commit plus block 11 carries exactly the tree the old
block 10 carried -- the net set is unchanged.  What moved to block 11 is the
qwen4exp model graph, the QSA/indexer ops and their kernels, the
hyper-connection ops, the managed lazy reader and the keys-only indexer cache,
i.e. everything that exists only because of that architecture.  The pieces of
the old block 10 that exist for qwen4exp but are implemented inside a general
kernel TU (the GDN gate/beta fusion, the HC16 MMB BF16 streams, the qwen4exp
weighted-down reduction, the PLE conv fusion) stay here with the TU that owns
them; the HC_BLK16/RES16 marking pass and the indexer relu-sum alloc-dep moved
to block 11 with the matchers they call.

Windows HIP build (issue ggml-org#217): the tables-registration slack guard uses the int64_t min/max helpers
block 09 defines instead of `std::min<int64_t>`/`std::max<int64_t>`.  With HIP on Windows (clang + the
MSVC STL) clang's force-included `cuda_wrappers/algorithm` and the MSVC STL `<utility>` each define an
inline `std::min<long long>` (`int64_t` is `__int64` there, and the `enable_if` that makes clang's
version win overload resolution is not part of the mangled name), so a translation unit that
instantiates both fails to codegen with "definition with same mangled name".  Behaviour is unchanged.

Amended (r132): the block-10 arms of the Q8_1 cache fix that block 08 introduces.  The fused GLU -> Q8_1 site's
key walk stops at the first pointer change (the fused write is keyed by the matmul's src1, and must not take the
root's entry for an offset view), and both of this block's gated-q8_1 launch arms -- the fused norm+gate kernel
and the GLU write -- validate their sources with q8_1_src_range_ok() before launching.  From PR ggml-org#218 (@slavap);
the rule and the validation are recorded with block 08.

Co-authored-by: Slava P. <[email protected]>
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Oct 27, 2026
…rastructure)

The infrastructure half of the old block 10.  qwen4exp, QSA and the
hyper-connection ops now live in their own block (11); this block is what they
are built on, and it no longer references them.

Contents:

- The movable-boundary slab and its arena (ggml-cuda-slab.cu,
  ggml-cuda-arena.cu, ggml-cuda-vmm.h, ggml-cuda-moe-cache-hooks.cu): one VMM
  reserve per device split by a movable boundary -- compute below, MoE arena
  above, no HIP call at runtime.  Plus the narrow-band learning, the wide-phase
  auxiliary region, pool-wide routing, and the slab transient absorption.
- The fusion dispatcher (ggml-cuda-try-fuse.cu): the matcher arms moved out of
  ggml-cuda.cu, with every arm implemented inside the kernel TU that owns it.
- The async graph-input ring: batched uploads + lazy done event (PR ggml-org#182), the
  r90 snapshot fix (the scheduler's set_tensor_async path is used for a CPU
  split's output, which the next ubatch rewrites), default-on, and the per-origin
  (per host thread) ordering state of issue ggml-org#201.
- Rope/FWHT fusions: M-ROPE and IMROPE in the RMS_NORM + MUL + ROPE (+ FWHT)
  matcher, BF16 SET_ROWS kept off the 5-op fusion, the q8_0 K/V cache writes
  folded into the rope + FWHT kernel, and the paired GDN q/k norms.
- GDN / attention-gate decode fusions: the BF16 alpha/beta pair with
  softplus(alpha + dt) * a in one mul_mat_vec_f launch (with the r108
  multi-sequence fix and its model-free regression test), the q/k norm pair in
  the direct conv kernel, the attention gate's row-strided view read in place by
  the gate -> Q8_1 kernel, the GDN output norm inside the gate kernel, and
  GGML_CUDA_GDN_TAIL (the sequential tail that writes the rollback snapshots).
- MMB and the HC16 BF16 streams: the per-context MMB state (two contexts
  interleaving must not share the activation cache or the marks), the BF16
  activation copies, DOWN16, and the graph-optimize marking passes.
- The MoE/MMQ decode fusions: mmvq-moe (the dedicated MoE multi-token kernel),
  the gate+up pair fold, silu(gate)*up into the mmq quantize, the dual-output
  matmul, the MoE down fold, and the weighted-down reduction.
- The verify-band arch extension: RDNA3_0 joins RDNA4 in the Q8_1 pre-quantize
  predicate and in the direct GDN conv.
- Meta/scheduler/allocator: the split-state refusals for a straddling split,
  the two-pass graph-optimize protocol (allocs_only / marks_only), graph-memory
  generations so a graph is recaptured when the pool / FA staging / H2D ring
  memory it captured is freed -- including the slab work-boundary shrink of
  issue ggml-org#187 -- the KV prefill pad (LLAMA_KV_N_PAD_PREFILL), and the FA accuracy
  instrument (LLAMA_TEST_OP_NMSE / LLAMA_TEST_SEED).
- bf16 RoPE destinations (TODO ggml-org#83): the missing NORMAL/NEOX bf16
  instantiations, so -ctk bf16 -ctv bf16 prefill does not abort in rope.cu.

Env-read hygiene (no behaviour change): resolve GGML_CUDA_GDN_CHUNKED /
GGML_CUDA_GDN_CHUNKED_BF16 and the GDN_DBG_SKIP_* diagnostics once into values
rather than caching the getenv() pointer: the MSVC CRT returns a buffer that the
next getenv() call overwrites, so a cached pointer is unsafe on Windows.

Build fix: the GGML_CUDA_WORK_ALLOC_DEBUG read in llama_context::graph_reserve
lives in src/ (not linked against the CUDA common.cuh), so it uses a local
static instead of the CUDA helper.

Split note (r109): this commit plus block 11 carries exactly the tree the old
block 10 carried -- the net set is unchanged.  What moved to block 11 is the
qwen4exp model graph, the QSA/indexer ops and their kernels, the
hyper-connection ops, the managed lazy reader and the keys-only indexer cache,
i.e. everything that exists only because of that architecture.  The pieces of
the old block 10 that exist for qwen4exp but are implemented inside a general
kernel TU (the GDN gate/beta fusion, the HC16 MMB BF16 streams, the qwen4exp
weighted-down reduction, the PLE conv fusion) stay here with the TU that owns
them; the HC_BLK16/RES16 marking pass and the indexer relu-sum alloc-dep moved
to block 11 with the matchers they call.

Windows HIP build (issue ggml-org#217): the tables-registration slack guard uses the int64_t min/max helpers
block 09 defines instead of `std::min<int64_t>`/`std::max<int64_t>`.  With HIP on Windows (clang + the
MSVC STL) clang's force-included `cuda_wrappers/algorithm` and the MSVC STL `<utility>` each define an
inline `std::min<long long>` (`int64_t` is `__int64` there, and the `enable_if` that makes clang's
version win overload resolution is not part of the mangled name), so a translation unit that
instantiates both fails to codegen with "definition with same mangled name".  Behaviour is unchanged.

Amended (r132): the block-10 arms of the Q8_1 cache fix that block 08 introduces.  The fused GLU -> Q8_1 site's
key walk stops at the first pointer change (the fused write is keyed by the matmul's src1, and must not take the
root's entry for an offset view), and both of this block's gated-q8_1 launch arms -- the fused norm+gate kernel
and the GLU write -- validate their sources with q8_1_src_range_ok() before launching.  From PR ggml-org#218 (@slavap);
the rule and the validation are recorded with block 08.

Co-authored-by: Slava P. <[email protected]>
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Oct 27, 2026
…rastructure)

The infrastructure half of the old block 10.  qwen4exp, QSA and the
hyper-connection ops now live in their own block (11); this block is what they
are built on, and it no longer references them.

Contents:

- The movable-boundary slab and its arena (ggml-cuda-slab.cu,
  ggml-cuda-arena.cu, ggml-cuda-vmm.h, ggml-cuda-moe-cache-hooks.cu): one VMM
  reserve per device split by a movable boundary -- compute below, MoE arena
  above, no HIP call at runtime.  Plus the narrow-band learning, the wide-phase
  auxiliary region, pool-wide routing, and the slab transient absorption.
- The fusion dispatcher (ggml-cuda-try-fuse.cu): the matcher arms moved out of
  ggml-cuda.cu, with every arm implemented inside the kernel TU that owns it.
- The async graph-input ring: batched uploads + lazy done event (PR ggml-org#182), the
  r90 snapshot fix (the scheduler's set_tensor_async path is used for a CPU
  split's output, which the next ubatch rewrites), default-on, and the per-origin
  (per host thread) ordering state of issue ggml-org#201.
- Rope/FWHT fusions: M-ROPE and IMROPE in the RMS_NORM + MUL + ROPE (+ FWHT)
  matcher, BF16 SET_ROWS kept off the 5-op fusion, the q8_0 K/V cache writes
  folded into the rope + FWHT kernel, and the paired GDN q/k norms.
- GDN / attention-gate decode fusions: the BF16 alpha/beta pair with
  softplus(alpha + dt) * a in one mul_mat_vec_f launch (with the r108
  multi-sequence fix and its model-free regression test), the q/k norm pair in
  the direct conv kernel, the attention gate's row-strided view read in place by
  the gate -> Q8_1 kernel, the GDN output norm inside the gate kernel, and
  GGML_CUDA_GDN_TAIL (the sequential tail that writes the rollback snapshots).
- MMB and the HC16 BF16 streams: the per-context MMB state (two contexts
  interleaving must not share the activation cache or the marks), the BF16
  activation copies, DOWN16, and the graph-optimize marking passes.
- The MoE/MMQ decode fusions: mmvq-moe (the dedicated MoE multi-token kernel),
  the gate+up pair fold, silu(gate)*up into the mmq quantize, the dual-output
  matmul, the MoE down fold, and the weighted-down reduction.
- The verify-band arch extension: RDNA3_0 joins RDNA4 in the Q8_1 pre-quantize
  predicate and in the direct GDN conv.
- Meta/scheduler/allocator: the split-state refusals for a straddling split,
  the two-pass graph-optimize protocol (allocs_only / marks_only), graph-memory
  generations so a graph is recaptured when the pool / FA staging / H2D ring
  memory it captured is freed -- including the slab work-boundary shrink of
  issue ggml-org#187 -- the KV prefill pad (LLAMA_KV_N_PAD_PREFILL), and the FA accuracy
  instrument (LLAMA_TEST_OP_NMSE / LLAMA_TEST_SEED).
- bf16 RoPE destinations (TODO ggml-org#83): the missing NORMAL/NEOX bf16
  instantiations, so -ctk bf16 -ctv bf16 prefill does not abort in rope.cu.

Env-read hygiene (no behaviour change): resolve GGML_CUDA_GDN_CHUNKED /
GGML_CUDA_GDN_CHUNKED_BF16 and the GDN_DBG_SKIP_* diagnostics once into values
rather than caching the getenv() pointer: the MSVC CRT returns a buffer that the
next getenv() call overwrites, so a cached pointer is unsafe on Windows.

Build fix: the GGML_CUDA_WORK_ALLOC_DEBUG read in llama_context::graph_reserve
lives in src/ (not linked against the CUDA common.cuh), so it uses a local
static instead of the CUDA helper.

Split note (r109): this commit plus block 11 carries exactly the tree the old
block 10 carried -- the net set is unchanged.  What moved to block 11 is the
qwen4exp model graph, the QSA/indexer ops and their kernels, the
hyper-connection ops, the managed lazy reader and the keys-only indexer cache,
i.e. everything that exists only because of that architecture.  The pieces of
the old block 10 that exist for qwen4exp but are implemented inside a general
kernel TU (the GDN gate/beta fusion, the HC16 MMB BF16 streams, the qwen4exp
weighted-down reduction, the PLE conv fusion) stay here with the TU that owns
them; the HC_BLK16/RES16 marking pass and the indexer relu-sum alloc-dep moved
to block 11 with the matchers they call.

Windows HIP build (issue ggml-org#217): the tables-registration slack guard uses the int64_t min/max helpers
block 09 defines instead of `std::min<int64_t>`/`std::max<int64_t>`.  With HIP on Windows (clang + the
MSVC STL) clang's force-included `cuda_wrappers/algorithm` and the MSVC STL `<utility>` each define an
inline `std::min<long long>` (`int64_t` is `__int64` there, and the `enable_if` that makes clang's
version win overload resolution is not part of the mangled name), so a translation unit that
instantiates both fails to codegen with "definition with same mangled name".  Behaviour is unchanged.

Amended (r132): the block-10 arms of the Q8_1 cache fix that block 08 introduces.  The fused GLU -> Q8_1 site's
key walk stops at the first pointer change (the fused write is keyed by the matmul's src1, and must not take the
root's entry for an offset view), and both of this block's gated-q8_1 launch arms -- the fused norm+gate kernel
and the GLU write -- validate their sources with q8_1_src_range_ok() before launching.  From PR ggml-org#218 (@slavap);
the rule and the validation are recorded with block 08.

Co-authored-by: Slava P. <[email protected]>
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Oct 27, 2026
…rastructure)

The infrastructure half of the old block 10.  qwen4exp, QSA and the
hyper-connection ops now live in their own block (11); this block is what they
are built on, and it no longer references them.

Contents:

- The movable-boundary slab and its arena (ggml-cuda-slab.cu,
  ggml-cuda-arena.cu, ggml-cuda-vmm.h, ggml-cuda-moe-cache-hooks.cu): one VMM
  reserve per device split by a movable boundary -- compute below, MoE arena
  above, no HIP call at runtime.  Plus the narrow-band learning, the wide-phase
  auxiliary region, pool-wide routing, and the slab transient absorption.
- The fusion dispatcher (ggml-cuda-try-fuse.cu): the matcher arms moved out of
  ggml-cuda.cu, with every arm implemented inside the kernel TU that owns it.
- The async graph-input ring: batched uploads + lazy done event (PR ggml-org#182), the
  r90 snapshot fix (the scheduler's set_tensor_async path is used for a CPU
  split's output, which the next ubatch rewrites), default-on, and the per-origin
  (per host thread) ordering state of issue ggml-org#201.
- Rope/FWHT fusions: M-ROPE and IMROPE in the RMS_NORM + MUL + ROPE (+ FWHT)
  matcher, BF16 SET_ROWS kept off the 5-op fusion, the q8_0 K/V cache writes
  folded into the rope + FWHT kernel, and the paired GDN q/k norms.
- GDN / attention-gate decode fusions: the BF16 alpha/beta pair with
  softplus(alpha + dt) * a in one mul_mat_vec_f launch (with the r108
  multi-sequence fix and its model-free regression test), the q/k norm pair in
  the direct conv kernel, the attention gate's row-strided view read in place by
  the gate -> Q8_1 kernel, the GDN output norm inside the gate kernel, and
  GGML_CUDA_GDN_TAIL (the sequential tail that writes the rollback snapshots).
- MMB and the HC16 BF16 streams: the per-context MMB state (two contexts
  interleaving must not share the activation cache or the marks), the BF16
  activation copies, DOWN16, and the graph-optimize marking passes.
- The MoE/MMQ decode fusions: mmvq-moe (the dedicated MoE multi-token kernel),
  the gate+up pair fold, silu(gate)*up into the mmq quantize, the dual-output
  matmul, the MoE down fold, and the weighted-down reduction.
- The verify-band arch extension: RDNA3_0 joins RDNA4 in the Q8_1 pre-quantize
  predicate and in the direct GDN conv.
- Meta/scheduler/allocator: the split-state refusals for a straddling split,
  the two-pass graph-optimize protocol (allocs_only / marks_only), graph-memory
  generations so a graph is recaptured when the pool / FA staging / H2D ring
  memory it captured is freed -- including the slab work-boundary shrink of
  issue ggml-org#187 -- the KV prefill pad (LLAMA_KV_N_PAD_PREFILL), and the FA accuracy
  instrument (LLAMA_TEST_OP_NMSE / LLAMA_TEST_SEED).
- bf16 RoPE destinations (TODO ggml-org#83): the missing NORMAL/NEOX bf16
  instantiations, so -ctk bf16 -ctv bf16 prefill does not abort in rope.cu.

Env-read hygiene (no behaviour change): resolve GGML_CUDA_GDN_CHUNKED /
GGML_CUDA_GDN_CHUNKED_BF16 and the GDN_DBG_SKIP_* diagnostics once into values
rather than caching the getenv() pointer: the MSVC CRT returns a buffer that the
next getenv() call overwrites, so a cached pointer is unsafe on Windows.

Build fix: the GGML_CUDA_WORK_ALLOC_DEBUG read in llama_context::graph_reserve
lives in src/ (not linked against the CUDA common.cuh), so it uses a local
static instead of the CUDA helper.

Split note (r109): this commit plus block 11 carries exactly the tree the old
block 10 carried -- the net set is unchanged.  What moved to block 11 is the
qwen4exp model graph, the QSA/indexer ops and their kernels, the
hyper-connection ops, the managed lazy reader and the keys-only indexer cache,
i.e. everything that exists only because of that architecture.  The pieces of
the old block 10 that exist for qwen4exp but are implemented inside a general
kernel TU (the GDN gate/beta fusion, the HC16 MMB BF16 streams, the qwen4exp
weighted-down reduction, the PLE conv fusion) stay here with the TU that owns
them; the HC_BLK16/RES16 marking pass and the indexer relu-sum alloc-dep moved
to block 11 with the matchers they call.

Windows HIP build (issue ggml-org#217): the tables-registration slack guard uses the int64_t min/max helpers
block 09 defines instead of `std::min<int64_t>`/`std::max<int64_t>`.  With HIP on Windows (clang + the
MSVC STL) clang's force-included `cuda_wrappers/algorithm` and the MSVC STL `<utility>` each define an
inline `std::min<long long>` (`int64_t` is `__int64` there, and the `enable_if` that makes clang's
version win overload resolution is not part of the mangled name), so a translation unit that
instantiates both fails to codegen with "definition with same mangled name".  Behaviour is unchanged.

Amended (r132): the block-10 arms of the Q8_1 cache fix that block 08 introduces.  The fused GLU -> Q8_1 site's
key walk stops at the first pointer change (the fused write is keyed by the matmul's src1, and must not take the
root's entry for an offset view), and both of this block's gated-q8_1 launch arms -- the fused norm+gate kernel
and the GLU write -- validate their sources with q8_1_src_range_ok() before launching.  From PR ggml-org#218 (@slavap);
the rule and the validation are recorded with block 08.

Co-authored-by: Slava P. <[email protected]>
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Oct 27, 2026
…rastructure)

The infrastructure half of the old block 10.  qwen4exp, QSA and the
hyper-connection ops now live in their own block (11); this block is what they
are built on, and it no longer references them.

Contents:

- The movable-boundary slab and its arena (ggml-cuda-slab.cu,
  ggml-cuda-arena.cu, ggml-cuda-vmm.h, ggml-cuda-moe-cache-hooks.cu): one VMM
  reserve per device split by a movable boundary -- compute below, MoE arena
  above, no HIP call at runtime.  Plus the narrow-band learning, the wide-phase
  auxiliary region, pool-wide routing, and the slab transient absorption.
- The fusion dispatcher (ggml-cuda-try-fuse.cu): the matcher arms moved out of
  ggml-cuda.cu, with every arm implemented inside the kernel TU that owns it.
- The async graph-input ring: batched uploads + lazy done event (PR ggml-org#182), the
  r90 snapshot fix (the scheduler's set_tensor_async path is used for a CPU
  split's output, which the next ubatch rewrites), default-on, and the per-origin
  (per host thread) ordering state of issue ggml-org#201.
- Rope/FWHT fusions: M-ROPE and IMROPE in the RMS_NORM + MUL + ROPE (+ FWHT)
  matcher, BF16 SET_ROWS kept off the 5-op fusion, the q8_0 K/V cache writes
  folded into the rope + FWHT kernel, and the paired GDN q/k norms.
- GDN / attention-gate decode fusions: the BF16 alpha/beta pair with
  softplus(alpha + dt) * a in one mul_mat_vec_f launch (with the r108
  multi-sequence fix and its model-free regression test), the q/k norm pair in
  the direct conv kernel, the attention gate's row-strided view read in place by
  the gate -> Q8_1 kernel, the GDN output norm inside the gate kernel, and
  GGML_CUDA_GDN_TAIL (the sequential tail that writes the rollback snapshots).
- MMB and the HC16 BF16 streams: the per-context MMB state (two contexts
  interleaving must not share the activation cache or the marks), the BF16
  activation copies, DOWN16, and the graph-optimize marking passes.
- The MoE/MMQ decode fusions: mmvq-moe (the dedicated MoE multi-token kernel),
  the gate+up pair fold, silu(gate)*up into the mmq quantize, the dual-output
  matmul, the MoE down fold, and the weighted-down reduction.
- The verify-band arch extension: RDNA3_0 joins RDNA4 in the Q8_1 pre-quantize
  predicate and in the direct GDN conv.
- Meta/scheduler/allocator: the split-state refusals for a straddling split,
  the two-pass graph-optimize protocol (allocs_only / marks_only), graph-memory
  generations so a graph is recaptured when the pool / FA staging / H2D ring
  memory it captured is freed -- including the slab work-boundary shrink of
  issue ggml-org#187 -- the KV prefill pad (LLAMA_KV_N_PAD_PREFILL), and the FA accuracy
  instrument (LLAMA_TEST_OP_NMSE / LLAMA_TEST_SEED).
- bf16 RoPE destinations (TODO ggml-org#83): the missing NORMAL/NEOX bf16
  instantiations, so -ctk bf16 -ctv bf16 prefill does not abort in rope.cu.

Env-read hygiene (no behaviour change): resolve GGML_CUDA_GDN_CHUNKED /
GGML_CUDA_GDN_CHUNKED_BF16 and the GDN_DBG_SKIP_* diagnostics once into values
rather than caching the getenv() pointer: the MSVC CRT returns a buffer that the
next getenv() call overwrites, so a cached pointer is unsafe on Windows.

Build fix: the GGML_CUDA_WORK_ALLOC_DEBUG read in llama_context::graph_reserve
lives in src/ (not linked against the CUDA common.cuh), so it uses a local
static instead of the CUDA helper.

Split note (r109): this commit plus block 11 carries exactly the tree the old
block 10 carried -- the net set is unchanged.  What moved to block 11 is the
qwen4exp model graph, the QSA/indexer ops and their kernels, the
hyper-connection ops, the managed lazy reader and the keys-only indexer cache,
i.e. everything that exists only because of that architecture.  The pieces of
the old block 10 that exist for qwen4exp but are implemented inside a general
kernel TU (the GDN gate/beta fusion, the HC16 MMB BF16 streams, the qwen4exp
weighted-down reduction, the PLE conv fusion) stay here with the TU that owns
them; the HC_BLK16/RES16 marking pass and the indexer relu-sum alloc-dep moved
to block 11 with the matchers they call.

Windows HIP build (issue ggml-org#217): the tables-registration slack guard uses the int64_t min/max helpers
block 09 defines instead of `std::min<int64_t>`/`std::max<int64_t>`.  With HIP on Windows (clang + the
MSVC STL) clang's force-included `cuda_wrappers/algorithm` and the MSVC STL `<utility>` each define an
inline `std::min<long long>` (`int64_t` is `__int64` there, and the `enable_if` that makes clang's
version win overload resolution is not part of the mangled name), so a translation unit that
instantiates both fails to codegen with "definition with same mangled name".  Behaviour is unchanged.

Amended (r132): the block-10 arms of the Q8_1 cache fix that block 08 introduces.  The fused GLU -> Q8_1 site's
key walk stops at the first pointer change (the fused write is keyed by the matmul's src1, and must not take the
root's entry for an offset view), and both of this block's gated-q8_1 launch arms -- the fused norm+gate kernel
and the GLU write -- validate their sources with q8_1_src_range_ok() before launching.  From PR ggml-org#218 (@slavap);
the rule and the validation are recorded with block 08.

Co-authored-by: Slava P. <[email protected]>
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Oct 28, 2026
…rastructure)

The infrastructure half of the old block 10.  qwen4exp, QSA and the
hyper-connection ops now live in their own block (11); this block is what they
are built on, and it no longer references them.

Contents:

- The movable-boundary slab and its arena (ggml-cuda-slab.cu,
  ggml-cuda-arena.cu, ggml-cuda-vmm.h, ggml-cuda-moe-cache-hooks.cu): one VMM
  reserve per device split by a movable boundary -- compute below, MoE arena
  above, no HIP call at runtime.  Plus the narrow-band learning, the wide-phase
  auxiliary region, pool-wide routing, and the slab transient absorption.
- The fusion dispatcher (ggml-cuda-try-fuse.cu): the matcher arms moved out of
  ggml-cuda.cu, with every arm implemented inside the kernel TU that owns it.
- The async graph-input ring: batched uploads + lazy done event (PR ggml-org#182), the
  r90 snapshot fix (the scheduler's set_tensor_async path is used for a CPU
  split's output, which the next ubatch rewrites), default-on, and the per-origin
  (per host thread) ordering state of issue ggml-org#201.
- Rope/FWHT fusions: M-ROPE and IMROPE in the RMS_NORM + MUL + ROPE (+ FWHT)
  matcher, BF16 SET_ROWS kept off the 5-op fusion, the q8_0 K/V cache writes
  folded into the rope + FWHT kernel, and the paired GDN q/k norms.
- GDN / attention-gate decode fusions: the BF16 alpha/beta pair with
  softplus(alpha + dt) * a in one mul_mat_vec_f launch (with the r108
  multi-sequence fix and its model-free regression test), the q/k norm pair in
  the direct conv kernel, the attention gate's row-strided view read in place by
  the gate -> Q8_1 kernel, the GDN output norm inside the gate kernel, and
  GGML_CUDA_GDN_TAIL (the sequential tail that writes the rollback snapshots).
- MMB and the HC16 BF16 streams: the per-context MMB state (two contexts
  interleaving must not share the activation cache or the marks), the BF16
  activation copies, DOWN16, and the graph-optimize marking passes.
- The MoE/MMQ decode fusions: mmvq-moe (the dedicated MoE multi-token kernel),
  the gate+up pair fold, silu(gate)*up into the mmq quantize, the dual-output
  matmul, the MoE down fold, and the weighted-down reduction.
- The verify-band arch extension: RDNA3_0 joins RDNA4 in the Q8_1 pre-quantize
  predicate and in the direct GDN conv.
- Meta/scheduler/allocator: the split-state refusals for a straddling split,
  the two-pass graph-optimize protocol (allocs_only / marks_only), graph-memory
  generations so a graph is recaptured when the pool / FA staging / H2D ring
  memory it captured is freed -- including the slab work-boundary shrink of
  issue ggml-org#187 -- the KV prefill pad (LLAMA_KV_N_PAD_PREFILL), and the FA accuracy
  instrument (LLAMA_TEST_OP_NMSE / LLAMA_TEST_SEED).
- bf16 RoPE destinations (TODO ggml-org#83): the missing NORMAL/NEOX bf16
  instantiations, so -ctk bf16 -ctv bf16 prefill does not abort in rope.cu.

Env-read hygiene (no behaviour change): resolve GGML_CUDA_GDN_CHUNKED /
GGML_CUDA_GDN_CHUNKED_BF16 and the GDN_DBG_SKIP_* diagnostics once into values
rather than caching the getenv() pointer: the MSVC CRT returns a buffer that the
next getenv() call overwrites, so a cached pointer is unsafe on Windows.

Build fix: the GGML_CUDA_WORK_ALLOC_DEBUG read in llama_context::graph_reserve
lives in src/ (not linked against the CUDA common.cuh), so it uses a local
static instead of the CUDA helper.

Split note (r109): this commit plus block 11 carries exactly the tree the old
block 10 carried -- the net set is unchanged.  What moved to block 11 is the
qwen4exp model graph, the QSA/indexer ops and their kernels, the
hyper-connection ops, the managed lazy reader and the keys-only indexer cache,
i.e. everything that exists only because of that architecture.  The pieces of
the old block 10 that exist for qwen4exp but are implemented inside a general
kernel TU (the GDN gate/beta fusion, the HC16 MMB BF16 streams, the qwen4exp
weighted-down reduction, the PLE conv fusion) stay here with the TU that owns
them; the HC_BLK16/RES16 marking pass and the indexer relu-sum alloc-dep moved
to block 11 with the matchers they call.

Windows HIP build (issue ggml-org#217): the tables-registration slack guard uses the int64_t min/max helpers
block 09 defines instead of `std::min<int64_t>`/`std::max<int64_t>`.  With HIP on Windows (clang + the
MSVC STL) clang's force-included `cuda_wrappers/algorithm` and the MSVC STL `<utility>` each define an
inline `std::min<long long>` (`int64_t` is `__int64` there, and the `enable_if` that makes clang's
version win overload resolution is not part of the mangled name), so a translation unit that
instantiates both fails to codegen with "definition with same mangled name".  Behaviour is unchanged.

Amended (r132): the block-10 arms of the Q8_1 cache fix that block 08 introduces.  The fused GLU -> Q8_1 site's
key walk stops at the first pointer change (the fused write is keyed by the matmul's src1, and must not take the
root's entry for an offset view), and both of this block's gated-q8_1 launch arms -- the fused norm+gate kernel
and the GLU write -- validate their sources with q8_1_src_range_ok() before launching.  From PR ggml-org#218 (@slavap);
the rule and the validation are recorded with block 08.

Co-authored-by: Slava P. <[email protected]>
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Oct 28, 2026
…rastructure)

The infrastructure half of the old block 10.  qwen4exp, QSA and the
hyper-connection ops now live in their own block (11); this block is what they
are built on, and it no longer references them.

Contents:

- The movable-boundary slab and its arena (ggml-cuda-slab.cu,
  ggml-cuda-arena.cu, ggml-cuda-vmm.h, ggml-cuda-moe-cache-hooks.cu): one VMM
  reserve per device split by a movable boundary -- compute below, MoE arena
  above, no HIP call at runtime.  Plus the narrow-band learning, the wide-phase
  auxiliary region, pool-wide routing, and the slab transient absorption.
- The fusion dispatcher (ggml-cuda-try-fuse.cu): the matcher arms moved out of
  ggml-cuda.cu, with every arm implemented inside the kernel TU that owns it.
- The async graph-input ring: batched uploads + lazy done event (PR ggml-org#182), the
  r90 snapshot fix (the scheduler's set_tensor_async path is used for a CPU
  split's output, which the next ubatch rewrites), default-on, and the per-origin
  (per host thread) ordering state of issue ggml-org#201.
- Rope/FWHT fusions: M-ROPE and IMROPE in the RMS_NORM + MUL + ROPE (+ FWHT)
  matcher, BF16 SET_ROWS kept off the 5-op fusion, the q8_0 K/V cache writes
  folded into the rope + FWHT kernel, and the paired GDN q/k norms.
- GDN / attention-gate decode fusions: the BF16 alpha/beta pair with
  softplus(alpha + dt) * a in one mul_mat_vec_f launch (with the r108
  multi-sequence fix and its model-free regression test), the q/k norm pair in
  the direct conv kernel, the attention gate's row-strided view read in place by
  the gate -> Q8_1 kernel, the GDN output norm inside the gate kernel, and
  GGML_CUDA_GDN_TAIL (the sequential tail that writes the rollback snapshots).
- MMB and the HC16 BF16 streams: the per-context MMB state (two contexts
  interleaving must not share the activation cache or the marks), the BF16
  activation copies, DOWN16, and the graph-optimize marking passes.
- The MoE/MMQ decode fusions: mmvq-moe (the dedicated MoE multi-token kernel),
  the gate+up pair fold, silu(gate)*up into the mmq quantize, the dual-output
  matmul, the MoE down fold, and the weighted-down reduction.
- The verify-band arch extension: RDNA3_0 joins RDNA4 in the Q8_1 pre-quantize
  predicate and in the direct GDN conv.
- Meta/scheduler/allocator: the split-state refusals for a straddling split,
  the two-pass graph-optimize protocol (allocs_only / marks_only), graph-memory
  generations so a graph is recaptured when the pool / FA staging / H2D ring
  memory it captured is freed -- including the slab work-boundary shrink of
  issue ggml-org#187 -- the KV prefill pad (LLAMA_KV_N_PAD_PREFILL), and the FA accuracy
  instrument (LLAMA_TEST_OP_NMSE / LLAMA_TEST_SEED).
- bf16 RoPE destinations (TODO ggml-org#83): the missing NORMAL/NEOX bf16
  instantiations, so -ctk bf16 -ctv bf16 prefill does not abort in rope.cu.

Env-read hygiene (no behaviour change): resolve GGML_CUDA_GDN_CHUNKED /
GGML_CUDA_GDN_CHUNKED_BF16 and the GDN_DBG_SKIP_* diagnostics once into values
rather than caching the getenv() pointer: the MSVC CRT returns a buffer that the
next getenv() call overwrites, so a cached pointer is unsafe on Windows.

Build fix: the GGML_CUDA_WORK_ALLOC_DEBUG read in llama_context::graph_reserve
lives in src/ (not linked against the CUDA common.cuh), so it uses a local
static instead of the CUDA helper.

Split note (r109): this commit plus block 11 carries exactly the tree the old
block 10 carried -- the net set is unchanged.  What moved to block 11 is the
qwen4exp model graph, the QSA/indexer ops and their kernels, the
hyper-connection ops, the managed lazy reader and the keys-only indexer cache,
i.e. everything that exists only because of that architecture.  The pieces of
the old block 10 that exist for qwen4exp but are implemented inside a general
kernel TU (the GDN gate/beta fusion, the HC16 MMB BF16 streams, the qwen4exp
weighted-down reduction, the PLE conv fusion) stay here with the TU that owns
them; the HC_BLK16/RES16 marking pass and the indexer relu-sum alloc-dep moved
to block 11 with the matchers they call.

Windows HIP build (issue ggml-org#217): the tables-registration slack guard uses the int64_t min/max helpers
block 09 defines instead of `std::min<int64_t>`/`std::max<int64_t>`.  With HIP on Windows (clang + the
MSVC STL) clang's force-included `cuda_wrappers/algorithm` and the MSVC STL `<utility>` each define an
inline `std::min<long long>` (`int64_t` is `__int64` there, and the `enable_if` that makes clang's
version win overload resolution is not part of the mangled name), so a translation unit that
instantiates both fails to codegen with "definition with same mangled name".  Behaviour is unchanged.

Amended (r132): the block-10 arms of the Q8_1 cache fix that block 08 introduces.  The fused GLU -> Q8_1 site's
key walk stops at the first pointer change (the fused write is keyed by the matmul's src1, and must not take the
root's entry for an offset view), and both of this block's gated-q8_1 launch arms -- the fused norm+gate kernel
and the GLU write -- validate their sources with q8_1_src_range_ok() before launching.  From PR ggml-org#218 (@slavap);
the rule and the validation are recorded with block 08.

Co-authored-by: Slava P. <[email protected]>
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Oct 28, 2026
…rastructure)

The infrastructure half of the old block 10.  qwen4exp, QSA and the
hyper-connection ops now live in their own block (11); this block is what they
are built on, and it no longer references them.

Contents:

- The movable-boundary slab and its arena (ggml-cuda-slab.cu,
  ggml-cuda-arena.cu, ggml-cuda-vmm.h, ggml-cuda-moe-cache-hooks.cu): one VMM
  reserve per device split by a movable boundary -- compute below, MoE arena
  above, no HIP call at runtime.  Plus the narrow-band learning, the wide-phase
  auxiliary region, pool-wide routing, and the slab transient absorption.
- The fusion dispatcher (ggml-cuda-try-fuse.cu): the matcher arms moved out of
  ggml-cuda.cu, with every arm implemented inside the kernel TU that owns it.
- The async graph-input ring: batched uploads + lazy done event (PR ggml-org#182), the
  r90 snapshot fix (the scheduler's set_tensor_async path is used for a CPU
  split's output, which the next ubatch rewrites), default-on, and the per-origin
  (per host thread) ordering state of issue ggml-org#201.
- Rope/FWHT fusions: M-ROPE and IMROPE in the RMS_NORM + MUL + ROPE (+ FWHT)
  matcher, BF16 SET_ROWS kept off the 5-op fusion, the q8_0 K/V cache writes
  folded into the rope + FWHT kernel, and the paired GDN q/k norms.
- GDN / attention-gate decode fusions: the BF16 alpha/beta pair with
  softplus(alpha + dt) * a in one mul_mat_vec_f launch (with the r108
  multi-sequence fix and its model-free regression test), the q/k norm pair in
  the direct conv kernel, the attention gate's row-strided view read in place by
  the gate -> Q8_1 kernel, the GDN output norm inside the gate kernel, and
  GGML_CUDA_GDN_TAIL (the sequential tail that writes the rollback snapshots).
- MMB and the HC16 BF16 streams: the per-context MMB state (two contexts
  interleaving must not share the activation cache or the marks), the BF16
  activation copies, DOWN16, and the graph-optimize marking passes.
- The MoE/MMQ decode fusions: mmvq-moe (the dedicated MoE multi-token kernel),
  the gate+up pair fold, silu(gate)*up into the mmq quantize, the dual-output
  matmul, the MoE down fold, and the weighted-down reduction.
- The verify-band arch extension: RDNA3_0 joins RDNA4 in the Q8_1 pre-quantize
  predicate and in the direct GDN conv.
- Meta/scheduler/allocator: the split-state refusals for a straddling split,
  the two-pass graph-optimize protocol (allocs_only / marks_only), graph-memory
  generations so a graph is recaptured when the pool / FA staging / H2D ring
  memory it captured is freed -- including the slab work-boundary shrink of
  issue ggml-org#187 -- the KV prefill pad (LLAMA_KV_N_PAD_PREFILL), and the FA accuracy
  instrument (LLAMA_TEST_OP_NMSE / LLAMA_TEST_SEED).
- bf16 RoPE destinations (TODO ggml-org#83): the missing NORMAL/NEOX bf16
  instantiations, so -ctk bf16 -ctv bf16 prefill does not abort in rope.cu.

Env-read hygiene (no behaviour change): resolve GGML_CUDA_GDN_CHUNKED /
GGML_CUDA_GDN_CHUNKED_BF16 and the GDN_DBG_SKIP_* diagnostics once into values
rather than caching the getenv() pointer: the MSVC CRT returns a buffer that the
next getenv() call overwrites, so a cached pointer is unsafe on Windows.

Build fix: the GGML_CUDA_WORK_ALLOC_DEBUG read in llama_context::graph_reserve
lives in src/ (not linked against the CUDA common.cuh), so it uses a local
static instead of the CUDA helper.

Split note (r109): this commit plus block 11 carries exactly the tree the old
block 10 carried -- the net set is unchanged.  What moved to block 11 is the
qwen4exp model graph, the QSA/indexer ops and their kernels, the
hyper-connection ops, the managed lazy reader and the keys-only indexer cache,
i.e. everything that exists only because of that architecture.  The pieces of
the old block 10 that exist for qwen4exp but are implemented inside a general
kernel TU (the GDN gate/beta fusion, the HC16 MMB BF16 streams, the qwen4exp
weighted-down reduction, the PLE conv fusion) stay here with the TU that owns
them; the HC_BLK16/RES16 marking pass and the indexer relu-sum alloc-dep moved
to block 11 with the matchers they call.

Windows HIP build (issue ggml-org#217): the tables-registration slack guard uses the int64_t min/max helpers
block 09 defines instead of `std::min<int64_t>`/`std::max<int64_t>`.  With HIP on Windows (clang + the
MSVC STL) clang's force-included `cuda_wrappers/algorithm` and the MSVC STL `<utility>` each define an
inline `std::min<long long>` (`int64_t` is `__int64` there, and the `enable_if` that makes clang's
version win overload resolution is not part of the mangled name), so a translation unit that
instantiates both fails to codegen with "definition with same mangled name".  Behaviour is unchanged.

Amended (r132): the block-10 arms of the Q8_1 cache fix that block 08 introduces.  The fused GLU -> Q8_1 site's
key walk stops at the first pointer change (the fused write is keyed by the matmul's src1, and must not take the
root's entry for an offset view), and both of this block's gated-q8_1 launch arms -- the fused norm+gate kernel
and the GLU write -- validate their sources with q8_1_src_range_ok() before launching.  From PR ggml-org#218 (@slavap);
the rule and the validation are recorded with block 08.

Co-authored-by: Slava P. <[email protected]>
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Oct 28, 2026
…rastructure)

The infrastructure half of the old block 10.  qwen4exp, QSA and the
hyper-connection ops now live in their own block (11); this block is what they
are built on, and it no longer references them.

Contents:

- The movable-boundary slab and its arena (ggml-cuda-slab.cu,
  ggml-cuda-arena.cu, ggml-cuda-vmm.h, ggml-cuda-moe-cache-hooks.cu): one VMM
  reserve per device split by a movable boundary -- compute below, MoE arena
  above, no HIP call at runtime.  Plus the narrow-band learning, the wide-phase
  auxiliary region, pool-wide routing, and the slab transient absorption.
- The fusion dispatcher (ggml-cuda-try-fuse.cu): the matcher arms moved out of
  ggml-cuda.cu, with every arm implemented inside the kernel TU that owns it.
- The async graph-input ring: batched uploads + lazy done event (PR ggml-org#182), the
  r90 snapshot fix (the scheduler's set_tensor_async path is used for a CPU
  split's output, which the next ubatch rewrites), default-on, and the per-origin
  (per host thread) ordering state of issue ggml-org#201.
- Rope/FWHT fusions: M-ROPE and IMROPE in the RMS_NORM + MUL + ROPE (+ FWHT)
  matcher, BF16 SET_ROWS kept off the 5-op fusion, the q8_0 K/V cache writes
  folded into the rope + FWHT kernel, and the paired GDN q/k norms.
- GDN / attention-gate decode fusions: the BF16 alpha/beta pair with
  softplus(alpha + dt) * a in one mul_mat_vec_f launch (with the r108
  multi-sequence fix and its model-free regression test), the q/k norm pair in
  the direct conv kernel, the attention gate's row-strided view read in place by
  the gate -> Q8_1 kernel, the GDN output norm inside the gate kernel, and
  GGML_CUDA_GDN_TAIL (the sequential tail that writes the rollback snapshots).
- MMB and the HC16 BF16 streams: the per-context MMB state (two contexts
  interleaving must not share the activation cache or the marks), the BF16
  activation copies, DOWN16, and the graph-optimize marking passes.
- The MoE/MMQ decode fusions: mmvq-moe (the dedicated MoE multi-token kernel),
  the gate+up pair fold, silu(gate)*up into the mmq quantize, the dual-output
  matmul, the MoE down fold, and the weighted-down reduction.
- The verify-band arch extension: RDNA3_0 joins RDNA4 in the Q8_1 pre-quantize
  predicate and in the direct GDN conv.
- Meta/scheduler/allocator: the split-state refusals for a straddling split,
  the two-pass graph-optimize protocol (allocs_only / marks_only), graph-memory
  generations so a graph is recaptured when the pool / FA staging / H2D ring
  memory it captured is freed -- including the slab work-boundary shrink of
  issue ggml-org#187 -- the KV prefill pad (LLAMA_KV_N_PAD_PREFILL), and the FA accuracy
  instrument (LLAMA_TEST_OP_NMSE / LLAMA_TEST_SEED).
- bf16 RoPE destinations (TODO ggml-org#83): the missing NORMAL/NEOX bf16
  instantiations, so -ctk bf16 -ctv bf16 prefill does not abort in rope.cu.

Env-read hygiene (no behaviour change): resolve GGML_CUDA_GDN_CHUNKED /
GGML_CUDA_GDN_CHUNKED_BF16 and the GDN_DBG_SKIP_* diagnostics once into values
rather than caching the getenv() pointer: the MSVC CRT returns a buffer that the
next getenv() call overwrites, so a cached pointer is unsafe on Windows.

Build fix: the GGML_CUDA_WORK_ALLOC_DEBUG read in llama_context::graph_reserve
lives in src/ (not linked against the CUDA common.cuh), so it uses a local
static instead of the CUDA helper.

Split note (r109): this commit plus block 11 carries exactly the tree the old
block 10 carried -- the net set is unchanged.  What moved to block 11 is the
qwen4exp model graph, the QSA/indexer ops and their kernels, the
hyper-connection ops, the managed lazy reader and the keys-only indexer cache,
i.e. everything that exists only because of that architecture.  The pieces of
the old block 10 that exist for qwen4exp but are implemented inside a general
kernel TU (the GDN gate/beta fusion, the HC16 MMB BF16 streams, the qwen4exp
weighted-down reduction, the PLE conv fusion) stay here with the TU that owns
them; the HC_BLK16/RES16 marking pass and the indexer relu-sum alloc-dep moved
to block 11 with the matchers they call.

Windows HIP build (issue ggml-org#217): the tables-registration slack guard uses the int64_t min/max helpers
block 09 defines instead of `std::min<int64_t>`/`std::max<int64_t>`.  With HIP on Windows (clang + the
MSVC STL) clang's force-included `cuda_wrappers/algorithm` and the MSVC STL `<utility>` each define an
inline `std::min<long long>` (`int64_t` is `__int64` there, and the `enable_if` that makes clang's
version win overload resolution is not part of the mangled name), so a translation unit that
instantiates both fails to codegen with "definition with same mangled name".  Behaviour is unchanged.

Amended (r132): the block-10 arms of the Q8_1 cache fix that block 08 introduces.  The fused GLU -> Q8_1 site's
key walk stops at the first pointer change (the fused write is keyed by the matmul's src1, and must not take the
root's entry for an offset view), and both of this block's gated-q8_1 launch arms -- the fused norm+gate kernel
and the GLU write -- validate their sources with q8_1_src_range_ok() before launching.  From PR ggml-org#218 (@slavap);
the rule and the validation are recorded with block 08.

Co-authored-by: Slava P. <[email protected]>
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Oct 28, 2026
…rastructure)

The infrastructure half of the old block 10.  qwen4exp, QSA and the
hyper-connection ops now live in their own block (11); this block is what they
are built on, and it no longer references them.

Contents:

- The movable-boundary slab and its arena (ggml-cuda-slab.cu,
  ggml-cuda-arena.cu, ggml-cuda-vmm.h, ggml-cuda-moe-cache-hooks.cu): one VMM
  reserve per device split by a movable boundary -- compute below, MoE arena
  above, no HIP call at runtime.  Plus the narrow-band learning, the wide-phase
  auxiliary region, pool-wide routing, and the slab transient absorption.
- The fusion dispatcher (ggml-cuda-try-fuse.cu): the matcher arms moved out of
  ggml-cuda.cu, with every arm implemented inside the kernel TU that owns it.
- The async graph-input ring: batched uploads + lazy done event (PR ggml-org#182), the
  r90 snapshot fix (the scheduler's set_tensor_async path is used for a CPU
  split's output, which the next ubatch rewrites), default-on, and the per-origin
  (per host thread) ordering state of issue ggml-org#201.
- Rope/FWHT fusions: M-ROPE and IMROPE in the RMS_NORM + MUL + ROPE (+ FWHT)
  matcher, BF16 SET_ROWS kept off the 5-op fusion, the q8_0 K/V cache writes
  folded into the rope + FWHT kernel, and the paired GDN q/k norms.
- GDN / attention-gate decode fusions: the BF16 alpha/beta pair with
  softplus(alpha + dt) * a in one mul_mat_vec_f launch (with the r108
  multi-sequence fix and its model-free regression test), the q/k norm pair in
  the direct conv kernel, the attention gate's row-strided view read in place by
  the gate -> Q8_1 kernel, the GDN output norm inside the gate kernel, and
  GGML_CUDA_GDN_TAIL (the sequential tail that writes the rollback snapshots).
- MMB and the HC16 BF16 streams: the per-context MMB state (two contexts
  interleaving must not share the activation cache or the marks), the BF16
  activation copies, DOWN16, and the graph-optimize marking passes.
- The MoE/MMQ decode fusions: mmvq-moe (the dedicated MoE multi-token kernel),
  the gate+up pair fold, silu(gate)*up into the mmq quantize, the dual-output
  matmul, the MoE down fold, and the weighted-down reduction.
- The verify-band arch extension: RDNA3_0 joins RDNA4 in the Q8_1 pre-quantize
  predicate and in the direct GDN conv.
- Meta/scheduler/allocator: the split-state refusals for a straddling split,
  the two-pass graph-optimize protocol (allocs_only / marks_only), graph-memory
  generations so a graph is recaptured when the pool / FA staging / H2D ring
  memory it captured is freed -- including the slab work-boundary shrink of
  issue ggml-org#187 -- the KV prefill pad (LLAMA_KV_N_PAD_PREFILL), and the FA accuracy
  instrument (LLAMA_TEST_OP_NMSE / LLAMA_TEST_SEED).
- bf16 RoPE destinations (TODO ggml-org#83): the missing NORMAL/NEOX bf16
  instantiations, so -ctk bf16 -ctv bf16 prefill does not abort in rope.cu.

Env-read hygiene (no behaviour change): resolve GGML_CUDA_GDN_CHUNKED /
GGML_CUDA_GDN_CHUNKED_BF16 and the GDN_DBG_SKIP_* diagnostics once into values
rather than caching the getenv() pointer: the MSVC CRT returns a buffer that the
next getenv() call overwrites, so a cached pointer is unsafe on Windows.

Build fix: the GGML_CUDA_WORK_ALLOC_DEBUG read in llama_context::graph_reserve
lives in src/ (not linked against the CUDA common.cuh), so it uses a local
static instead of the CUDA helper.

Split note (r109): this commit plus block 11 carries exactly the tree the old
block 10 carried -- the net set is unchanged.  What moved to block 11 is the
qwen4exp model graph, the QSA/indexer ops and their kernels, the
hyper-connection ops, the managed lazy reader and the keys-only indexer cache,
i.e. everything that exists only because of that architecture.  The pieces of
the old block 10 that exist for qwen4exp but are implemented inside a general
kernel TU (the GDN gate/beta fusion, the HC16 MMB BF16 streams, the qwen4exp
weighted-down reduction, the PLE conv fusion) stay here with the TU that owns
them; the HC_BLK16/RES16 marking pass and the indexer relu-sum alloc-dep moved
to block 11 with the matchers they call.

Windows HIP build (issue ggml-org#217): the tables-registration slack guard uses the int64_t min/max helpers
block 09 defines instead of `std::min<int64_t>`/`std::max<int64_t>`.  With HIP on Windows (clang + the
MSVC STL) clang's force-included `cuda_wrappers/algorithm` and the MSVC STL `<utility>` each define an
inline `std::min<long long>` (`int64_t` is `__int64` there, and the `enable_if` that makes clang's
version win overload resolution is not part of the mangled name), so a translation unit that
instantiates both fails to codegen with "definition with same mangled name".  Behaviour is unchanged.

Amended (r132): the block-10 arms of the Q8_1 cache fix that block 08 introduces.  The fused GLU -> Q8_1 site's
key walk stops at the first pointer change (the fused write is keyed by the matmul's src1, and must not take the
root's entry for an offset view), and both of this block's gated-q8_1 launch arms -- the fused norm+gate kernel
and the GLU write -- validate their sources with q8_1_src_range_ok() before launching.  From PR ggml-org#218 (@slavap);
the rule and the validation are recorded with block 08.

Co-authored-by: Slava P. <[email protected]>
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Oct 28, 2026
…rastructure)

The infrastructure half of the old block 10.  qwen4exp, QSA and the
hyper-connection ops now live in their own block (11); this block is what they
are built on, and it no longer references them.

Contents:

- The movable-boundary slab and its arena (ggml-cuda-slab.cu,
  ggml-cuda-arena.cu, ggml-cuda-vmm.h, ggml-cuda-moe-cache-hooks.cu): one VMM
  reserve per device split by a movable boundary -- compute below, MoE arena
  above, no HIP call at runtime.  Plus the narrow-band learning, the wide-phase
  auxiliary region, pool-wide routing, and the slab transient absorption.
- The fusion dispatcher (ggml-cuda-try-fuse.cu): the matcher arms moved out of
  ggml-cuda.cu, with every arm implemented inside the kernel TU that owns it.
- The async graph-input ring: batched uploads + lazy done event (PR ggml-org#182), the
  r90 snapshot fix (the scheduler's set_tensor_async path is used for a CPU
  split's output, which the next ubatch rewrites), default-on, and the per-origin
  (per host thread) ordering state of issue ggml-org#201.
- Rope/FWHT fusions: M-ROPE and IMROPE in the RMS_NORM + MUL + ROPE (+ FWHT)
  matcher, BF16 SET_ROWS kept off the 5-op fusion, the q8_0 K/V cache writes
  folded into the rope + FWHT kernel, and the paired GDN q/k norms.
- GDN / attention-gate decode fusions: the BF16 alpha/beta pair with
  softplus(alpha + dt) * a in one mul_mat_vec_f launch (with the r108
  multi-sequence fix and its model-free regression test), the q/k norm pair in
  the direct conv kernel, the attention gate's row-strided view read in place by
  the gate -> Q8_1 kernel, the GDN output norm inside the gate kernel, and
  GGML_CUDA_GDN_TAIL (the sequential tail that writes the rollback snapshots).
- MMB and the HC16 BF16 streams: the per-context MMB state (two contexts
  interleaving must not share the activation cache or the marks), the BF16
  activation copies, DOWN16, and the graph-optimize marking passes.
- The MoE/MMQ decode fusions: mmvq-moe (the dedicated MoE multi-token kernel),
  the gate+up pair fold, silu(gate)*up into the mmq quantize, the dual-output
  matmul, the MoE down fold, and the weighted-down reduction.
- The verify-band arch extension: RDNA3_0 joins RDNA4 in the Q8_1 pre-quantize
  predicate and in the direct GDN conv.
- Meta/scheduler/allocator: the split-state refusals for a straddling split,
  the two-pass graph-optimize protocol (allocs_only / marks_only), graph-memory
  generations so a graph is recaptured when the pool / FA staging / H2D ring
  memory it captured is freed -- including the slab work-boundary shrink of
  issue ggml-org#187 -- the KV prefill pad (LLAMA_KV_N_PAD_PREFILL), and the FA accuracy
  instrument (LLAMA_TEST_OP_NMSE / LLAMA_TEST_SEED).
- bf16 RoPE destinations (TODO ggml-org#83): the missing NORMAL/NEOX bf16
  instantiations, so -ctk bf16 -ctv bf16 prefill does not abort in rope.cu.

Env-read hygiene (no behaviour change): resolve GGML_CUDA_GDN_CHUNKED /
GGML_CUDA_GDN_CHUNKED_BF16 and the GDN_DBG_SKIP_* diagnostics once into values
rather than caching the getenv() pointer: the MSVC CRT returns a buffer that the
next getenv() call overwrites, so a cached pointer is unsafe on Windows.

Build fix: the GGML_CUDA_WORK_ALLOC_DEBUG read in llama_context::graph_reserve
lives in src/ (not linked against the CUDA common.cuh), so it uses a local
static instead of the CUDA helper.

Split note (r109): this commit plus block 11 carries exactly the tree the old
block 10 carried -- the net set is unchanged.  What moved to block 11 is the
qwen4exp model graph, the QSA/indexer ops and their kernels, the
hyper-connection ops, the managed lazy reader and the keys-only indexer cache,
i.e. everything that exists only because of that architecture.  The pieces of
the old block 10 that exist for qwen4exp but are implemented inside a general
kernel TU (the GDN gate/beta fusion, the HC16 MMB BF16 streams, the qwen4exp
weighted-down reduction, the PLE conv fusion) stay here with the TU that owns
them; the HC_BLK16/RES16 marking pass and the indexer relu-sum alloc-dep moved
to block 11 with the matchers they call.

Windows HIP build (issue ggml-org#217): the tables-registration slack guard uses the int64_t min/max helpers
block 09 defines instead of `std::min<int64_t>`/`std::max<int64_t>`.  With HIP on Windows (clang + the
MSVC STL) clang's force-included `cuda_wrappers/algorithm` and the MSVC STL `<utility>` each define an
inline `std::min<long long>` (`int64_t` is `__int64` there, and the `enable_if` that makes clang's
version win overload resolution is not part of the mangled name), so a translation unit that
instantiates both fails to codegen with "definition with same mangled name".  Behaviour is unchanged.

Amended (r132): the block-10 arms of the Q8_1 cache fix that block 08 introduces.  The fused GLU -> Q8_1 site's
key walk stops at the first pointer change (the fused write is keyed by the matmul's src1, and must not take the
root's entry for an offset view), and both of this block's gated-q8_1 launch arms -- the fused norm+gate kernel
and the GLU write -- validate their sources with q8_1_src_range_ok() before launching.  From PR ggml-org#218 (@slavap);
the rule and the validation are recorded with block 08.

Co-authored-by: Slava P. <[email protected]>
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Oct 28, 2026
…rastructure)

The infrastructure half of the old block 10.  qwen4exp, QSA and the
hyper-connection ops now live in their own block (11); this block is what they
are built on, and it no longer references them.

Contents:

- The movable-boundary slab and its arena (ggml-cuda-slab.cu,
  ggml-cuda-arena.cu, ggml-cuda-vmm.h, ggml-cuda-moe-cache-hooks.cu): one VMM
  reserve per device split by a movable boundary -- compute below, MoE arena
  above, no HIP call at runtime.  Plus the narrow-band learning, the wide-phase
  auxiliary region, pool-wide routing, and the slab transient absorption.
- The fusion dispatcher (ggml-cuda-try-fuse.cu): the matcher arms moved out of
  ggml-cuda.cu, with every arm implemented inside the kernel TU that owns it.
- The async graph-input ring: batched uploads + lazy done event (PR ggml-org#182), the
  r90 snapshot fix (the scheduler's set_tensor_async path is used for a CPU
  split's output, which the next ubatch rewrites), default-on, and the per-origin
  (per host thread) ordering state of issue ggml-org#201.
- Rope/FWHT fusions: M-ROPE and IMROPE in the RMS_NORM + MUL + ROPE (+ FWHT)
  matcher, BF16 SET_ROWS kept off the 5-op fusion, the q8_0 K/V cache writes
  folded into the rope + FWHT kernel, and the paired GDN q/k norms.
- GDN / attention-gate decode fusions: the BF16 alpha/beta pair with
  softplus(alpha + dt) * a in one mul_mat_vec_f launch (with the r108
  multi-sequence fix and its model-free regression test), the q/k norm pair in
  the direct conv kernel, the attention gate's row-strided view read in place by
  the gate -> Q8_1 kernel, the GDN output norm inside the gate kernel, and
  GGML_CUDA_GDN_TAIL (the sequential tail that writes the rollback snapshots).
- MMB and the HC16 BF16 streams: the per-context MMB state (two contexts
  interleaving must not share the activation cache or the marks), the BF16
  activation copies, DOWN16, and the graph-optimize marking passes.
- The MoE/MMQ decode fusions: mmvq-moe (the dedicated MoE multi-token kernel),
  the gate+up pair fold, silu(gate)*up into the mmq quantize, the dual-output
  matmul, the MoE down fold, and the weighted-down reduction.
- The verify-band arch extension: RDNA3_0 joins RDNA4 in the Q8_1 pre-quantize
  predicate and in the direct GDN conv.
- Meta/scheduler/allocator: the split-state refusals for a straddling split,
  the two-pass graph-optimize protocol (allocs_only / marks_only), graph-memory
  generations so a graph is recaptured when the pool / FA staging / H2D ring
  memory it captured is freed -- including the slab work-boundary shrink of
  issue ggml-org#187 -- the KV prefill pad (LLAMA_KV_N_PAD_PREFILL), and the FA accuracy
  instrument (LLAMA_TEST_OP_NMSE / LLAMA_TEST_SEED).
- bf16 RoPE destinations (TODO ggml-org#83): the missing NORMAL/NEOX bf16
  instantiations, so -ctk bf16 -ctv bf16 prefill does not abort in rope.cu.

Env-read hygiene (no behaviour change): resolve GGML_CUDA_GDN_CHUNKED /
GGML_CUDA_GDN_CHUNKED_BF16 and the GDN_DBG_SKIP_* diagnostics once into values
rather than caching the getenv() pointer: the MSVC CRT returns a buffer that the
next getenv() call overwrites, so a cached pointer is unsafe on Windows.

Build fix: the GGML_CUDA_WORK_ALLOC_DEBUG read in llama_context::graph_reserve
lives in src/ (not linked against the CUDA common.cuh), so it uses a local
static instead of the CUDA helper.

Split note (r109): this commit plus block 11 carries exactly the tree the old
block 10 carried -- the net set is unchanged.  What moved to block 11 is the
qwen4exp model graph, the QSA/indexer ops and their kernels, the
hyper-connection ops, the managed lazy reader and the keys-only indexer cache,
i.e. everything that exists only because of that architecture.  The pieces of
the old block 10 that exist for qwen4exp but are implemented inside a general
kernel TU (the GDN gate/beta fusion, the HC16 MMB BF16 streams, the qwen4exp
weighted-down reduction, the PLE conv fusion) stay here with the TU that owns
them; the HC_BLK16/RES16 marking pass and the indexer relu-sum alloc-dep moved
to block 11 with the matchers they call.

Windows HIP build (issue ggml-org#217): the tables-registration slack guard uses the int64_t min/max helpers
block 09 defines instead of `std::min<int64_t>`/`std::max<int64_t>`.  With HIP on Windows (clang + the
MSVC STL) clang's force-included `cuda_wrappers/algorithm` and the MSVC STL `<utility>` each define an
inline `std::min<long long>` (`int64_t` is `__int64` there, and the `enable_if` that makes clang's
version win overload resolution is not part of the mangled name), so a translation unit that
instantiates both fails to codegen with "definition with same mangled name".  Behaviour is unchanged.

Amended (r132): the block-10 arms of the Q8_1 cache fix that block 08 introduces.  The fused GLU -> Q8_1 site's
key walk stops at the first pointer change (the fused write is keyed by the matmul's src1, and must not take the
root's entry for an offset view), and both of this block's gated-q8_1 launch arms -- the fused norm+gate kernel
and the GLU write -- validate their sources with q8_1_src_range_ok() before launching.  From PR ggml-org#218 (@slavap);
the rule and the validation are recorded with block 08.

Co-authored-by: Slava P. <[email protected]>
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Oct 28, 2026
…rastructure)

The infrastructure half of the old block 10.  qwen4exp, QSA and the
hyper-connection ops now live in their own block (11); this block is what they
are built on, and it no longer references them.

Contents:

- The movable-boundary slab and its arena (ggml-cuda-slab.cu,
  ggml-cuda-arena.cu, ggml-cuda-vmm.h, ggml-cuda-moe-cache-hooks.cu): one VMM
  reserve per device split by a movable boundary -- compute below, MoE arena
  above, no HIP call at runtime.  Plus the narrow-band learning, the wide-phase
  auxiliary region, pool-wide routing, and the slab transient absorption.
- The fusion dispatcher (ggml-cuda-try-fuse.cu): the matcher arms moved out of
  ggml-cuda.cu, with every arm implemented inside the kernel TU that owns it.
- The async graph-input ring: batched uploads + lazy done event (PR ggml-org#182), the
  r90 snapshot fix (the scheduler's set_tensor_async path is used for a CPU
  split's output, which the next ubatch rewrites), default-on, and the per-origin
  (per host thread) ordering state of issue ggml-org#201.
- Rope/FWHT fusions: M-ROPE and IMROPE in the RMS_NORM + MUL + ROPE (+ FWHT)
  matcher, BF16 SET_ROWS kept off the 5-op fusion, the q8_0 K/V cache writes
  folded into the rope + FWHT kernel, and the paired GDN q/k norms.
- GDN / attention-gate decode fusions: the BF16 alpha/beta pair with
  softplus(alpha + dt) * a in one mul_mat_vec_f launch (with the r108
  multi-sequence fix and its model-free regression test), the q/k norm pair in
  the direct conv kernel, the attention gate's row-strided view read in place by
  the gate -> Q8_1 kernel, the GDN output norm inside the gate kernel, and
  GGML_CUDA_GDN_TAIL (the sequential tail that writes the rollback snapshots).
- MMB and the HC16 BF16 streams: the per-context MMB state (two contexts
  interleaving must not share the activation cache or the marks), the BF16
  activation copies, DOWN16, and the graph-optimize marking passes.
- The MoE/MMQ decode fusions: mmvq-moe (the dedicated MoE multi-token kernel),
  the gate+up pair fold, silu(gate)*up into the mmq quantize, the dual-output
  matmul, the MoE down fold, and the weighted-down reduction.
- The verify-band arch extension: RDNA3_0 joins RDNA4 in the Q8_1 pre-quantize
  predicate and in the direct GDN conv.
- Meta/scheduler/allocator: the split-state refusals for a straddling split,
  the two-pass graph-optimize protocol (allocs_only / marks_only), graph-memory
  generations so a graph is recaptured when the pool / FA staging / H2D ring
  memory it captured is freed -- including the slab work-boundary shrink of
  issue ggml-org#187 -- the KV prefill pad (LLAMA_KV_N_PAD_PREFILL), and the FA accuracy
  instrument (LLAMA_TEST_OP_NMSE / LLAMA_TEST_SEED).
- bf16 RoPE destinations (TODO ggml-org#83): the missing NORMAL/NEOX bf16
  instantiations, so -ctk bf16 -ctv bf16 prefill does not abort in rope.cu.

Env-read hygiene (no behaviour change): resolve GGML_CUDA_GDN_CHUNKED /
GGML_CUDA_GDN_CHUNKED_BF16 and the GDN_DBG_SKIP_* diagnostics once into values
rather than caching the getenv() pointer: the MSVC CRT returns a buffer that the
next getenv() call overwrites, so a cached pointer is unsafe on Windows.

Build fix: the GGML_CUDA_WORK_ALLOC_DEBUG read in llama_context::graph_reserve
lives in src/ (not linked against the CUDA common.cuh), so it uses a local
static instead of the CUDA helper.

Split note (r109): this commit plus block 11 carries exactly the tree the old
block 10 carried -- the net set is unchanged.  What moved to block 11 is the
qwen4exp model graph, the QSA/indexer ops and their kernels, the
hyper-connection ops, the managed lazy reader and the keys-only indexer cache,
i.e. everything that exists only because of that architecture.  The pieces of
the old block 10 that exist for qwen4exp but are implemented inside a general
kernel TU (the GDN gate/beta fusion, the HC16 MMB BF16 streams, the qwen4exp
weighted-down reduction, the PLE conv fusion) stay here with the TU that owns
them; the HC_BLK16/RES16 marking pass and the indexer relu-sum alloc-dep moved
to block 11 with the matchers they call.

Windows HIP build (issue ggml-org#217): the tables-registration slack guard uses the int64_t min/max helpers
block 09 defines instead of `std::min<int64_t>`/`std::max<int64_t>`.  With HIP on Windows (clang + the
MSVC STL) clang's force-included `cuda_wrappers/algorithm` and the MSVC STL `<utility>` each define an
inline `std::min<long long>` (`int64_t` is `__int64` there, and the `enable_if` that makes clang's
version win overload resolution is not part of the mangled name), so a translation unit that
instantiates both fails to codegen with "definition with same mangled name".  Behaviour is unchanged.

Amended (r132): the block-10 arms of the Q8_1 cache fix that block 08 introduces.  The fused GLU -> Q8_1 site's
key walk stops at the first pointer change (the fused write is keyed by the matmul's src1, and must not take the
root's entry for an offset view), and both of this block's gated-q8_1 launch arms -- the fused norm+gate kernel
and the GLU write -- validate their sources with q8_1_src_range_ok() before launching.  From PR ggml-org#218 (@slavap);
the rule and the validation are recorded with block 08.

Co-authored-by: Slava P. <[email protected]>
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Oct 28, 2026
…rastructure)

The infrastructure half of the old block 10.  qwen4exp, QSA and the
hyper-connection ops now live in their own block (11); this block is what they
are built on, and it no longer references them.

Contents:

- The movable-boundary slab and its arena (ggml-cuda-slab.cu,
  ggml-cuda-arena.cu, ggml-cuda-vmm.h, ggml-cuda-moe-cache-hooks.cu): one VMM
  reserve per device split by a movable boundary -- compute below, MoE arena
  above, no HIP call at runtime.  Plus the narrow-band learning, the wide-phase
  auxiliary region, pool-wide routing, and the slab transient absorption.
- The fusion dispatcher (ggml-cuda-try-fuse.cu): the matcher arms moved out of
  ggml-cuda.cu, with every arm implemented inside the kernel TU that owns it.
- The async graph-input ring: batched uploads + lazy done event (PR ggml-org#182), the
  r90 snapshot fix (the scheduler's set_tensor_async path is used for a CPU
  split's output, which the next ubatch rewrites), default-on, and the per-origin
  (per host thread) ordering state of issue ggml-org#201.
- Rope/FWHT fusions: M-ROPE and IMROPE in the RMS_NORM + MUL + ROPE (+ FWHT)
  matcher, BF16 SET_ROWS kept off the 5-op fusion, the q8_0 K/V cache writes
  folded into the rope + FWHT kernel, and the paired GDN q/k norms.
- GDN / attention-gate decode fusions: the BF16 alpha/beta pair with
  softplus(alpha + dt) * a in one mul_mat_vec_f launch (with the r108
  multi-sequence fix and its model-free regression test), the q/k norm pair in
  the direct conv kernel, the attention gate's row-strided view read in place by
  the gate -> Q8_1 kernel, the GDN output norm inside the gate kernel, and
  GGML_CUDA_GDN_TAIL (the sequential tail that writes the rollback snapshots).
- MMB and the HC16 BF16 streams: the per-context MMB state (two contexts
  interleaving must not share the activation cache or the marks), the BF16
  activation copies, DOWN16, and the graph-optimize marking passes.
- The MoE/MMQ decode fusions: mmvq-moe (the dedicated MoE multi-token kernel),
  the gate+up pair fold, silu(gate)*up into the mmq quantize, the dual-output
  matmul, the MoE down fold, and the weighted-down reduction.
- The verify-band arch extension: RDNA3_0 joins RDNA4 in the Q8_1 pre-quantize
  predicate and in the direct GDN conv.
- Meta/scheduler/allocator: the split-state refusals for a straddling split,
  the two-pass graph-optimize protocol (allocs_only / marks_only), graph-memory
  generations so a graph is recaptured when the pool / FA staging / H2D ring
  memory it captured is freed -- including the slab work-boundary shrink of
  issue ggml-org#187 -- the KV prefill pad (LLAMA_KV_N_PAD_PREFILL), and the FA accuracy
  instrument (LLAMA_TEST_OP_NMSE / LLAMA_TEST_SEED).
- bf16 RoPE destinations (TODO ggml-org#83): the missing NORMAL/NEOX bf16
  instantiations, so -ctk bf16 -ctv bf16 prefill does not abort in rope.cu.

Env-read hygiene (no behaviour change): resolve GGML_CUDA_GDN_CHUNKED /
GGML_CUDA_GDN_CHUNKED_BF16 and the GDN_DBG_SKIP_* diagnostics once into values
rather than caching the getenv() pointer: the MSVC CRT returns a buffer that the
next getenv() call overwrites, so a cached pointer is unsafe on Windows.

Build fix: the GGML_CUDA_WORK_ALLOC_DEBUG read in llama_context::graph_reserve
lives in src/ (not linked against the CUDA common.cuh), so it uses a local
static instead of the CUDA helper.

Split note (r109): this commit plus block 11 carries exactly the tree the old
block 10 carried -- the net set is unchanged.  What moved to block 11 is the
qwen4exp model graph, the QSA/indexer ops and their kernels, the
hyper-connection ops, the managed lazy reader and the keys-only indexer cache,
i.e. everything that exists only because of that architecture.  The pieces of
the old block 10 that exist for qwen4exp but are implemented inside a general
kernel TU (the GDN gate/beta fusion, the HC16 MMB BF16 streams, the qwen4exp
weighted-down reduction, the PLE conv fusion) stay here with the TU that owns
them; the HC_BLK16/RES16 marking pass and the indexer relu-sum alloc-dep moved
to block 11 with the matchers they call.

Windows HIP build (issue ggml-org#217): the tables-registration slack guard uses the int64_t min/max helpers
block 09 defines instead of `std::min<int64_t>`/`std::max<int64_t>`.  With HIP on Windows (clang + the
MSVC STL) clang's force-included `cuda_wrappers/algorithm` and the MSVC STL `<utility>` each define an
inline `std::min<long long>` (`int64_t` is `__int64` there, and the `enable_if` that makes clang's
version win overload resolution is not part of the mangled name), so a translation unit that
instantiates both fails to codegen with "definition with same mangled name".  Behaviour is unchanged.

Amended (r132): the block-10 arms of the Q8_1 cache fix that block 08 introduces.  The fused GLU -> Q8_1 site's
key walk stops at the first pointer change (the fused write is keyed by the matmul's src1, and must not take the
root's entry for an offset view), and both of this block's gated-q8_1 launch arms -- the fused norm+gate kernel
and the GLU write -- validate their sources with q8_1_src_range_ok() before launching.  From PR ggml-org#218 (@slavap);
the rule and the validation are recorded with block 08.

Co-authored-by: Slava P. <[email protected]>
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Oct 29, 2026
…rastructure)

The infrastructure half of the old block 10.  qwen4exp, QSA and the
hyper-connection ops now live in their own block (11); this block is what they
are built on, and it no longer references them.

Contents:

- The movable-boundary slab and its arena (ggml-cuda-slab.cu,
  ggml-cuda-arena.cu, ggml-cuda-vmm.h, ggml-cuda-moe-cache-hooks.cu): one VMM
  reserve per device split by a movable boundary -- compute below, MoE arena
  above, no HIP call at runtime.  Plus the narrow-band learning, the wide-phase
  auxiliary region, pool-wide routing, and the slab transient absorption.
- The fusion dispatcher (ggml-cuda-try-fuse.cu): the matcher arms moved out of
  ggml-cuda.cu, with every arm implemented inside the kernel TU that owns it.
- The async graph-input ring: batched uploads + lazy done event (PR ggml-org#182), the
  r90 snapshot fix (the scheduler's set_tensor_async path is used for a CPU
  split's output, which the next ubatch rewrites), default-on, and the per-origin
  (per host thread) ordering state of issue ggml-org#201.
- Rope/FWHT fusions: M-ROPE and IMROPE in the RMS_NORM + MUL + ROPE (+ FWHT)
  matcher, BF16 SET_ROWS kept off the 5-op fusion, the q8_0 K/V cache writes
  folded into the rope + FWHT kernel, and the paired GDN q/k norms.
- GDN / attention-gate decode fusions: the BF16 alpha/beta pair with
  softplus(alpha + dt) * a in one mul_mat_vec_f launch (with the r108
  multi-sequence fix and its model-free regression test), the q/k norm pair in
  the direct conv kernel, the attention gate's row-strided view read in place by
  the gate -> Q8_1 kernel, the GDN output norm inside the gate kernel, and
  GGML_CUDA_GDN_TAIL (the sequential tail that writes the rollback snapshots).
- MMB and the HC16 BF16 streams: the per-context MMB state (two contexts
  interleaving must not share the activation cache or the marks), the BF16
  activation copies, DOWN16, and the graph-optimize marking passes.
- The MoE/MMQ decode fusions: mmvq-moe (the dedicated MoE multi-token kernel),
  the gate+up pair fold, silu(gate)*up into the mmq quantize, the dual-output
  matmul, the MoE down fold, and the weighted-down reduction.
- The verify-band arch extension: RDNA3_0 joins RDNA4 in the Q8_1 pre-quantize
  predicate and in the direct GDN conv.
- Meta/scheduler/allocator: the split-state refusals for a straddling split,
  the two-pass graph-optimize protocol (allocs_only / marks_only), graph-memory
  generations so a graph is recaptured when the pool / FA staging / H2D ring
  memory it captured is freed -- including the slab work-boundary shrink of
  issue ggml-org#187 -- the KV prefill pad (LLAMA_KV_N_PAD_PREFILL), and the FA accuracy
  instrument (LLAMA_TEST_OP_NMSE / LLAMA_TEST_SEED).
- bf16 RoPE destinations (TODO ggml-org#83): the missing NORMAL/NEOX bf16
  instantiations, so -ctk bf16 -ctv bf16 prefill does not abort in rope.cu.

Env-read hygiene (no behaviour change): resolve GGML_CUDA_GDN_CHUNKED /
GGML_CUDA_GDN_CHUNKED_BF16 and the GDN_DBG_SKIP_* diagnostics once into values
rather than caching the getenv() pointer: the MSVC CRT returns a buffer that the
next getenv() call overwrites, so a cached pointer is unsafe on Windows.

Build fix: the GGML_CUDA_WORK_ALLOC_DEBUG read in llama_context::graph_reserve
lives in src/ (not linked against the CUDA common.cuh), so it uses a local
static instead of the CUDA helper.

Split note (r109): this commit plus block 11 carries exactly the tree the old
block 10 carried -- the net set is unchanged.  What moved to block 11 is the
qwen4exp model graph, the QSA/indexer ops and their kernels, the
hyper-connection ops, the managed lazy reader and the keys-only indexer cache,
i.e. everything that exists only because of that architecture.  The pieces of
the old block 10 that exist for qwen4exp but are implemented inside a general
kernel TU (the GDN gate/beta fusion, the HC16 MMB BF16 streams, the qwen4exp
weighted-down reduction, the PLE conv fusion) stay here with the TU that owns
them; the HC_BLK16/RES16 marking pass and the indexer relu-sum alloc-dep moved
to block 11 with the matchers they call.

Windows HIP build (issue ggml-org#217): the tables-registration slack guard uses the int64_t min/max helpers
block 09 defines instead of `std::min<int64_t>`/`std::max<int64_t>`.  With HIP on Windows (clang + the
MSVC STL) clang's force-included `cuda_wrappers/algorithm` and the MSVC STL `<utility>` each define an
inline `std::min<long long>` (`int64_t` is `__int64` there, and the `enable_if` that makes clang's
version win overload resolution is not part of the mangled name), so a translation unit that
instantiates both fails to codegen with "definition with same mangled name".  Behaviour is unchanged.

Amended (r132): the block-10 arms of the Q8_1 cache fix that block 08 introduces.  The fused GLU -> Q8_1 site's
key walk stops at the first pointer change (the fused write is keyed by the matmul's src1, and must not take the
root's entry for an offset view), and both of this block's gated-q8_1 launch arms -- the fused norm+gate kernel
and the GLU write -- validate their sources with q8_1_src_range_ok() before launching.  From PR ggml-org#218 (@slavap);
the rule and the validation are recorded with block 08.

Co-authored-by: Slava P. <[email protected]>
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Oct 29, 2026
…rastructure)

The infrastructure half of the old block 10.  qwen4exp, QSA and the
hyper-connection ops now live in their own block (11); this block is what they
are built on, and it no longer references them.

Contents:

- The movable-boundary slab and its arena (ggml-cuda-slab.cu,
  ggml-cuda-arena.cu, ggml-cuda-vmm.h, ggml-cuda-moe-cache-hooks.cu): one VMM
  reserve per device split by a movable boundary -- compute below, MoE arena
  above, no HIP call at runtime.  Plus the narrow-band learning, the wide-phase
  auxiliary region, pool-wide routing, and the slab transient absorption.
- The fusion dispatcher (ggml-cuda-try-fuse.cu): the matcher arms moved out of
  ggml-cuda.cu, with every arm implemented inside the kernel TU that owns it.
- The async graph-input ring: batched uploads + lazy done event (PR ggml-org#182), the
  r90 snapshot fix (the scheduler's set_tensor_async path is used for a CPU
  split's output, which the next ubatch rewrites), default-on, and the per-origin
  (per host thread) ordering state of issue ggml-org#201.
- Rope/FWHT fusions: M-ROPE and IMROPE in the RMS_NORM + MUL + ROPE (+ FWHT)
  matcher, BF16 SET_ROWS kept off the 5-op fusion, the q8_0 K/V cache writes
  folded into the rope + FWHT kernel, and the paired GDN q/k norms.
- GDN / attention-gate decode fusions: the BF16 alpha/beta pair with
  softplus(alpha + dt) * a in one mul_mat_vec_f launch (with the r108
  multi-sequence fix and its model-free regression test), the q/k norm pair in
  the direct conv kernel, the attention gate's row-strided view read in place by
  the gate -> Q8_1 kernel, the GDN output norm inside the gate kernel, and
  GGML_CUDA_GDN_TAIL (the sequential tail that writes the rollback snapshots).
- MMB and the HC16 BF16 streams: the per-context MMB state (two contexts
  interleaving must not share the activation cache or the marks), the BF16
  activation copies, DOWN16, and the graph-optimize marking passes.
- The MoE/MMQ decode fusions: mmvq-moe (the dedicated MoE multi-token kernel),
  the gate+up pair fold, silu(gate)*up into the mmq quantize, the dual-output
  matmul, the MoE down fold, and the weighted-down reduction.
- The verify-band arch extension: RDNA3_0 joins RDNA4 in the Q8_1 pre-quantize
  predicate and in the direct GDN conv.
- Meta/scheduler/allocator: the split-state refusals for a straddling split,
  the two-pass graph-optimize protocol (allocs_only / marks_only), graph-memory
  generations so a graph is recaptured when the pool / FA staging / H2D ring
  memory it captured is freed -- including the slab work-boundary shrink of
  issue ggml-org#187 -- the KV prefill pad (LLAMA_KV_N_PAD_PREFILL), and the FA accuracy
  instrument (LLAMA_TEST_OP_NMSE / LLAMA_TEST_SEED).
- bf16 RoPE destinations (TODO ggml-org#83): the missing NORMAL/NEOX bf16
  instantiations, so -ctk bf16 -ctv bf16 prefill does not abort in rope.cu.

Env-read hygiene (no behaviour change): resolve GGML_CUDA_GDN_CHUNKED /
GGML_CUDA_GDN_CHUNKED_BF16 and the GDN_DBG_SKIP_* diagnostics once into values
rather than caching the getenv() pointer: the MSVC CRT returns a buffer that the
next getenv() call overwrites, so a cached pointer is unsafe on Windows.

Build fix: the GGML_CUDA_WORK_ALLOC_DEBUG read in llama_context::graph_reserve
lives in src/ (not linked against the CUDA common.cuh), so it uses a local
static instead of the CUDA helper.

Split note (r109): this commit plus block 11 carries exactly the tree the old
block 10 carried -- the net set is unchanged.  What moved to block 11 is the
qwen4exp model graph, the QSA/indexer ops and their kernels, the
hyper-connection ops, the managed lazy reader and the keys-only indexer cache,
i.e. everything that exists only because of that architecture.  The pieces of
the old block 10 that exist for qwen4exp but are implemented inside a general
kernel TU (the GDN gate/beta fusion, the HC16 MMB BF16 streams, the qwen4exp
weighted-down reduction, the PLE conv fusion) stay here with the TU that owns
them; the HC_BLK16/RES16 marking pass and the indexer relu-sum alloc-dep moved
to block 11 with the matchers they call.

Windows HIP build (issue ggml-org#217): the tables-registration slack guard uses the int64_t min/max helpers
block 09 defines instead of `std::min<int64_t>`/`std::max<int64_t>`.  With HIP on Windows (clang + the
MSVC STL) clang's force-included `cuda_wrappers/algorithm` and the MSVC STL `<utility>` each define an
inline `std::min<long long>` (`int64_t` is `__int64` there, and the `enable_if` that makes clang's
version win overload resolution is not part of the mangled name), so a translation unit that
instantiates both fails to codegen with "definition with same mangled name".  Behaviour is unchanged.

Amended (r132): the block-10 arms of the Q8_1 cache fix that block 08 introduces.  The fused GLU -> Q8_1 site's
key walk stops at the first pointer change (the fused write is keyed by the matmul's src1, and must not take the
root's entry for an offset view), and both of this block's gated-q8_1 launch arms -- the fused norm+gate kernel
and the GLU write -- validate their sources with q8_1_src_range_ok() before launching.  From PR ggml-org#218 (@slavap);
the rule and the validation are recorded with block 08.

Co-authored-by: Slava P. <[email protected]>

Amended (r171): the pair fusion's MMB stand-down asks the dispatch, not the weight type (TODO ggml-org#115).
`mul_mat_q_pair` stood down for any weight type MMB supports, a superset of the shapes MMB actually
claims, so on a shape MMB declines (T < mmb_min_t(), n_used > 64, a K that is not a whole super-block
count, ...) the pair had already stood down and the mmq/mmvq triple took the gate+up pair instead.
It now stands down on the predicate the mmb dispatch uses (both muls claimed), which is a strict
SUPERSET of the fused-GLU predicate, so the priority chain is well defined and cannot preempt an MMB
claim: MMB's fused GLU -> the mmq/mmvq triple -> this pair (the fallback for shapes none of them takes)
-> the two plain muls.  The routed SWIGLU -> MMQ matcher's stand-down is the same exact claim (its GLU
output can be marked BF16-only for an MMB reader).  GGML_PAIR_ROUTED_OFF is the new A/B arm for the
routed half; GGML_PAIR_OFF still means both halves.  Measured neutral: gfx1151 pair vs triple
(LFM2 Q6_K 3379/3399 vs 3348/3407, 35B-A3B Q4_K_M 2304/2312 vs 2296/2313 t/s at pp512, interleaved
r=3, dense MMB path untouched) and byte-identical greedy text on pair == triple == unfused ==
GGML_CUDA_MMB=0 (LFM2 765 chars, 35B-A3B 723 chars); gfx1201 inert (routed = 0 there, so the pair
already won before this change).
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Oct 29, 2026
…rastructure)

The infrastructure half of the old block 10.  qwen4exp, QSA and the
hyper-connection ops now live in their own block (11); this block is what they
are built on, and it no longer references them.

Contents:

- The movable-boundary slab and its arena (ggml-cuda-slab.cu,
  ggml-cuda-arena.cu, ggml-cuda-vmm.h, ggml-cuda-moe-cache-hooks.cu): one VMM
  reserve per device split by a movable boundary -- compute below, MoE arena
  above, no HIP call at runtime.  Plus the narrow-band learning, the wide-phase
  auxiliary region, pool-wide routing, and the slab transient absorption.
- The fusion dispatcher (ggml-cuda-try-fuse.cu): the matcher arms moved out of
  ggml-cuda.cu, with every arm implemented inside the kernel TU that owns it.
- The async graph-input ring: batched uploads + lazy done event (PR ggml-org#182), the
  r90 snapshot fix (the scheduler's set_tensor_async path is used for a CPU
  split's output, which the next ubatch rewrites), default-on, and the per-origin
  (per host thread) ordering state of issue ggml-org#201.
- Rope/FWHT fusions: M-ROPE and IMROPE in the RMS_NORM + MUL + ROPE (+ FWHT)
  matcher, BF16 SET_ROWS kept off the 5-op fusion, the q8_0 K/V cache writes
  folded into the rope + FWHT kernel, and the paired GDN q/k norms.
- GDN / attention-gate decode fusions: the BF16 alpha/beta pair with
  softplus(alpha + dt) * a in one mul_mat_vec_f launch (with the r108
  multi-sequence fix and its model-free regression test), the q/k norm pair in
  the direct conv kernel, the attention gate's row-strided view read in place by
  the gate -> Q8_1 kernel, the GDN output norm inside the gate kernel, and
  GGML_CUDA_GDN_TAIL (the sequential tail that writes the rollback snapshots).
- MMB and the HC16 BF16 streams: the per-context MMB state (two contexts
  interleaving must not share the activation cache or the marks), the BF16
  activation copies, DOWN16, and the graph-optimize marking passes.
- The MoE/MMQ decode fusions: mmvq-moe (the dedicated MoE multi-token kernel),
  the gate+up pair fold, silu(gate)*up into the mmq quantize, the dual-output
  matmul, the MoE down fold, and the weighted-down reduction.
- The verify-band arch extension: RDNA3_0 joins RDNA4 in the Q8_1 pre-quantize
  predicate and in the direct GDN conv.
- Meta/scheduler/allocator: the split-state refusals for a straddling split,
  the two-pass graph-optimize protocol (allocs_only / marks_only), graph-memory
  generations so a graph is recaptured when the pool / FA staging / H2D ring
  memory it captured is freed -- including the slab work-boundary shrink of
  issue ggml-org#187 -- the KV prefill pad (LLAMA_KV_N_PAD_PREFILL), and the FA accuracy
  instrument (LLAMA_TEST_OP_NMSE / LLAMA_TEST_SEED).
- bf16 RoPE destinations (TODO ggml-org#83): the missing NORMAL/NEOX bf16
  instantiations, so -ctk bf16 -ctv bf16 prefill does not abort in rope.cu.

Env-read hygiene (no behaviour change): resolve GGML_CUDA_GDN_CHUNKED /
GGML_CUDA_GDN_CHUNKED_BF16 and the GDN_DBG_SKIP_* diagnostics once into values
rather than caching the getenv() pointer: the MSVC CRT returns a buffer that the
next getenv() call overwrites, so a cached pointer is unsafe on Windows.

Build fix: the GGML_CUDA_WORK_ALLOC_DEBUG read in llama_context::graph_reserve
lives in src/ (not linked against the CUDA common.cuh), so it uses a local
static instead of the CUDA helper.

Split note (r109): this commit plus block 11 carries exactly the tree the old
block 10 carried -- the net set is unchanged.  What moved to block 11 is the
qwen4exp model graph, the QSA/indexer ops and their kernels, the
hyper-connection ops, the managed lazy reader and the keys-only indexer cache,
i.e. everything that exists only because of that architecture.  The pieces of
the old block 10 that exist for qwen4exp but are implemented inside a general
kernel TU (the GDN gate/beta fusion, the HC16 MMB BF16 streams, the qwen4exp
weighted-down reduction, the PLE conv fusion) stay here with the TU that owns
them; the HC_BLK16/RES16 marking pass and the indexer relu-sum alloc-dep moved
to block 11 with the matchers they call.

Windows HIP build (issue ggml-org#217): the tables-registration slack guard uses the int64_t min/max helpers
block 09 defines instead of `std::min<int64_t>`/`std::max<int64_t>`.  With HIP on Windows (clang + the
MSVC STL) clang's force-included `cuda_wrappers/algorithm` and the MSVC STL `<utility>` each define an
inline `std::min<long long>` (`int64_t` is `__int64` there, and the `enable_if` that makes clang's
version win overload resolution is not part of the mangled name), so a translation unit that
instantiates both fails to codegen with "definition with same mangled name".  Behaviour is unchanged.

Amended (r132): the block-10 arms of the Q8_1 cache fix that block 08 introduces.  The fused GLU -> Q8_1 site's
key walk stops at the first pointer change (the fused write is keyed by the matmul's src1, and must not take the
root's entry for an offset view), and both of this block's gated-q8_1 launch arms -- the fused norm+gate kernel
and the GLU write -- validate their sources with q8_1_src_range_ok() before launching.  From PR ggml-org#218 (@slavap);
the rule and the validation are recorded with block 08.

Co-authored-by: Slava P. <[email protected]>

Amended (r171): the pair fusion's MMB stand-down asks the dispatch, not the weight type (TODO ggml-org#115).
`mul_mat_q_pair` stood down for any weight type MMB supports, a superset of the shapes MMB actually
claims, so on a shape MMB declines (T < mmb_min_t(), n_used > 64, a K that is not a whole super-block
count, ...) the pair had already stood down and the mmq/mmvq triple took the gate+up pair instead.
It now stands down on the predicate the mmb dispatch uses (both muls claimed), which is a strict
SUPERSET of the fused-GLU predicate, so the priority chain is well defined and cannot preempt an MMB
claim: MMB's fused GLU -> the mmq/mmvq triple -> this pair (the fallback for shapes none of them takes)
-> the two plain muls.  The routed SWIGLU -> MMQ matcher's stand-down is the same exact claim (its GLU
output can be marked BF16-only for an MMB reader).  GGML_PAIR_ROUTED_OFF is the new A/B arm for the
routed half; GGML_PAIR_OFF still means both halves.  Measured neutral: gfx1151 pair vs triple
(LFM2 Q6_K 3379/3399 vs 3348/3407, 35B-A3B Q4_K_M 2304/2312 vs 2296/2313 t/s at pp512, interleaved
r=3, dense MMB path untouched) and byte-identical greedy text on pair == triple == unfused ==
GGML_CUDA_MMB=0 (LFM2 765 chars, 35B-A3B 723 chars); gfx1201 inert (routed = 0 there, so the pair
already won before this change).
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Oct 29, 2026
…rastructure)

The infrastructure half of the old block 10.  qwen4exp, QSA and the
hyper-connection ops now live in their own block (11); this block is what they
are built on, and it no longer references them.

Contents:

- The movable-boundary slab and its arena (ggml-cuda-slab.cu,
  ggml-cuda-arena.cu, ggml-cuda-vmm.h, ggml-cuda-moe-cache-hooks.cu): one VMM
  reserve per device split by a movable boundary -- compute below, MoE arena
  above, no HIP call at runtime.  Plus the narrow-band learning, the wide-phase
  auxiliary region, pool-wide routing, and the slab transient absorption.
- The fusion dispatcher (ggml-cuda-try-fuse.cu): the matcher arms moved out of
  ggml-cuda.cu, with every arm implemented inside the kernel TU that owns it.
- The async graph-input ring: batched uploads + lazy done event (PR ggml-org#182), the
  r90 snapshot fix (the scheduler's set_tensor_async path is used for a CPU
  split's output, which the next ubatch rewrites), default-on, and the per-origin
  (per host thread) ordering state of issue ggml-org#201.
- Rope/FWHT fusions: M-ROPE and IMROPE in the RMS_NORM + MUL + ROPE (+ FWHT)
  matcher, BF16 SET_ROWS kept off the 5-op fusion, the q8_0 K/V cache writes
  folded into the rope + FWHT kernel, and the paired GDN q/k norms.
- GDN / attention-gate decode fusions: the BF16 alpha/beta pair with
  softplus(alpha + dt) * a in one mul_mat_vec_f launch (with the r108
  multi-sequence fix and its model-free regression test), the q/k norm pair in
  the direct conv kernel, the attention gate's row-strided view read in place by
  the gate -> Q8_1 kernel, the GDN output norm inside the gate kernel, and
  GGML_CUDA_GDN_TAIL (the sequential tail that writes the rollback snapshots).
- MMB and the HC16 BF16 streams: the per-context MMB state (two contexts
  interleaving must not share the activation cache or the marks), the BF16
  activation copies, DOWN16, and the graph-optimize marking passes.
- The MoE/MMQ decode fusions: mmvq-moe (the dedicated MoE multi-token kernel),
  the gate+up pair fold, silu(gate)*up into the mmq quantize, the dual-output
  matmul, the MoE down fold, and the weighted-down reduction.
- The verify-band arch extension: RDNA3_0 joins RDNA4 in the Q8_1 pre-quantize
  predicate and in the direct GDN conv.
- Meta/scheduler/allocator: the split-state refusals for a straddling split,
  the two-pass graph-optimize protocol (allocs_only / marks_only), graph-memory
  generations so a graph is recaptured when the pool / FA staging / H2D ring
  memory it captured is freed -- including the slab work-boundary shrink of
  issue ggml-org#187 -- the KV prefill pad (LLAMA_KV_N_PAD_PREFILL), and the FA accuracy
  instrument (LLAMA_TEST_OP_NMSE / LLAMA_TEST_SEED).
- bf16 RoPE destinations (TODO ggml-org#83): the missing NORMAL/NEOX bf16
  instantiations, so -ctk bf16 -ctv bf16 prefill does not abort in rope.cu.

Env-read hygiene (no behaviour change): resolve GGML_CUDA_GDN_CHUNKED /
GGML_CUDA_GDN_CHUNKED_BF16 and the GDN_DBG_SKIP_* diagnostics once into values
rather than caching the getenv() pointer: the MSVC CRT returns a buffer that the
next getenv() call overwrites, so a cached pointer is unsafe on Windows.

Build fix: the GGML_CUDA_WORK_ALLOC_DEBUG read in llama_context::graph_reserve
lives in src/ (not linked against the CUDA common.cuh), so it uses a local
static instead of the CUDA helper.

Split note (r109): this commit plus block 11 carries exactly the tree the old
block 10 carried -- the net set is unchanged.  What moved to block 11 is the
qwen4exp model graph, the QSA/indexer ops and their kernels, the
hyper-connection ops, the managed lazy reader and the keys-only indexer cache,
i.e. everything that exists only because of that architecture.  The pieces of
the old block 10 that exist for qwen4exp but are implemented inside a general
kernel TU (the GDN gate/beta fusion, the HC16 MMB BF16 streams, the qwen4exp
weighted-down reduction, the PLE conv fusion) stay here with the TU that owns
them; the HC_BLK16/RES16 marking pass and the indexer relu-sum alloc-dep moved
to block 11 with the matchers they call.

Windows HIP build (issue ggml-org#217): the tables-registration slack guard uses the int64_t min/max helpers
block 09 defines instead of `std::min<int64_t>`/`std::max<int64_t>`.  With HIP on Windows (clang + the
MSVC STL) clang's force-included `cuda_wrappers/algorithm` and the MSVC STL `<utility>` each define an
inline `std::min<long long>` (`int64_t` is `__int64` there, and the `enable_if` that makes clang's
version win overload resolution is not part of the mangled name), so a translation unit that
instantiates both fails to codegen with "definition with same mangled name".  Behaviour is unchanged.

Amended (r132): the block-10 arms of the Q8_1 cache fix that block 08 introduces.  The fused GLU -> Q8_1 site's
key walk stops at the first pointer change (the fused write is keyed by the matmul's src1, and must not take the
root's entry for an offset view), and both of this block's gated-q8_1 launch arms -- the fused norm+gate kernel
and the GLU write -- validate their sources with q8_1_src_range_ok() before launching.  From PR ggml-org#218 (@slavap);
the rule and the validation are recorded with block 08.

Co-authored-by: Slava P. <[email protected]>

Amended (r171): the pair fusion's MMB stand-down asks the dispatch, not the weight type (TODO ggml-org#115).
`mul_mat_q_pair` stood down for any weight type MMB supports, a superset of the shapes MMB actually
claims, so on a shape MMB declines (T < mmb_min_t(), n_used > 64, a K that is not a whole super-block
count, ...) the pair had already stood down and the mmq/mmvq triple took the gate+up pair instead.
It now stands down on the predicate the mmb dispatch uses (both muls claimed), which is a strict
SUPERSET of the fused-GLU predicate, so the priority chain is well defined and cannot preempt an MMB
claim: MMB's fused GLU -> the mmq/mmvq triple -> this pair (the fallback for shapes none of them takes)
-> the two plain muls.  The routed SWIGLU -> MMQ matcher's stand-down is the same exact claim (its GLU
output can be marked BF16-only for an MMB reader).  GGML_PAIR_ROUTED_OFF is the new A/B arm for the
routed half; GGML_PAIR_OFF still means both halves.  Measured neutral: gfx1151 pair vs triple
(LFM2 Q6_K 3379/3399 vs 3348/3407, 35B-A3B Q4_K_M 2304/2312 vs 2296/2313 t/s at pp512, interleaved
r=3, dense MMB path untouched) and byte-identical greedy text on pair == triple == unfused ==
GGML_CUDA_MMB=0 (LFM2 765 chars, 35B-A3B 723 chars); gfx1201 inert (routed = 0 there, so the pair
already won before this change).

Fold (r174, PR ggml-org#249, briansp2020): the M-RoPE section power is computed once instead of
once per section arm, in `rope_multi` and in the M-RoPE arm of the fused
`rms_norm_mul_rope_f32`.  Every arm multiplied its position index by the same
`powf(theta_scale, iw/2)`, and adjacent lanes take different arms (`sector % 3`), so the
divergent arms were serialized and `powf` executed once per arm taken.  It is hoisted
before the branch: same input, same value, so the result is bit-identical (the
non-M-RoPE path and the "no arm matched, `theta_base` stays 0" case are untouched).
Measured on this box, gfx1201: `rms_norm_mul_rope_f32` 3.20 -> 2.85 us (__half dst) and
3.06 -> 2.70 us (f32 dst) per launch, greedy text byte-identical on 4B Q8_0 / 27B
UD-Q4_K_XL / 35B-A3B Q4_K_M and the `-ub 1` prefill-logit A/B reads 0.000000 KLD /
100.000 % same-top-p; wall clock is inside the noise on RDNA4 (+0.0 %) and +0.25 to
+0.65 % tg on gfx1100 (7900 XTX: 35B-A3B Q4_K_M 137.6 -> 138.6).  The submission's other
half (a GDN direct conv for 1-token decode) is NOT taken -- it adds a launch per GDN
layer wherever the conv's q/k norm fold is refused and measures -1.1 % on RDNA4 dense
Q8_0, +0.0 % on the submitter's own 7900 XTX arm (WORKLOG 261029.005).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants