Commit 0570c9701 for llama.cpp

commit 0570c970176489f4e89d9168822e1b0516a349d0
Author: Aaron St George <aaronstgeorge@gmail.com>
Date:   Fri Dec 4 09:54:45 2026 -0700

    docs : add kernel routing guidance to the Loom kernel style guide (#33569)

    Assisted-by: Codex

diff --git a/ggml/src/ggml-hrx/dev_doc/kernel-style-guide.md b/ggml/src/ggml-hrx/dev_doc/kernel-style-guide.md
new file mode 100644
index 000000000..191d379f8
--- /dev/null
+++ b/ggml/src/ggml-hrx/dev_doc/kernel-style-guide.md
@@ -0,0 +1,90 @@
+# Loom kernel style guide
+
+## Table of contents
+
+- [Kernel routing](#kernel-routing) covers where to select an implementation and how to keep its Loom launch geometry and device code in agreement.
+
+## Kernel routing
+
+Kernel routing is the choice of which Loom kernel will execute an operation for a given graph, workload and device. That choice can affect how GPU threads share the work, which input representation the kernel reads and how many dispatches the operation requires.
+
+Tuning uses performance measurements to choose parameters for a device and workload. Those parameters often influence routing and can also control how the selected kernel runs.
+
+### Options
+
+For `GGML_OP_MUL_MAT` with one input vector, either C++ or Loom can choose between the paired-row and standard schedules. Both sketches use the same compute motifs.
+
+#### C++ chooses the schedule
+
+C++ checks whether the paired-row schedule is eligible and sets the kernel symbol in the HRX descriptor.
+
+```cpp
+const bool paired = can_use_mul_mat_vec_pair(dst, input_format, token_capacity, publish_format);
+desc.symbol = paired ? "ggml_mul_mat_vec_pair" : "ggml_mul_mat_vec_dot";
+ggml_hrx_kernel * kernel = ggml_hrx_get_kernel(ctx->device, desc);
+```
+
+Each entry sets up its launch and calls its compute motif directly.
+
+```mlir
+kernel.def @ggml_mul_mat_vec_pair(...) {
+  ... // Each 64-thread workgroup handles up to two rows of src0.
+} launch(...) {
+  func.call @ggml_matmul_vector_f32_decode_pair(...)
+  kernel.return
+}
+
+kernel.def @ggml_mul_mat_vec_dot(...) {
+  ... // Launch geometry for the standard schedule.
+} launch(...) {
+  func.call @ggml_matmul_vector_f32_activation_dot(...)
+  kernel.return
+}
+```
+
+#### Loom chooses the schedule
+
+C++ supplies one kernel symbol and passes the information that Loom needs to choose the schedule.
+
+```cpp
+desc.symbol = "ggml_mul_mat_vec";
+desc.config = { ... }; // src0->ne[0], bound input format, token capacity and output mode.
+ggml_hrx_kernel * kernel = ggml_hrx_get_kernel(ctx->device, desc);
+```
+
+Loom checks eligibility in `@use_pair`. The entry uses that choice twice, first to set the launch geometry and then to call the matching compute motif.
+
+```mlir
+func.def pure inline @use_pair() -> (i1) {
+  ... // Read the configuration and check paired-row eligibility.
+}
+
+kernel.def @ggml_mul_mat_vec(...) {
+  %paired = func.call pure @use_pair() : () -> (i1)
+  %groups, %threads = func.call pure @launch_for_schedule(%paired, ...)
+      : (...) -> (index, index)
+  %one = index.constant 1 : index
+  kernel.launch.config workgroups(%groups, %one, %one)
+                       workgroup_size(%threads, %one, %one) : index
+} launch(...) {
+  %paired = func.call pure @use_pair() : () -> (i1)
+  scf.if %paired {
+    func.call @ggml_matmul_vector_f32_decode_pair(...)
+  } else {
+    func.call @ggml_matmul_vector_f32_activation_dot(...)
+  }
+  kernel.return
+}
+```
+
+When the configuration is known during specialization, Loom can remove the unused path. Both options can produce the same device code.
+
+### Decision
+
+**Prefer C++ routing and dispatch a Loom entry that calls the selected implementation directly.** Name the entry for the operation and the specialization C++ selects. Keep launch geometry, device indexing, synchronization and target-specific compute motifs in Loom. Entries can share those motifs. When a GPU needs a different route, select it in C++. When the route needs a GPU-specific instruction sequence, specialize its motif in Loom.
+
+#### Rationale
+
+C++ may need to know the route ahead of time. For example, a split-K implementation that writes one partial output per partition requires the planner to allocate those partials and arrange their reduction.
+
+Calling the selected motif directly can also reduce JIT compilation time. In a `gfx1151` experiment, the median compile time was 157.6 ms with a broad Loom selector and 24.5 ms when the same entry called the selected motif directly. [Routing RFC and compiler measurements](https://github.com/ROCm/ggml-staging-automation/issues/189).