diff --git a/docs/SYCL_PORTING.md b/docs/SYCL_PORTING.md new file mode 100644 index 00000000..9ca9e451 --- /dev/null +++ b/docs/SYCL_PORTING.md @@ -0,0 +1,549 @@ +# Porting radiance to Intel GPUs (SYCL / Level Zero) + +What the core depends on, what the Intel backend has to provide, and the design. The running log +(status, blockers, commands, benchmark runs) is `docs/SYCL_PROGRESS.md`. Written against the tree at +`87ec3c1` (radiance 1.11.0, `RAD_ABI_VERSION` 26). + +--- + +## 1. Where the core depends on HIP + +Reproduce the raw list with: + +```sh +grep -rn -E '\bhip[A-Z][A-Za-z]*\b|hip/hip_|__HIP|RAD_HAVE_HIP|RAD_HIP_FOUND|__global__|__device__|<<<' \ + --include=*.cpp --include=*.h --include=*.hip --include=*.cc --include=*.c \ + --include=CMakeLists.txt --include=*.cmake . | grep -v -E '^\./(vendor|libr4d|build|tests/r4d_emu)/' +``` + +288 lines outside `libr4d/` and `vendor/`; 47 of them are comments that only name a HIP call. The +substance, classified: + +### 1.1 Already behind the device ABI (`abi/rad_device.h` + the `DeviceBackend` vtable) + +The device layer is a vtable (`core/device/device.h:178`, `struct DeviceBackend`), chosen once in +`select_backend()` (`core/device/dispatch.cpp:87`). Every `rad_dev_*` / `rad_stream_*` / +`rad_event_*` / `rad_memcpy*` call above the device layer goes through it. Today it has three +implementations: + +| backend | file | runtime calls | +|---|---|---| +| host | `core/device/host.cpp` | none (worker threads, `malloc`) | +| HIP | `core/device/hip.cpp` | `hipMalloc`, `hipFree`, `hipSetDevice`, `hipGetDevice(Count)`, `hipGetDeviceProperties`, `hipDeviceGetAttribute`, `hipMemGetInfo`, `hipDeviceGetPCIBusId`, `hipDeviceCanAccessPeer`, `hipDeviceEnablePeerAccess`, `hipPointerGetAttributes`, `hipHostGetDevicePointer`, `hipRuntimeGetVersion` | +| AQL (the one a card actually runs) | `core/device/aql.cpp`, `aql_code.cpp`, `aql_blit.hip` | HIP for allocation, properties, peer access, IPC, code registration; HSA for everything on the queues: `hsa_queue_*`, `hsa_signal_*`, `hsa_amd_memory_pool_*`, `hsa_amd_vmem_*` (elastic memory), `hsa_executable_*` / `hsa_code_object_reader_*` (it loads plugins' code objects itself), `hsa_amd_profiling_*`, `hsa_amd_memory_lock_to_pool` (pinning) | + +What the AQL backend implements that matters for a port (from `aql.cpp`'s header and +`device.h`): + +- **Streams** are HSA queues the engine owns; every kernel, copy, fill and fence is an AQL packet it + writes (6 ns per dispatch versus 0.5-1.3 us through `hipLaunchKernel`, ~1600 dispatches per rank + per decode step). +- **Kernel-argument staging**: a ring of 1 KiB slots written by the host, in VRAM through the BAR + when the BAR spans VRAM, in pinned host memory otherwise (`aql_force_host_kargs`, `device.h:476`), + with a system-scope acquire at least once per half lap. +- **Resizable BAR handling** is exactly that placement choice. Nothing else in the core reads the + BAR size. +- **Events**: barrier packets with agent-scope (`RAD_EVENT_LOCAL`) or system-scope release; + `RAD_EVENT_HOST_WAIT` adds an interrupt signal. +- **Graphs**: "tapes" (`DeviceBackend::tape_*`, `device.h:227`) record a pass's packets and replay + them. They are optional; null means every pass is issued. +- **Elastic memory** (`vmem_*`, `device.h:271`) shares VRAM between KV and experts. Optional; null + sizes pools once at startup. +- **Pinned memory**: `RAD_MEM_HOST_PINNED` / `RAD_MEM_HOST_MAPPED`; the host arena locks file + mappings to the pool (`hsa_amd_memory_lock_to_pool`). +- **P2P / IPC**: `enable_peer`, `peer_access`; IPC lives in libr4d's collectives, not the core. +- **DMA lane, link holds, rides, gates, expert prefetch** (`memcpy_list_async`, `link_hold`, + `xp_*`, `stream_gate`): all optional, null on a backend without them. + +### 1.2 The core calls HIP directly + +These are the places a second device backend has to touch. None is a HIP call from generic engine +code: each is a device-code launcher or a build switch. + +| site | what | classification / what the Intel backend needs | +|---|---|---| +| `core/sched/advance.cpp:18` + `core/sched/advance.hip` | the per-step advance kernel (one thread per batch row), launched through `hipLaunchKernel` | **core device kernel**, every decode step. The row logic is shared host/device code in `core/sched/advance_impl.h` (`RAD_ADV_FN`, `:10`, is `__host__ __device__` under `__HIPCC__`). Needs a SYCL launcher calling the same `adv_row` | +| `core/runtime/wtab.cpp:18` + `core/runtime/wtab.hip` | the weight-table patch kernel (one thread per pointer write) | **core device kernel**; needs a SYCL launcher (19 lines of HIP) | +| `core/runtime/xprefetch.cpp:11` + `core/runtime/xprefetch.hip` | MoE expert prefetch (router logits, plan) | **core device kernel**, MoE only. Gated by `rad_xp_supported`; the Intel backend reports 0 and the prefetch is off (supported configuration) | +| `core/device/aql_blit.hip` | copy / fill kernels behind the AQL backend's memcpy / memset | AQL-only; SYCL has `queue::memcpy` / `memset` / `fill` | +| `core/CMakeLists.txt:73` | the engine exports `hipLaunchKernel`, `hipMemcpyAsync`, ..., `__hipRegisterFatBinary` so plugins' HIP launches bind to the AQL backend | **the plugin launch contract**: a plugin launches device work with HIP calls the engine serves (`abi/rad_types.h:325`, `docs/PLUGIN.md` §5). A SYCL plugin needs its own hand-off (§4.2 below) | +| `core/device/dispatch.cpp:60, 88`; `core/device/device.h:465` | backend selection and AQL-only hooks under `RAD_HAVE_HIP` | selection gains a SYCL branch | +| `core/engine_diag.cpp:60` | `device_build` fact for the startup report | becomes "HIP or SYCL" | +| `abi/rad_philox.h:16`, `abi/rad_yarn.h:16`, `core/sched/advance_impl.h:10` | `__host__ __device__` qualifiers under `__HIPCC__` | header-only device code; under SYCL device compilation the qualifier is empty (SYCL device code is plain C++), so these need an `#elif defined(SYCL_LANGUAGE_VERSION)` that defines the macro to `inline` | +| `CMakeLists.txt:17-77, 132-156, 229-236, 297` | `RAD_WITH_HIP`, `RAD_HIP_FOUND`, `RAD_GPU_TARGETS`, `enable_language(HIP)`, `RAD_HAVE_HIP` on `rad_abi`, `add_subdirectory(libr4d)` | build integration; `RAD_SYCL` mirrors it | +| `cmake/RadAddPlugin.cmake:68-121` | `HIP_SOURCES`, `rad_hipify`, per-source `-cuid` | gains `SYCL_SOURCES` | +| `tests/CMakeLists.txt:236, 313, 328, 342, 523, 551, 579`; `tests/plugin_test.cpp:93`; `tests/host_kargs_main.h:21` | card tests (`device_test`, `mem_test`, `place_test`, `runtime_test` on a card, `r4d_selftest`, `kbench` gpu label, ops_doc and oot over libr4d) | the `sycl` label and its tests | +| `tools/vmemprobe.cpp` | a HIP diagnostic tool | AMD-only; not ported | + +Comments only (no code dependency): `core/engine_bringup.cpp:3656`, `core/mem/pools.cpp:221`, +`core/format/radfile.h:82`, `core/runtime/ctx.h:12`, `core/device/host.cpp:267, 445, 496`, +`libavx/avx_ngram.cpp:8`, `abi/rad_types.h:327`. + +--- + +## 2. How the host backend avoids HIP (the template) + +- `select_backend()` returns `host_backend()` when the build has no HIP + (`core/device/dispatch.cpp:100`). `RadDeviceProps::is_host_backend = 1`, arch `"host"`. +- **Streams** are queues run by worker threads; **device memory** is host memory; events are + counters (`core/device/host.cpp`). +- **Kernels**: libref and libavx declare `RAD_DOMAIN_HOST` rows and are plain shared objects built by + `rad_add_plugin` with `SOURCES` only. They ignore the `RadStream` they are handed + (`abi/rad_types.h:330`). +- **Core device kernels** branch on `device_is_host()` *before* the `RAD_HAVE_HIP` branch: drain the + stream, then run the shared row function on the host (`core/sched/advance.cpp:13`, + `core/runtime/wtab.cpp`). Without HIP the device branch returns `RAD_E_UNSUPPORTED`. +- **Optional features** (tapes, vmem, DMA lane, prefetch, gates) are null, which the engine treats as + a supported configuration. +- **Build**: `RAD_WITH_HIP=OFF` (or AUTO without `hipcc`) leaves `RAD_HIP_FOUND` off; libr4d is not + added, `RAD_HAVE_HIP` is not defined, the HIP-only tests are not registered. + +A SYCL backend follows the same shape: a fourth `DeviceBackend`, a third branch in the core +kernels' launchers, its own kernel library, its optional features null until measured worth it. + +--- + +## 3. The op vocabulary + +`docs/OPS.md` documents 238 ops: **205 that libref implements** (the oracle for `rad-kbench` and for +the Intel kernels' tests) and **33 device-only** ops that only libr4d declares (no host fallback and +no oracle; libr4d's own `r4d_selftest` patterns are their checks). Appendix A is the full table, +generated by `scripts/sycl/op_inventory.sh` (libref's schemas through `rad-schemas`; libr4d's 407 +`kKernels` rows parsed from `libr4d/r4d_rows.cpp` by `scripts/sycl/r4d_rows.py`, since a build +without HIP has no `libr4d.so`; the architectures column is a grep of `arch/` and over-counts). + +How libr4d implements the ops a dense LLM needs (from the rows' prose and `libr4d/README.md`): + +- **GEMM**: one geometry per entry point. bf16 (`gemm_bf16_nt_m16`/`m64` skinny with split-K and + 16x16x16 WMMA, `gemm_bf16_nt_tiled` for M > 64), each quantised format its own family + (`gemm_fp8a8_*`, `gemm_w4a8_*`, `gemm_mxfp4a8_*`, `gemm_i8a8_*`, ...), a skinny decode kernel + (M <= 16..128) and a tiled prefill kernel per format; weights pre-permuted into WMMA fragment + order by a `relayout` hook at load. Deterministic reductions: the split-K slices are summed in a + fixed order, and "BYTE-IDENTICAL" siblings are stated in the rows. +- **Attention**: paged (block 16) prefill and split-KV decode, one instantiation per + (head_dim, gqa, kv dtype): `attn_decode_h128_gqa{1,2,4,8}_{bf16,fp8}kv`, + `attn_window_h_gqa_` templates, fp8 KV with per-(seq, head) descales. +- **Norms and elementwise**: one workgroup a row (`rmsnorm_quant_fp8` "two passes, the second L1-hot"), + fused quantisers (`gated_quant_fp8`, `quant_act_fp8`) writing E4M3 with an f32 scale per + (row, 128 columns). +- **Vocabulary edge**: `logits_gemm_{bf16,fp8,i8}` writing f32 logits, `embed_lookup_bf16`. +- **Sampling**: f32 stages (`r4d_sample_stages_f32.hip`), `sample_argmax_f32`. + +### 3.1 The minimal set: MiniCPM5-2B + +No MiniCPM5 container is in the model library (`SYCL_PROGRESS.md`, blocker 1), so the set below was +measured on the test suite's synthetic llama (`tests/tiny_model.h`, the same `llama_dense_fp8` +graph: `rad-convert` with no recipe for bf16, the e2e test's `llama.recipe` for the block-fp8 trunk) +with `radiance --model .rad --debug-graph` on the host backend. The geometry differs (the tiny +model is head_dim 64, gqa 2, n_embd 128; MiniCPM5 is head_dim 128, 16 q over 2 kv heads = gqa 8, +n_embd 2048, ffn 6144, vocab 130560), the op list does not. + +**MiniCPM5-2B bf16: 13 model ops.** (`docs/PLUGIN.md` §10 also says 13.) + +| op | params as declared | count per layer / model | dtype | +|---|---|---|---| +| `embed_lookup` | n_embd, n_vocab | 1 / model | bf16 table | +| `rmsnorm_quant_fp8` | n, eps, group=128 | 2 / layer | bf16 in; writes bf16 `h` plus E4M3 `h.q` and f32 scale `h.s` | +| `gemm_nt` | N, K | 4 / layer (qkv, o, gate_up, down) | bf16 | +| `rope` | head_dim, n_head, n_head_kv, theta, mode=neox, rotary_dim | 1 / layer | bf16 | +| `cast` | n, from=bf16, to=bf16 | 1 / layer | copy-out of q | +| `kv_store` | head_dim, n_head_kv, block_size=16 | 1 / layer | bf16 KV, or `fp8_e4m3` at `--kv-cache-dtype fp8` | +| `attn_paged` | head_dim, gqa, causal=1, window=0, block_size=16 | 1 / layer | q bf16; kv bf16 or `fp8_e4m3` | +| `quant_act_fp8` | n, group=128 | 1 / layer | bf16 -> E4M3 + f32 scale | +| `gated_quant_fp8` | n, group=128, act=silu | 1 / layer | SwiGLU, bf16 out plus E4M3 | +| `add` | n | residual | bf16 | +| `rmsnorm` | n, eps | final norm | bf16 | +| `gather_rows` | | last-token rows for the head | | +| `logits_gemm` | n_vocab, n_embd | 1 / model | bf16 head, **f32 logits** | + +**Sampler: 13 ops** (`docs/PLUGIN.md` says 11; the measured list is): `sample_penalties`, +`sample_dry`, `sample_ngram_ban`, `sample_temp`, `sample_mask`, `sample_topk`, `sample_argmax`, +`sample_topp`, `sample_minp`, `sample_typical`, `sample_xtc`, `sample_pick`, `sample_logprobs`. +Greedy decoding uses `sample_argmax`; the token-for-token comparison in Milestone A runs greedy. + +**MiniCPM5-2B fp8** (block-fp8 trunk, 128x128 scales): `gemm_nt` becomes `gemm_nt_q` at +`dtype=fp8a8 group=128`, plus **`gemm_nt_q_gated`** (gate_up GEMM with the SiLU-gate fused, +`act=silu`) as the alternative the fp8 path declares. Everything else is the same list. With an fp8 +or int8 lm_head (`llama_fp8head`, `llama_i8head`), `logits_gemm` stays one op and selects the kernel +by the head's encoding. + +**The 4-bit paths**, measured the same way on the tiny llama: int4 (compressed-tensors, asymmetric) +issues `gemm_nt_q` at `w4a16_asym` and `w4a8i8_asym` plus `quant_act_i8g`; MXFP4 issues `gemm_nt_q` +at `mxfp4a8 group=32`. The real 27B / 31B containers add their architectures' own ops (gated delta +net for qwen35, Gemma's norms and soft-caps); those are listed when a container is available. + +**Speculative decoding** (DSpark, 5 layers, block 7) adds the draft block's ops: fp8a8 GEMMs at +128x128 blocks and the `u2` 2-bit draft head; to be measured on a container that carries a drafter. + +--- + +## 4. Design + +The brief's default design, with what the code showed. Each decision is also in +`SYCL_PROGRESS.md` under Decisions. + +### 4.1 Device runtime: a fourth `DeviceBackend`, not a new abstraction + +The brief proposes a device-runtime interface if the core calls HIP directly. It does not: the +`DeviceBackend` vtable already *is* that interface (§1.1), with every call the brief lists +(allocate/free device and pinned memory, copies, streams, events, device info), and the HIP/AQL +implementations are already behind it. So no wrapper is introduced and the HIP path is not touched. + +`core/device/sycl.cpp`, compiled only when `RAD_SYCL=ON`, defines `sycl_backend_if_present()`: + +| vtable entry | SYCL / Level Zero | +|---|---| +| `count`, `set`, `props` | GPU devices of the Level Zero platform; `props.arch` from `ext::oneapi::experimental::info::device::architecture` (`"intel_gpu_bmg_g31"`); `n_cu` = `max_compute_units` (160), `warp_size` = 16 (the sub-group the kernels use), `lds_bytes` = `local_mem_size`, `vram_free` from `ext::intel::info::device::free_memory` | +| `alloc` | `RAD_MEM_DEVICE` -> `malloc_device`; `HOST_PINNED` and `HOST_MAPPED` -> `malloc_host` (device-reachable, same address both sides, so `host_ptr`/`device_ptr` are identity); `HOST` -> plain `malloc` | +| streams | one in-order `sycl::queue` per stream on one shared `sycl::context`; `high_priority` -> `ext::oneapi::property::queue::priority_high` | +| events | `queue::ext_oneapi_submit_barrier()` returns the record; `event_wait` = `ext_oneapi_submit_barrier({e})` on the waiting queue (no host sync); `query` / `sync` on the event; `elapsed_ms` from profiling info (queues created with `enable_profiling`; its cost to be measured, and dropped if it shows) | +| copies, fills | `queue::memcpy`, `memset`; 2-D copy as `ext_oneapi_copy2d` or a row loop; ranges and lists as one small kernel / a loop of copies | +| `host_wrote` | nothing: USM host allocations are coherent for the device at submission | +| `vram_used` | `ext::intel::info::device::free_memory` | +| `pci_address` | `ext::intel::info::device::pci_address` | +| `runtime_version` | the SYCL platform version string | +| tapes | null at first; later `sycl_ext_oneapi_graph` (Phase 4, if submission overhead dominates decode) | +| vmem, DMA lane, link holds, rides, prefetch, gates | null (each a supported configuration) | + +`select_backend()` tries, in order: AQL (if built with HIP and an AMD card is visible), SYCL (if built +with SYCL and a Level Zero GPU is visible), host. `RADIANCE_DEVICE_BACKEND=sycl|aql|host` (new) +chooses explicitly in a build with both. + +### 4.2 Plugin launches: a SYCL stream contract + +On a card the engine serves plugins' `hipLaunchKernel`. SYCL has no launch symbol to interpose, so +a SYCL kernel library needs the queue itself. Under the SYCL backend a `RadStream` points to + +```c +/* abi/rad_sycl.h (new, C-compatible) */ +#define RAD_SYCL_STREAM_MAGIC 0x4C435953u /* "SYCL" */ +typedef struct RadSyclStream { + uint32_t magic; /* RAD_SYCL_STREAM_MAGIC */ + uint32_t version; /* RAD_SYCL_STREAM_VERSION, bumped on any change of this struct */ + void* queue; /* sycl::queue*, in-order, owned by the engine */ +} RadSyclStream; +``` + +with an inline C++ helper `rad_sycl_queue(RadStream)` that checks the magic and version and returns +the `sycl::queue&` (or null, which the launch turns into `RAD_E_DEVICE`). The engine and every SYCL +plugin load the same `libsycl.so`, so the object is valid across the boundary. + +Why a new header with its own version rather than a bump of `RAD_ABI_VERSION`: nothing an existing +plugin compiles against changes shape (`rad_types.h` keeps `typedef void* RadStream`; only its +comment gains the SYCL case), so a bump would force every out-of-tree plugin to rebuild for no +reason. A SYCL plugin checks `version` at each launch's first call and refuses by name on a +mismatch, which is the same guarantee for the only plugins that read the struct. + +What a SYCL launch may do mirrors `docs/PLUGIN.md` §5: submit to that queue only; no `wait`, no +allocation (scratch from the `scratch` hook), no host tasks. + +### 4.3 The kernel library: `libxe2/` + +Built by `rad_add_plugin(libxe2 kernels SYCL_SOURCES ...)`, AOT for `bmg-g31` (`-fsycl-targets= +intel_gpu_bmg_g31`), `build_target "intel_gpu_bmg_g31"`. Device rows only; kernels launch on the +stream's queue with sub-group 16. A library with no code for the card is left out of selection, as +for AMD (`docs/PLUGIN.md` §10): the SYCL backend's `code_runs` answers from the plugin's +`build_target` against `props.arch`, so libr4d's rows can never be selected on the B65 in a build +with both (and libxe2's never on an AMD card). + +Built and loaded like every bundled plugin, so `tests/oot_plugins.sh` rebuilds it out of tree when +`icpx` is available. + +### 4.4 No silent CPU fallback + +On a device backend the engine places an op that has weights and no device kernel on the host and +logs it once at INFO ("host-only ops: ... Not a hole", `core/engine_bringup.cpp:146`). That is a +CPU route for a GPU op, which the brief forbids. **On the SYCL backend that message becomes a fatal +startup error naming the ops**, unless `--debug-accept-host-ops` (new, debug-only) is given; ops +without weights already fail as holes. `--debug-graph` shows the resolution either way. + +### 4.5 Build integration + +- `RAD_SYCL` (`OFF | ON | AUTO`, default **OFF**), `build.sh --sycl`, a `sycl` preset, a `sycl` ctest + label (card tests, `SKIP_RETURN_CODE 77` without a Level Zero GPU, like `gpu`). +- **Compiler.** CMake has no SYCL language, and `-fsycl` sources need `icpx`. With `RAD_SYCL=ON` the + whole build uses `icpx` as `CMAKE_CXX_COMPILER` and only SYCL sources get `-fsycl` (with + `-fsycl` on the link of targets holding them). Configure refuses `RAD_SYCL=ON` with another C++ + compiler, naming the fix (`-DCMAKE_CXX_COMPILER=icpx`, which `build.sh --sycl` passes). + **`icpx` defaults to `-fp-model=fast`**; the SYCL build passes `-ffp-model=precise` to host code so + libref and libavx compute what they compute under GCC, and the host tier is run in the SYCL build + too to show it. The default build (GCC, `RAD_SYCL=OFF`) is unchanged. + *Fallback* if host code under `icpx` does not reproduce the GCC results: build the SYCL pieces + (`core/device/sycl.cpp` as a small C-ABI shared library, `libxe2`) as a separate CMake project + with `icpx` through `ExternalProject`, leaving the main build on GCC. +- **HIP and SYCL in one build**: allowed in principle (HIP is its own CMake language), but untestable + here (no ROCm). The first version refuses `RAD_SYCL=ON` together with a found HIP at configure + time with a clear message; lifting that is a later change made on a machine with both. + +### 4.6 Core device kernels under SYCL + +`advance` and `wtab` get SYCL launchers (`core/sched/advance_sycl.cpp`, `core/runtime/wtab_sycl.cpp`, +`-fsycl`) as a third branch after `device_is_host()`. `RAD_ADV_FN`, `RAD_PHILOX_HD`, `RAD_YARN_HD` +gain a SYCL case so the shared row code compiles for the device. `xprefetch` stays off +(`rad_xp_supported` = 0). + +### 4.7 Single card + +`--tp > 1` on the SYCL backend stops at startup: "the Intel backend serves one card (--tp 1); tensor +parallelism needs the all-reduce kernels it does not have". No collective rows are declared. + +### 4.8 Numerics + +- fp8 is OCP E4M3 everywhere the engine reads it (`docs/PLUGIN.md` §10). XMX has no fp8 input on this + part (`SYCL_PROGRESS.md`, Phase 0), so fp8 and MXFP4 weights are widened to bf16 in registers; + int8 uses s8 DPAS. +- Tolerances come from the matching libr4d rows and `rad-kbench`'s checks for that op and dtype, + never looser. +- Reductions: the first kernels use a fixed reduction order per output so results do not depend on + work-group scheduling. Where that differs from libref's order, greedy outputs may diverge after a + near-tie, and Milestone A then states a measured KL bound (the engine has a KL tool: `core/kld.cpp`). + +--- + +## Appendix A. Every op + +Generated by `scripts/sycl/op_inventory.sh`; regenerate after a vocabulary change. Columns: whether +libref implements the op (the oracle), libr4d's kernels for it, the dtype prose of up to three of +those rows, and the architecture plugins whose source names it (a grep: `common` is +`arch/common`, the shared blocks every LLM uses). + +| op | libref | libr4d kernels | libr4d dtypes (first three rows' prose) | architectures naming it | +|---|---|---|---|---| +| `act_mul` | yes | act_mul_bf16 | bf16 in and out, f32 arithmetic, libm silu / erf / tanh | common, embgemma2, gemma4, minimaxmusic3, sdxl | +| `add` | yes | add_bf16, add_f32 | bf16 in and out, fp32 arithmetic; f32 in and out | anima, breeze, common, embgemma2, flux3, gemma3, gemma4, gemma4_bf16, krea2, lfm2_bf16, ltx2, minimaxh3, minimaxmusic3, qwen3asr_bf16, qwenimage21, sdxl, unlimitedocr_bf16 | +| `add_rmsnorm` | no | add_rmsnorm_bf16 | bf16 x / a / y, f32 or bf16 gain, fp32 reduction; byte-identical to add_bf16 + rmsnorm_bf16 | common | +| `all_gather` | yes | ar_gather_2rank, ar_gather_3rank, ar_gather_4rank, ar_gather_8rank | any payload -- the bytes are moved, never summed, so the (u32 id, f32 logit) pairs the vocab-parallel sampler gathers survive intact | common, krea2, minimaxh3, qwenimage21 | +| `all_reduce` | yes | ar_oneshot_2rank_exact, ar_oneshot_2rank_exact_lane, ar_oneshot_2rank_wht6, ar_oneshot_2rank_wht6_lane, ar_oneshot_3rank_exact, ar_oneshot_4rank_exact, ar_oneshot_8rank_exact, ar_twoshot_3rank_exact, ar_twoshot_3rank_ti8, ar_twoshot_4rank_exact, ar_twoshot_4rank_exact_lane, ar_twoshot_4rank_ti8, ar_twoshot_4rank_ti8_lane, ar_twoshot_8rank_exact | bf16 / fp16 / fp32 payload, fp32 accumulate in ascending rank order, bit-identical across ranks; bf16 / fp16 / fp32 payload, fp32 accumulate in ascending rank order, bit-identical across ranks and to ar_oneshot_3rank_exact; bf16 / fp16 / fp32 payload, fp32 accumulate in ascending rank order, bit-identical across ranks and to the wide row | common, flux3, gemma3, gemma4, gemma4_bf16, krea2, llama_fp8, minimaxh3, minimaxmusic3, qwen35_bf16, qwen35_fp8, qwen3asr_bf16, qwen4exp_fp8, qwenimage21, unlimitedocr_bf16 | +| `ar_gather_hc_write` | no | ar_gather_hc_write, ar_gather_hc_write_4rank | bf16 throughout; the gather's sums and narrows are moe_gather's (round-to-nearest-even, the shared arm's product rounded before the add), the reduction and the write ar_hc_write's on the same wire -- byte-identical to the three kernels it replaces; bf16 throughout; the gather's sums and narrows are moe_gather's (round-to-nearest-even, the shared arm's product rounded before the add), the sum in fp32 in ascending rank order and rounded to bf16 exactly as the four-rank exact all-reduce stores it, and the write in hc_write's arithmetic over that bf16 value -- byte-identical to the three kernels it replaces | common | +| `ar_hc_write` | no | ar_hc_write, ar_hc_write_4rank | bf16 throughout; the sum in fp32 in ascending rank order and rounded to bf16 exactly as the four-rank exact all-reduce stores it, and the write in hc_write's arithmetic over that bf16 value -- byte-identical to the pair it replaces; bf16 throughout; the sum rounded to bf16 exactly as the standalone all-reduce of the SAME wire stores it and the write in hc_write's arithmetic over that bf16 value -- byte-identical to the pair it replaces | common | +| `ar_ln_had_quant_i8` | no | ar_ln_had_quant_i8 | bf16 in, int8 out with an f32 per-row scale carrying 1/sqrt(had), optional bf16 out | -- | +| `ar_rmsnorm_had_quant_i8g` | no | ar_rmsnorm_had_quant_i8g | bf16 in, int8 out with an f32 scale per (row, 128 columns) and an optional bf16 out of the UNROTATED norm output; x and the residual are ar_rmsnorm_quant_fp8's bytes, and the codes rmsnorm_had_quant_i8g's over the same norm output | common, qwen35_fp8 | +| `ar_rmsnorm_post_quant_fp8` | no | ar_rmsnorm_post_quant_fp8 | bf16 in, E4M3 out with an f32 scale per (row, 128 columns); x receives the reduced sum | gemma3 | +| `ar_rmsnorm_quant_fp8` | no | ar_rmsnorm_quant_fp8 | bf16 in, E4M3 out with an f32 scale per (row, 128 columns) and an optional bf16 out; codes taken over the BF16-ROUNDED norm output, and the reduced sum rounded to bf16 exactly as the standalone all-reduce of the SAME wire stores it -- byte-identical to the pair it replaces | common | +| `ar_rmsnorm_quant_i8` | no | ar_rmsnorm_quant_i8, ar_rmsnorm_quant_i8_4rank | bf16 in, int8 out in the w4a8 GEMM's fragment order with an f32 per-row scale; the reduced sum rounded to bf16 as the standalone exact all-reduce stores it | gemma3, gemma4_bf16 | +| `attn_cross` | yes | attn_cross_h128_bf16, attn_cross_h64_bf16 | bf16 query / key / value / out, bf16 operands, fp32 accumulate | anima, flux3, ltx2, sdxl | +| `attn_dense` | yes | attn_dense_h1152_bf16, attn_dense_h128_bf16, attn_dense_h256_gqa2_bf16, attn_dense_h256_gqa4_bf16, attn_dense_h256_gqa8_bf16, attn_dense_h384_bf16, attn_dense_h512_bf16, attn_dense_h512_gqa2_bf16, attn_dense_h512_gqa4_bf16, attn_dense_h512_gqa8_bf16, attn_dense_h64_bf16, attn_dense_h768_bf16, attn_dense_small_h256_bf16, attn_vit_h72_bf16 | bf16 query / key / value / out, bf16 operands, fp32 accumulate; bf16 query / key / value / out, f16 operands, fp32 accumulate; bf16 query / key / value / out, fp32 scores and accumulate | anima, breeze, common, embgemma2, flux3, krea2, lfm2_bf16, ltx2, minimaxh3, minimaxmusic3, qwen3asr_bf16, qwenimage21, sdxl | +| `attn_local_rel` | yes | attn_local_rel_bf16 | bf16 q / k / v / relk / out, bf16 or f32 per-dim scale, f32 softmax | embgemma2 | +| `attn_na3d` | yes | attn_na3d_h64 | bf16 or f32 q / k / v / out, fp32 accumulate | ltx2 | +| `attn_paged` | yes | attn_decode_h128_gqa1_bf16kv, attn_decode_h128_gqa1_fp8kv, attn_decode_h128_gqa2_bf16kv, attn_decode_h128_gqa2_fp8kv, attn_decode_h128_gqa2w_bf16kv, attn_decode_h128_gqa2w_fp8kv, attn_decode_h128_gqa4_bf16kv, attn_decode_h128_gqa4_fp8kv, attn_decode_h128_gqa8_bf16kv, attn_decode_h128_gqa8_fp8kv, attn_decode_h256_gqa12_bf16kv, attn_decode_h256_gqa12_fp8kv, attn_decode_h256_gqa12_fp8v4, attn_decode_h256_gqa12_k6v4, attn_decode_h256_gqa2_bf16kv, attn_decode_h256_gqa2_fp8kv, attn_decode_h256_gqa4_bf16kv, attn_decode_h256_gqa4_fp8kv, attn_decode_h256_gqa6_bf16kv, attn_decode_h256_gqa6_bs4_bf16kv, attn_decode_h256_gqa6_bs4_fp8kv, attn_decode_h256_gqa6_bs4_fp8v4, attn_decode_h256_gqa6_bs4_k6v4, attn_decode_h256_gqa6_fp8kv, attn_decode_h256_gqa6_fp8v4, attn_decode_h256_gqa6_k6v4, attn_decode_h256_gqa8_bf16kv, attn_decode_h256_gqa8_fp8kv, attn_prefill_h128_gqa1_bf16kv, attn_prefill_h128_gqa1_fp8kv, attn_prefill_h128_gqa2_bf16kv, attn_prefill_h128_gqa2_fp8kv, attn_prefill_h128_gqa2w_bf16kv, attn_prefill_h128_gqa2w_fp8kv, attn_prefill_h128_gqa8_bf16kv, attn_prefill_h128_gqa8_fp8kv, attn_prefill_h256_gqa12_bf16kv, attn_prefill_h256_gqa12_fp8kv, attn_prefill_h256_gqa12_fp8v4, attn_prefill_h256_gqa12_k6v4, attn_prefill_h256_gqa2_bf16kv, attn_prefill_h256_gqa2_fp8kv, attn_prefill_h256_gqa4_bf16kv, attn_prefill_h256_gqa4_fp8kv, attn_prefill_h256_gqa6_bf16kv, attn_prefill_h256_gqa6_bs4_bf16kv, attn_prefill_h256_gqa6_bs4_fp8kv, attn_prefill_h256_gqa6_bs4_fp8v4, attn_prefill_h256_gqa6_bs4_k6v4, attn_prefill_h256_gqa6_fp8kv, attn_prefill_h256_gqa6_fp8kv_pv8, attn_prefill_h256_gqa6_fp8kv_qk8, attn_prefill_h256_gqa6_fp8kv_qk8pv8, attn_prefill_h256_gqa6_fp8v4, attn_prefill_h256_gqa6_fp8v4_pv8, attn_prefill_h256_gqa6_fp8v4_qk8, attn_prefill_h256_gqa6_fp8v4_qk8pv8, attn_prefill_h256_gqa6_k6v4, attn_prefill_h256_gqa6_k6v4_pv8, attn_prefill_h256_gqa6_k6v4_qk8, attn_prefill_h256_gqa6_k6v4_qk8pv8, attn_prefill_h256_gqa8_bf16kv, attn_prefill_h256_gqa8_fp8kv, attn_prefill_h64_gqa4_bf16kv, attn_prefill_h64_gqa4_fp8kv, attn_window_h_gqa_ | bf16 query and probabilities rounded to e4m3, fp8-e4m3 kv cache with per-(seq,head) descales, bf16 out; bf16 query and probabilities rounded to e4m3, fp8_v4 kv cache (E4M3 K, int4 V in groups of 32 with f16 scales), K and V as e4m3 in LDS, bf16 out; bf16 query and probabilities rounded to e4m3, k6_v4 kv cache (int6 K, int4 V, each in groups of 32 with f16 scales), K and V as e4m3 in LDS, bf16 out | breeze, common, gemma3, gemma4, gemma4_bf16, lfm2_bf16, minimaxmusic3, unlimitedocr_bf16 | +| `attn_paged_gate_quant` | no | attn_decode_gq_h256_gqa12_bf16kv, attn_decode_gq_h256_gqa12_fp8kv, attn_decode_gq_h256_gqa12_fp8v4, attn_decode_gq_h256_gqa12_k6v4, attn_decode_gq_h256_gqa6_bs4_bf16kv, attn_decode_gq_h256_gqa6_bs4_fp8kv, attn_decode_gq_h256_gqa6_bs4_fp8v4, attn_decode_gq_h256_gqa6_bs4_k6v4 | bf16 query, bf16 kv cache, bf16 gated out, E4M3 codes with an f32 scale per 128 columns; bf16 query, fp8-e4m3 kv cache, bf16 gated out, E4M3 codes with an f32 scale per 128 columns; bf16 query, fp8_v4 kv cache (E4M3 K, int4 V in groups of 32 with f16 scales), bf16 gated out, E4M3 codes with an f32 scale per 128 columns | common | +| `attn_paged_qrow` | no | attn_qrow_decode_h256_gqa2_bf16kv, attn_qrow_decode_h256_gqa2_fp8kv, attn_qrow_h128_gqa8_bf16kv, attn_qrow_h128_gqa8_fp8kv, attn_qrow_h_gqa_ | bf16 query (any row pitch), kv cache, bf16 out, f32 partials; bf16 query (any row pitch, a multiple of 4), bf16 kv cache, bf16 out, f16 partials; bf16 query (any row pitch, a multiple of 4), fp8-e4m3 kv cache with per-(seq,head) descales, bf16 out, f16 partials | common, gemma4, gemma4_bf16, unlimitedocr_bf16 | +| `attn_prefix_self` | yes | attn_prefix_self_h128_bf16 | bf16 q/k/v/out and cache, bf16 operands, fp32 accumulate; or i8 Q.K codes, i32 accumulate; or E4M3 V codes and P, fp32 accumulate | breeze, minimaxh3, minimaxmusic3, qwenimage21 | +| `attn_vsa` | yes | attn_vsa_h128_bf16 | bf16 q / k / v / coarse / gate / out, i32 segs / geom / sel; bf16 operands, fp32 accumulate; or i8 Q.K codes, i32 accumulate; or E4M3 V codes and P, fp32 accumulate | minimaxh3 | +| `bwe_up` | yes | bwe_up | bf16 or f32 operands | ltx2 | +| `cast` | yes | cast_bf16_bf16, cast_bf16_f16, cast_bf16_f32, cast_f32_bf16, cast_f32_f32 | bf16 in, bf16 out, byte-for-byte; bf16 in, f16 out, rounded to nearest even (a value past f16's range becomes an infinity); bf16 in, f32 out, exact | breeze, common, embgemma2, gemma3, gemma4, gemma4_bf16, glm5next, llama_fp8, ltx2, minimaxh3, minimaxmusic3, qwen35_fp8, sdxl, unlimitedocr_bf16 | +| `causal_conv1d` | yes | causal_conv1d_bf16 | bf16 activations, weights and conv state; i32 cu, slots, has_init and num_accepted | lfm2_bf16 | +| `cfg_topk_sample` | yes | cfg_topk_sample | f32 or bf16 logits, i32 picks | breeze, minimaxmusic3 | +| `chan_affine` | yes | chan_affine_bf16, chan_affine_f32 | bf16; f32 | anima, flux3, krea2, minimaxh3, qwenimage21, sdxl | +| `chan_split` | yes | chan_split_bf16 | bf16 | minimaxmusic3 | +| `chan_stats` | yes | chan_stats_bf16, chan_stats_f32 | bf16; f32 x and y, bf16 or f32 statistics, every step rounded to f32 | flux3, ltx2 | +| `clamp` | yes | clamp_bf16 | bf16 in and out | embgemma2, minimaxh3 | +| `conv1d` | yes | conv1d_bf16, conv1d_f32 | bf16 rows, weight, bias and residual, fp32 accumulate, one rounding; act none, tanh or clamp; f32 rows, weight, bias and residual, f32 accumulate; act none, tanh or clamp | breeze, ltx2, minimaxh3, minimaxmusic3 | +| `conv1d_dw` | yes | conv1d_dw_bf16 | bf16 x / w / y, i32 cu_seqlens, f32 accumulate | breeze, embgemma2 | +| `conv2d` | yes | conv2d_bf16 | bf16 x / w / y, i32 cu_seqlens and mask, f32 accumulate | embgemma2, qwen3asr_bf16 | +| `conv2d_nhwc` | yes | conv2d_nhwc_bf16 | bf16 image, weight and bias, fp32 accumulate, one rounding | common, ltx2, sdxl | +| `conv2d_unfold` | yes | conv2d_unfold_bf16 | bf16 x / y, i32 cu_seqlens and mask | common, qwen3asr_bf16 | +| `conv3d_ndhwc` | yes | conv3d_ndhwc_bf16 | bf16 voxels, weight and residual, bf16 or f32 bias, fp32 accumulate | ltx2, minimaxh3 | +| `conv_t1d` | yes | conv_t1d_bf16, conv_t1d_f32 | bf16 rows, weight and bias, fp32 accumulate, one rounding; f32 rows, weight and bias, f32 accumulate | breeze, ltx2, minimaxh3, minimaxmusic3 | +| `cu_repeat` | yes | cu_repeat | i32 | anima, breeze, flux3, krea2, minimaxh3, minimaxmusic3, sdxl | +| `d2s3d` | yes | d2s3d | bf16 or f32 x and y, i32 geom | ltx2 | +| `d2s_add` | yes | d2s_add_bf16 | bf16 | anima, common, flux3, krea2 | +| `dequant` | yes | -- | | -- | +| `dequant_w4` | no | dequant_w4_bf16 | 4-bit in with an f16 scale and a zero in the dword's high half, bf16 out | -- | +| `dflash_conv` | yes | dflash_conv_t2_g16_bf16 | bf16 x / delta / base / out, fp32 accumulate | common | +| `dflash_select` | yes | dflash_select_bf16 | i32 candidate ids, f32 unary logits, bf16 hp and both codebooks, i32 tokens out | common | +| `dsa_pool` | yes | dsa_pool_fp8 | bf16 keys/gates, f32 position bias; FP8 codes and f32 scale | common | +| `dsa_query` | yes | dsa_query_fp8 | bf16 input, E4M3 codes and power-of-two f32 scale | common | +| `dsa_score` | yes | dsa_score_fp8 | E4M3 codes, f32 scales and gates | common | +| `embed_lookup` | yes | embed_lookup_bf16 | i32 tokens, bf16 table and output | anima, breeze, common, embgemma2, flux3, gemma3, gemma4, gemma4_bf16, glm5next, krea2, lfm2_bf16, llama_fp8, ltx2, minimaxh3, minimaxmusic3, qwen35_bf16, qwen35_fp8, qwen3asr_bf16, qwen4exp_fp8, qwenimage21, sdxl, unlimitedocr_bf16 | +| `embed_lookup_q` | yes | embed_lookup_q_bf16 | i32 tokens, an E4M3 table with a bf16 or f32 scale or a plain bf16 one, bf16 output | common | +| `end_status` | yes | end_status | i32 | breeze, minimaxmusic3 | +| `expert_scale` | no | expert_scale_bf16 | i32 ids, bf16 table and weights | gemma4 | +| `fill` | yes | fill_bf16, fill_f32 | bf16 out; the value rounds to nearest even once; f32 out, the value exactly | anima, breeze, common, flux3, krea2, ltx2, sdxl | +| `flow_euler` | yes | flow_euler_bf16 | bf16 | anima, flux3, krea2, minimaxmusic3, qwenimage21 | +| `flow_renoise` | yes | flow_renoise_f32 | f32 latent and sigma, u32 seed words | ltx2, minimaxh3 | +| `flow_x0_step` | yes | flow_x0_step_f32 | f32 state, f32 or bf16 velocity | minimaxh3 | +| `fourier_embed` | yes | fourier_embed_bf16 | f32 time and w, bf16 out | minimaxmusic3 | +| `frame_mix_store` | yes | frame_mix_store_bf16 | bf16 planes and rows, f32 logits and scale | minimaxmusic3 | +| `frame_store` | yes | frame_store | i32 | breeze | +| `gate_add` | yes | gate_add_bf16 | bf16 | anima, flux3, krea2, ltx2, qwenimage21 | +| `gate_quant_fp8` | no | gate_quant_fp8 | bf16 in, E4M3 out with an f32 scale per (row, 128 columns) and an optional bf16 out; the codes are taken over the BF16-ROUNDED product | common, krea2 | +| `gated_had_quant_fp8` | no | gated_had_quant_fp8 | bf16 in, E4M3 out with an f32 scale per (row, 128 columns) and an optional bf16 out that receives the UNROTATED product; the codes are taken over the rotated BF16-ROUNDED product, and the residual factor of 128 is folded into the stored weight scale at convert, not here | common | +| `gated_had_quant_i8` | yes | gated_had_quant_i8 | bf16 in, int8 out with an f32 per-row scale carrying 1/sqrt(had) | -- | +| `gated_had_quant_i8g` | no | gated_had_quant_i8g | bf16 in, int8 out with an f32 scale per (row, 128 columns) and an optional bf16 out that receives the UNROTATED product; the codes are taken over the rotated BF16-ROUNDED product, byte-identical to the product + had_quant_act_i8g | common, qwen35_fp8 | +| `gated_quant_fp8` | yes | gated_quant_fp8 | bf16 in, E4M3 out with an f32 scale per (row, 128 columns) and an optional bf16 out; the codes are taken over the BF16-ROUNDED product | common | +| `gather_rows` | yes | gather_rows_bf16, gather_rows_u8 | i32 indices, bf16 rows; i32 indices, u8 rows | breeze, common, flux3, gemma3, gemma4, gemma4_bf16, glm5next, krea2, lfm2_bf16, llama_fp8, minimaxmusic3, qwen35_bf16, qwen35_fp8, qwen3asr_bf16, qwen4exp_fp8, qwenimage21, sdxl, unlimitedocr_bf16 | +| `gather_rows2` | yes | gather_rows2_bf16 | bf16 | anima, krea2 | +| `gdn_chunk_scan` | yes | gdn_chunk_scan_k128_v128_c64_bf16 | bf16 q/k/v/A, fp32 gate/beta, bf16 out; the state cache is f32 or f16 | common | +| `gdn_conv_prep` | yes | gdn_conv_prep_w4_h128_bf16 | bf16 x / weights / conv state / q,k,v out, fp32 a,b and gate/beta out | common | +| `gdn_conv_recurrent_update` | yes | gdn_conv_recurrent_update_k128_v128_bf16 | bf16 x / conv weights / conv state / a,b / out; the state cache is f32 or f16. Byte-identical to gdn_conv_update followed by gdn_recurrent_update | common | +| `gdn_conv_update` | yes | gdn_conv_update_w4_h128_bf16 | bf16 x / weights / conv state / q,k,v out | common | +| `gdn_gated_norm_had_quant_i8` | no | gdn_gated_norm_had_quant_i8 | bf16 x and z, f32 norm weight, int8 out with an f32 per-row scale carrying 1/sqrt(had) | -- | +| `gdn_gated_rmsnorm` | yes | gdn_gated_rmsnorm_h128_bf16 | bf16 x / z / out, fp32 weight | common | +| `gdn_kkt_solve` | yes | gdn_kkt_solve_k128_c64_bf16 | bf16 k and A out, fp32 beta / gate / gram / inverse | common | +| `gdn_recurrent_update` | yes | gdn_recurrent_update_k128_v128_bf16_fp32state | bf16 q/k/v and out, fp32 a,b; the state cache is f32 or f16 and the operand says which | common | +| `gelu` | yes | gelu_bf16 | bf16 in and out, fp32 arithmetic | anima, breeze, common, lfm2_bf16, qwen3asr_bf16, sdxl | +| `gelu_mul` | yes | gelu_mul_bf16 | bf16 in and out, fp32 arithmetic | breeze, gemma3, gemma4_bf16, ltx2 | +| `gelu_mul_quant_i8` | no | gelu_mul_quant_i8 | bf16 gate_up in, int8 out in the w4a8 GEMM's fragment order with an f32 per-row scale, optional bf16 out; the codes taken over the bf16-rounded product | gemma3, gemma4_bf16 | +| `gelu_quick` | yes | gelu_quick_bf16 | bf16 or f32 in and out (one dtype), f32 arithmetic | sdxl | +| `gelu_tanh` | yes | gelu_tanh_bf16 | bf16 | common, embgemma2, gemma4, krea2, lfm2_bf16, ltx2, qwenimage21 | +| `gemm_nt` | yes | gemm_bf16_nt_m16, gemm_bf16_nt_m64, gemm_bf16_nt_tiled | bf16 A / W / C, fp32 accumulate, deterministic reduction; bf16 A / W / C, fp32 accumulate. BYTE-IDENTICAL to gemm_bf16_nt_m64: the same WMMA sequence a tile and the same split count, the slices summed in the same order from 0.f | anima, breeze, common, embgemma2, flux3, gemma3, gemma4, gemma4_bf16, lfm2_bf16, ltx2, minimaxmusic3, qwen3asr_bf16, qwenimage21, sdxl, unlimitedocr_bf16 | +| `gemm_nt_bias` | yes | gemm_bf16_nt_bias_tiled, gemm_f32_nt_bias | bf16 A / W / C / res, bf16 or f32 bias, fp32 accumulate, three RNE roundings in the store; f32 A / W, f32 or bf16 bias, f32 accumulate, C f32 or bf16 with res in C's dtype (each epilogue step rounded to C's dtype) | anima, breeze, common, embgemma2, krea2, lfm2_bf16, ltx2, minimaxh3, minimaxmusic3, qwen3asr_bf16, sdxl | +| `gemm_nt_f32` | yes | gemm_nt_f32_bf16 | bf16 input, f32 weights and output | common | +| `gemm_nt_q` | yes | gemm_fp8a16_nt_m1, gemm_fp8a8_f32scale, gemm_fp8a8_nt_m16, gemm_fp8a8_tiled, gemm_i8a8_nt_m16, gemm_i8a8_tiled, gemm_mxfp4a8_decode, gemm_mxfp4a8_nt_m64, gemm_mxfp4a8_tiled, gemm_w2a8_nt, gemm_w4a16_asym_nt_m64, gemm_w4a16_nt_m64, gemm_w4a8_nt_m64, gemm_w4a8_prefill, gemm_w4a8_tiled, gemm_w4a8i8_tiled, gemm_w5a16_nt_m64, gemm_w5a8i8_tiled, gemm_w8a16_nt_m64, gemm_w8a8_nt_m64, gemm_w8a8_tiled | E4M3 A with an f32 scale per (row, 128 K), E4M3 W with a bf16 scale per 128x128 tile, bf16 C. The split-K finisher sums its planes in INDEX order, so a run repeats exactly; but the split COUNT is chosen from M, so the same row computed at M=1 and at M=8 is not bit-identical. That is why a speculative decode diverges from a non-speculative one on a near-tie. NOTHING PINS IT TODAY: --deterministic reaches placement and the sampler, not this kernel; E4M3 A with an f32 scale per (row, 128 K), E4M3 W with a bf16 scale per 128x128 tile, bf16 C; each 128-K block's product folded into the f32 accumulator with one fma; E4M3 codes, F32 scales, BF16 output | common, gemma3, gemma4_bf16 | +| `gemm_nt_q_bias` | yes | gemm_fp8a8_bias_nt_m16 | E4M3 A with an f32 scale per (row, 128 K), E4M3 W with a bf16 scale per 128x128 tile, a bf16 bias added to the f32 accumulator before its one rounding, bf16 C | minimaxh3 | +| `gemm_nt_q_gated` | yes | gemm_fp8a8_gated_nt_m16 | E4M3 A with an f32 scale per (row, 128 K), E4M3 W with a bf16 scale per 128x128 tile, and the QUANTISER's outputs: E4M3 codes, an f32 scale per (row, 128 columns) and an optional bf16 product. Byte-identical to gemm_nt_q followed by gated_quant_fp8 -- the accumulator is rounded to bf16 before the gate and the multiply, and the amax is an fmaxf reduction, which is exact and order-free however it is regrouped across the waves | common | +| `givens_dense_quant` | yes | givens_dense_quant | bf16 in, int8 or E4M3 out in PLAIN ROW-MAJOR order, parts side by side, with an f32 scale (amax/127 or amax/448) per (row, part, 128 columns); f16 matrices and f32 channel scales | common | +| `givens_rotate` | yes | givens_rotate | bf16 in, f16 out, parts side by side; the tables are the weight's int32 pairs, f32 angles and f32 channel scales | common | +| `gram_accum` | yes | gram_accum, gram_accum_bf16 | E4M3 plus an f32 scale per (row, 128 columns) in; an f32 [n][n] accumulator in and out; bf16 in, no scale operand; an f32 [n][n] accumulator in and out | common, gemma3 | +| `grid_embed` | yes | grid_embed_bf16 | bf16 x, bf16 or f32 table, i32 coord, f32 taps | common | +| `grid_embed_aa` | yes | grid_embed_aa_bf16 | bf16 x, bf16 or f32 table, i32 coord, f32 taps | lfm2_bf16 | +| `grid_pos3` | yes | grid_pos3 | f32 | minimaxh3 | +| `group_norm` | yes | group_norm | bf16 or f32 rows, bf16 or f32 gain, bias and modulation, f32 statistics | common, ltx2, minimaxh3, sdxl | +| `had_quant_act_fp8` | yes | had_quant_act_fp8 | bf16 in, E4M3 out in PLAIN ROW-MAJOR order with an f32 scale per (row, 128 columns); the sqrt(128) the unnormalised transform leaves behind is NOT undone here, because = 128 and the whole factor is folded into the stored weight scale at convert | common | +| `had_quant_act_i8` | yes | had_quant_act_i8 | bf16 in, int8 out with an f32 per-row scale that also carries the 1/sqrt(had) normalisation | -- | +| `had_quant_act_i8g` | yes | had_quant_act_i8g | bf16 in, int8 out in PLAIN ROW-MAJOR order with an f32 scale of amax/127 per (row, 128 columns); the factor of 128 of the unnormalised transform is left to the weight's stored scale (dtype i8a8h) | common | +| `hc_enter` | yes | hc_enter_bf16 | bf16 in and out | common | +| `hc_project` | yes | hc_project_bf16 | bf16 stream, f32 direction, i32 switch | common | +| `hc_read` | yes | hc_read_bf16, hc_read_e4m3 | bf16 stream and mixing matrices, f32 gain, bf16 out, E4M3 + f32 scale for the optional twin; bf16 stream, E4M3 mixing matrices with f32 scales in each row (128-column groups for mix_down, a quarter row for mix_up), f32 gain, bf16 out, E4M3 + f32 scale for the twin | common | +| `hc_write` | yes | hc_write_bf16 | bf16 throughout | common | +| `head_gate` | yes | head_gate | bf16 logits, bf16 or f32 x | ltx2 | +| `im2col_nhwc` | yes | im2col_nhwc_bf16 | bf16 in and out, copied bit for bit | sdxl | +| `int_affine` | yes | int_affine | i32 | ltx2 | +| `interleave2` | yes | interleave2_bf16 | bf16 or f32 in, f32 out | minimaxh3, minimaxmusic3 | +| `iota` | yes | iota | i32 | anima, breeze, common, flux3, krea2, ltx2, minimaxh3, minimaxmusic3, sdxl | +| `join_add_scale` | no | join_add_scale_bf16 | bf16 activations, f32 gains, bf16 scalar | gemma4 | +| `kd_input` | yes | kd_input_bf16 | f32 lanes, bf16 y | sdxl | +| `kd_step` | yes | kd_step_bf16 | bf16 model output, f32 lanes, history and preview, f32 arithmetic | sdxl | +| `kda_update` | yes | kda_update_k128_v128_bf16 | bf16 activations, f32 gates and state | common | +| `kv_len_trim` | no | kv_len_trim | int32 in, int32 out, clamped at zero | gemma4_bf16 | +| `kv_store` | yes | kv_store_bf16, kv_store_fp8, kv_store_fp8v4, kv_store_k6v4 | bf16 k / v / cache, i32 slot mapping; bf16 k / v, E4M3 K and int4 V in groups of 32 with f16 scales, i32 slot mapping; bf16 k / v, fp8-e4m3 cache, i32 slot mapping, scalar k_scale / v_scale descales | breeze, common, gemma3, gemma4, gemma4_bf16, lfm2_bf16, minimaxmusic3, qwenimage21, unlimitedocr_bf16 | +| `l2norm_chan` | yes | l2norm_chan_bf16 | bf16 | common | +| `lane_gather` | yes | lane_gather_w32 | bf16 | anima, flux3, krea2, minimaxh3, qwenimage21 | +| `lane_store` | yes | lane_store_w32 | bf16 | anima, flux3, krea2, qwenimage21, sdxl | +| `layernorm` | yes | layernorm_bf16 | bf16 or f32 x, bf16 y, f32 or bf16 gain and bias | breeze, common, embgemma2, lfm2_bf16, minimaxh3, minimaxmusic3, qwen3asr_bf16, sdxl | +| `ln_mod` | yes | ln_mod_bf16 | bf16 | qwenimage21 | +| `ln_mod_quant_fp8` | yes | ln_mod_quant_fp8_bf16 | bf16 in, E4M3 codes with f32 scales out | qwenimage21 | +| `logit_rerank` | yes | logit_rerank, logit_rerank_i8 | bf16 in, f32 values + i32 ids out, ties to the lower id | common | +| `logit_softcap` | yes | logit_softcap_bf16, logit_softcap_f32 | bf16 in and out, fp32 arithmetic; f32 in and out — the 1.3.0 sampling chain carries the logits as f32 from the gemm | gemma4, gemma4_bf16 | +| `logits_gemm` | yes | logits_gemm_bf16, logits_gemm_bf16_cols, logits_gemm_fp8, logits_gemm_i8 | bf16 x and lm_head, F32 LOGITS OUT, fp32 accumulate; bf16 x and lm_head, F32 LOGITS OUT, fp32 accumulate. BYTE-IDENTICAL to logits_gemm_bf16; bf16 x, E4M3 head with a bf16 scale per 128x128 tile stored PER ROW, F32 LOGITS OUT, fp32 accumulate | breeze, common, gemma3, gemma4, gemma4_bf16, glm5next, lfm2_bf16, llama_fp8, qwen35_bf16, qwen35_fp8, qwen3asr_bf16, qwen4exp_fp8, unlimitedocr_bf16 | +| `lora_expand` | yes | lora_expand_scalar, lora_expand_tiled | f32 t and scale; bf16 lora_b; i32 slot; bf16 / f16 / f32 y | -- | +| `lora_expand_mm` | yes | lora_expand_mm_wmma | f32 t and scale; bf16 lora_b; i32 slot; bf16 / f16 / f32 y | -- | +| `lora_shrink` | yes | lora_shrink_scalar, lora_shrink_wmma, lora_shrink_wmma_q | bf16 / f16 / f32 a, or fp8_e4m3 / fp8_e5m2 / i8 a with its f32 scale stream; bf16 lora_a; i32 slot; f32 t; bf16 a; bf16 lora_a; i32 slot; f32 t; fp8_e4m3 / fp8_e5m2 / i8 a with its f32 scale stream; bf16 lora_a; i32 slot; f32 t | -- | +| `ltx_guide` | yes | ltx_guide | f32 latent, bf16 or f32 velocities | ltx2 | +| `mhc_contract` | yes | mhc_contract_bf16 | bf16 | glm5next | +| `mhc_post` | yes | mhc_post_bf16 | bf16 activation, f32 coefficients | common | +| `mhc_pre` | yes | mhc_pre_bf16 | bf16 activation, f32 weights and coefficients | common | +| `mhc_pre_finish` | yes | mhc_pre_finish_bf16 | bf16 activation, f32 partials and coefficients | common | +| `mhc_pre_partial` | yes | mhc_pre_partial_bf16 | bf16 activation, f32 weights and partials | common | +| `mix_rows` | yes | mix_rows_bf16 | bf16 | krea2 | +| `mla_attn` | yes | mla_attn_bf16, mla_attn_matrix_bf16 | bf16 Q/cache/output, f32 softmax and partials; bf16 operands; FP32 probabilities via high/low BF16 | common | +| `mla_project` | yes | mla_project_bf16 | bf16 input, weights and output; fp32 arithmetic | common | +| `moe_gather` | yes | moe_gather_bf16 | bf16 in and out | common, gemma4 | +| `moe_gather_inv` | no | moe_gather_inv_bf16 | bf16 in and out, f32 or bf16 routing weights | common | +| `moe_gemm` | yes | moe_gemm_bf16 | bf16 activation, bf16 weight as the checkpoint stores it ([N, K] row-major, no layout hook), f32 accumulate over the whole of K, bf16 out rounded to nearest-even | common, gemma4 | +| `moe_gemm_q` | yes | moe_gemm_fp8a8, moe_gemm_fp8a8_f32scale, moe_gemm_mxfp4a8, moe_gemm_w4a8 | E2M1 and E8M0 weights, E4M3 activations and f32 scales, bf16 output; E4M3 activation with an f32 scale per 128 of K, E4M3 weight with a bf16 scale per 128x128 tile, bf16 out; E4M3 activation with an f32 scale per 128 of K, symmetric int4 weight (codes -8..7) with a bf16 scale per row per 128 of K, bf16 out; dtype w4a8h is the same plane with a 128-wide Hadamard rotation along K baked into both, and pairs with had_quant_act_fp8; dtype w4nla8h is w4a8h with the codes indexing libquant's w4nl levels, and w4nl64a8h / w4nl32a8h are w4nla8h with an E4M3 scale per row per 64 / 32 of K under a fixed 2^-13; w5nl64a8h is w4nl64a8h with five-bit codes into libquant's w5nl levels, a sign bit plane after each row's nibbles | common, gemma4 | +| `moe_gemm_q_mod4` | yes | moe_gemm_fp8a8_mod4, moe_gemm_w4a8_mod4 | as moe_gemm_fp8a8; as moe_gemm_w4a8 | common | +| `moe_scatter` | yes | moe_scatter_i32 | i32 throughout | common, gemma4 | +| `moe_scatter_inv` | no | moe_scatter_inv_i32 | i32 throughout | common | +| `mtp_enter` | yes | mtp_enter_bf16, mtp_enter_e4m3 | bf16 activations and fc, f32 gains; bf16 activations, E4M3 fc rows with f32 128-column group scales in each row's tail, f32 gains | common | +| `mul` | yes | mul_bf16 | bf16 in and out, fp32 arithmetic | anima, common, flux3, gemma4, krea2, lfm2_bf16, ltx2, minimaxh3, qwenimage21, sdxl | +| `mul_weight` | yes | mul_weight_bf16, mul_weight_f32 | bf16 in and out, a bf16 or f32 weight, fp32 arithmetic; bf16 or f32 in, a bf16 or f32 weight, f32 out, the product rounded once | breeze, common, embgemma2, gemma4, minimaxh3 | +| `ngram_ids` | yes | ngram_ids_i32 | i32 tokens and state, i64 multipliers and per-head vocab sizes and offsets | common | +| `norm_add_norm` | no | norm_add_norm_bf16 | bf16 activations, f32 gains | gemma4 | +| `norm_add_norm_route` | no | norm_add_norm_route_bf16 | bf16 activations, f32 gains; E4M3 codes with an f32 scale a 128 columns | gemma4 | +| `pair_argmax` | yes | pair_argmax_f32 | f32 pairs (int32 id bits, f32 value), i32 idx, f32 val | common | +| `patch_fold` | yes | patch_fold_f32 | bf16 or f32 voxels, f32 patch rows | minimaxh3 | +| `patch_unfold` | yes | patch_unfold_f32 | f32 | minimaxh3 | +| `pix_patch` | yes | pix_patch | bf16 or f32 x and y | ltx2 | +| `pixel_norm` | yes | pixel_norm | bf16 or f32 x and y | ltx2 | +| `ple_conv` | yes | ple_conv_bf16 | bf16 activations, weights and conv state; i32 cu, slots, has_init and num_accepted | common | +| `ple_gate` | yes | ple_gate_bf16 | bf16 activations, F32 norm gains | common | +| `pool_rows` | yes | pool_rows_bf16 | bf16 in and out, f32 sum, two roundings | common | +| `prefetch` | no | prefetch | any | common, gemma4_bf16 | +| `qk_norm_rope` | yes | qk_norm_rope_bf16 | bf16 qkv, bf16 or f32 gains, i32 positions, f32 arithmetic, the norm rounded before the rotation | anima, breeze, common, embgemma2, flux3, gemma4, krea2, ltx2, minimaxh3, qwenimage21 | +| `qk_norm_rope_gate` | no | qk_norm_rope_gate | bf16 in and out; the norm output is rounded to bf16 before the rotation, as the unfused reference does by storing it | common | +| `qk_norm_rope_gate_kv_store` | no | qk_norm_rope_gate_kv_store_bf16, qk_norm_rope_gate_kv_store_fp8, qk_norm_rope_gate_kv_store_fp8v4, qk_norm_rope_gate_kv_store_k6v4 | bf16 in and out, E4M3 K and int4 V with f16 scales, i32 slot mapping; bf16 in and out, bf16 cache, i32 slot mapping; bf16 in and out, fp8-e4m3 cache, i32 slot mapping, scalar k_scale / v_scale descales | common | +| `qkv_norm_rope` | no | qkv_norm_rope_bf16, qkv_norm_rope_h128_bf16 | bf16 q/k/v and gains (or f32 gains), i32 positions; byte-identical to [rmsnorm_p +] rmsnorm x2 + rope x2, each norm taken by its standalone kernel's partition; bf16 q/k/v and gains (or f32 gains), i32 positions; byte-identical to rmsnorm_p + rmsnorm x2 + rope x2, each norm taken by its standalone kernel's partition | gemma3, gemma4_bf16 | +| `qkv_norm_rope_kv_store` | no | qkv_norm_rope_kv_store_bf16, qkv_norm_rope_kv_store_fp8 | bf16 q/k/v and gains (or f32 gains), i32 positions and slots, fp8-e4m3 cache, scalar k_scale / v_scale descales; byte-identical to qkv_norm_rope + kv_store_fp8; bf16 q/k/v, gains, cache; i32 positions and slots; byte-identical to qkv_norm_rope + kv_store_bf16 | common, gemma4_bf16 | +| `qsa_block_key` | yes | qsa_block_key_bf16 | bf16 keys in with an f32 gain; bf16 out, one row a BLOCK. The mean is rounded to bf16 before the norm, which is the reference's order and not the convenient one | common | +| `qsa_score` | yes | qsa_score_bf16 | bf16 queries and block keys, an i32 page-id table, f32 scores; a negative table entry scores -inf and not zero | common, qwen4exp_fp8 | +| `qsa_select` | yes | qsa_select_i32 | f32 scores and an i32 page table in; an i32 [M, topk+1] table and a live count out | common | +| `qsa_tail_store` | yes | qsa_tail_store_bf16 | bf16 keys in, an i32 position and an i32 cu_seqlens; the bf16 tail written in place | common | +| `qsa_work` | yes | qsa_work_bf16 | bf16 keys and a bf16 tail in, an i32 position, cu_seqlens and the block-key table; a bf16 staging plane out with an i32 page and first-token position a block | common | +| `quant_act_fp8` | yes | quant_act_fp8 | bf16 in, E4M3 out in PLAIN ROW-MAJOR order with an f32 scale per (row, 128 columns) | common, gemma3, gemma4 | +| `quant_act_i8` | yes | quant_act_i8 | bf16 in, int8 out with an f32 per-row scale | common, gemma3, gemma4_bf16 | +| `quant_act_i8g` | yes | quant_act_i8g | bf16 in, int8 out in PLAIN ROW-MAJOR order with an f32 scale of amax/127 per (row, 128 columns) | common, gemma3, minimaxh3, qwenimage21 | +| `quant_cols_fp8` | yes | quant_cols_fp8_bf16 | bf16 in, E4M3 out at its own pitch, f32 scale per column | minimaxh3 | +| `randn_lanes` | yes | randn_lanes_bf16, randn_lanes_f32 | bf16; f32 | anima, flux3, krea2, ltx2, minimaxh3, qwenimage21 | +| `rel_sinusoid` | yes | rel_sinusoid_bf16 | bf16 out, f32 libm sin / cos / exp | embgemma2 | +| `relu` | yes | relu_bf16 | bf16 in and out | embgemma2 | +| `resample_nearest` | yes | resample_nearest_bf16 | bf16 | minimaxmusic3 | +| `resize_bilinear` | yes | resize_bilinear | bf16 or f32 voxels, f32 arithmetic | minimaxh3 | +| `rms_mod` | yes | rms_mod_bf16 | bf16 rows, gain and table, fp32 sum of squares | anima, flux3, krea2, ltx2, minimaxh3 | +| `rms_mod_quant_fp8` | yes | rms_mod_quant_fp8_bf16 | bf16 rows, gain and table, E4M3 codes and f32 scales | anima, flux3, krea2, minimaxh3 | +| `rmsnorm` | yes | rmsnorm_bf16 | bf16 y, x bf16 or (with a gain) f32, bf16 or f32 gain, fp32 reduction | anima, breeze, common, embgemma2, flux3, gemma3, gemma4, gemma4_bf16, glm5next, krea2, lfm2_bf16, llama_fp8, ltx2, minimaxh3, minimaxmusic3, qwen35_bf16, qwen35_fp8, qwen3asr_bf16, qwenimage21, unlimitedocr_bf16 | +| `rmsnorm_add` | yes | -- | | -- | +| `rmsnorm_had_quant_i8` | yes | rmsnorm_had_quant_i8 | bf16 in, int8 out with an f32 per-row scale carrying 1/sqrt(had), optional bf16 out | -- | +| `rmsnorm_had_quant_i8g` | no | rmsnorm_had_quant_i8g | bf16 in, int8 out with an f32 scale per (row, 128 columns) and an optional bf16 out that receives the UNROTATED norm output; the codes are taken over the rotated BF16-ROUNDED norm output, byte-identical to rmsnorm + had_quant_act_i8g | common, qwen35_fp8 | +| `rmsnorm_p` | yes | rmsnorm_p_bf16 | bf16 x / y, fp32 reduction | gemma4_bf16, ltx2 | +| `rmsnorm_quant_fp8` | yes | rmsnorm_quant_fp8 | bf16 in, E4M3 out with an f32 scale per (row, 128 columns) and an optional bf16 out; the codes are taken over the BF16-ROUNDED norm output | common, gemma3, gemma4 | +| `rmsnorm_quant_i8` | no | rmsnorm_quant_i8 | bf16 in, int8 out in the w4a8 GEMM's fragment order with an f32 per-row scale, optional bf16 out; every stored intermediate rounded to bf16 as the unfused chain stores it | common, gemma3, gemma4_bf16 | +| `rope` | yes | rope_bf16 | bf16 qkv, i32 positions, fp32 angles through the accurate sincosf | breeze, common, gemma3, gemma4, gemma4_bf16, ltx2 | +| `rope_split` | yes | rope_split | bf16 or f32 x, f32 or i32 positions | ltx2 | +| `rope_table` | yes | rope_table_f32 | f32 or bf16 table, i32 or i64 positions; the angles are rope_bf16's exactly | qwen35_fp8, qwen4exp_fp8 | +| `router_gemm_topk_scatter` | yes | router_gemm_topk_scatter_bf16 | bf16 activation and weights, fp32 accumulate; bf16 logits, gate and weights, i32 ids, sorted slots, offsets and counts out | common, gemma4 | +| `router_sigmoid_topk` | yes | router_sigmoid_topk_f32 | f32 logits, bias and weights; i32 ids | common | +| `router_sigmoid_topk_scatter` | no | router_sigmoid_topk_scatter_f32 | f32 logits, bias and weights; i32 ids, sorted slots, offsets and counts; bf16 gate | common | +| `router_topk` | yes | router_topk_bf16 | bf16 in, bf16 weights + i32 expert ids out | common, gemma4 | +| `router_topk_scatter` | yes | router_topk_scatter_bf16 | bf16 in, bf16 weights + i32 ids, sorted slots, offsets and counts out | common, gemma4 | +| `row_topk` | yes | rowtopk_bf16 | bf16 in, f32 values + i32 columns out | common | +| `row_topk_merge` | yes | rowtopk_merge | f32 pairs in, f32 values + i32 ids out, ties to the lower id | common | +| `rvq_embed` | yes | rvq_embed_bf16 | bf16 tables and rows | breeze, minimaxmusic3 | +| `s2d3d` | yes | s2d3d | bf16 or f32 x and y, i32 geom | ltx2 | +| `s2d_avg_add` | yes | s2d_avg_add_bf16 | bf16 | common, flux3 | +| `sam_attn` | yes | sam_attn_bf16 | bf16 query / key / value / out and rel_pos tables, i32 cu_seqlens, fp32 accumulate | common | +| `sample_argmax` | yes | sample_argmax_f32 | f32 logits, i32 token | -- | +| `sample_chain` | no | sample_chain_f32 | f32 logits, f32 uniforms (two a position), u32 query tokens or absent, {u32 tok, u32 tok_excl, f32 p_query} out | -- | +| `sample_dry` | yes | sample_dry_f32 | f32 logits in place, i32 history, optional u8 breaker plane, per-row params | -- | +| `sample_logprobs` | yes | sample_logprobs_f32 | f32 logits, f32 stats [M, 2 + 2k] with the ids as floats | -- | +| `sample_mask` | yes | sample_mask_f32 | f32 logits in place, u32 bitmask, per-row params | -- | +| `sample_merge_topk` | yes | sample_merge_topk_f32 | u32 (id, logit-bits) pairs in, i32 candidate ids and f32 candidate logits out | -- | +| `sample_minp` | yes | sample_minp_f32 | i32 candidate ids and f32 candidate logits, both in place | -- | +| `sample_ngram_ban` | yes | sample_ngram_ban_f32 | f32 logits in place, i32 history, i32 {n, window} per-row pair | -- | +| `sample_penalties` | yes | sample_penalties_f32 | f32 logits in place, i32 history, per-row params | -- | +| `sample_pick` | yes | sample_pick_f32 | i32 candidate ids, f32 candidate logits, i32 token | -- | +| `sample_temp` | yes | sample_temp_f32 | f32 logits in place, per-row params | -- | +| `sample_topk` | yes | sample_topk_f32 | f32 logits, i32 candidate ids, f32 candidate LOGITS (not probabilities) | -- | +| `sample_topp` | yes | sample_topp_f32 | i32 candidate ids and f32 candidate logits, both in place | -- | +| `sample_typical` | yes | sample_typical_f32 | i32 candidate ids and f32 candidate logits, both in place | -- | +| `sample_xtc` | yes | sample_xtc_f32 | i32 candidate ids and f32 candidate logits, both in place | -- | +| `scale` | yes | scale_bf16 | bf16 in and out, fp32 arithmetic, s f32 or bf16 | anima, breeze, common, embgemma2, flux3, gemma3, gemma4, gemma4_bf16, krea2, lfm2_bf16, ltx2, minimaxh3, minimaxmusic3, qwen35_fp8, qwen3asr_bf16, qwen4exp_fp8, qwenimage21, sdxl | +| `scale_rows` | yes | scale_rows_bf16 | bf16 in and out, fp32 arithmetic | -- | +| `scatter_add_rows` | yes | scatter_add_rows_bf16 | bf16 | qwenimage21 | +| `scatter_rows` | yes | scatter_rows_bf16, scatter_rows_u8 | i32 indices, bf16 rows; i32 indices, u8 rows | breeze, common, embgemma2, flux3, gemma4_bf16, krea2, minimaxmusic3, qwenimage21, unlimitedocr_bf16 | +| `seg_mean` | yes | seg_mean_bf16 | bf16 in and out, f64 sum, one rounding | embgemma2 | +| `seg_sinusoid` | yes | seg_sinusoid_bf16 | bf16 out, i32 cu_seqlens, f32 libm sin / cos / exp | qwen3asr_bf16 | +| `sigmoid` | yes | sigmoid_bf16 | bf16 in and out, fp32 arithmetic | common, embgemma2, krea2, qwen4exp_fp8 | +| `silu` | yes | silu_bf16, silu_f32 | bf16 in and out, fp32 arithmetic; f32 in, f32 out or bf16 rounded once | anima, common, embgemma2, flux3, gemma4_bf16, krea2, ltx2, minimaxh3, minimaxmusic3, qwen4exp_fp8, qwenimage21, sdxl | +| `silu_mul` | yes | silu_mul_bf16 | bf16 in and out, fp32 arithmetic | breeze, common, ltx2, minimaxh3, unlimitedocr_bf16 | +| `snake` | yes | snake_bf16 | bf16 rows, f32 alpha | breeze, minimaxmusic3 | +| `snake_aa` | yes | snake_aa_f32 | f32 rows, filters, alpha and beta | ltx2, minimaxh3 | +| `softmax` | yes | -- | | unlimitedocr_bf16 | +| `stft_logmel` | yes | stft_logmel | bf16 or f32 operands | ltx2 | +| `swiglu_clamped` | yes | swiglu_clamped_bf16 | bf16 in and out, fp32 arithmetic | common | +| `swiglu_clamped_quant_fp8` | no | swiglu_clamped_quant_fp8 | bf16 in, E4M3 out with an f32 scale per (row, 128 columns) and an optional bf16 out; the codes are taken over the BF16-ROUNDED product | common | +| `table_add` | yes | table_add_bf16 | bf16 | krea2, ltx2 | +| `tconv_dw` | yes | tconv_dw_bf16 | bf16 voxels, weight and bias, fp32 accumulate | minimaxh3 | +| `tile_crop` | yes | tile_crop | bf16 or f32 x and y, i32 geom and box | ltx2 | +| `tile_grid` | yes | tile_grid | i32 | ltx2 | +| `tile_stitch` | yes | tile_stitch | bf16 or f32 x, u8 y, i32 geom and first | ltx2 | +| `timestep_embed` | yes | timestep_embed_bf16, timestep_embed_f32 | bf16; f32 t and out, f32 angles | anima, flux3, krea2, ltx2, minimaxh3, qwenimage21, sdxl | +| `to_rgba8` | yes | to_rgba8_bf16 | bf16 | anima, flux3, krea2, qwenimage21, sdxl | +| `vol_index` | yes | vol_index | i32 | ltx2 | +| `vsa_select` | yes | vsa_select_h128_bf16 | bf16 q / k / v / coarse, i32 segs / geom / sel; f32 means, scores and softmax | minimaxh3 | +| `vtile_gather` | yes | vtile_gather | bf16 or f32 rows and registers | minimaxh3 | +| `vtile_stitch` | yes | vtile_stitch | bf16 or f32 tiles and overlap, u8 out | minimaxh3 | +| `win_finish` | yes | win_finish_bf16 | bf16 states | minimaxmusic3 | +| `win_input` | yes | win_input_bf16 | bf16 | minimaxmusic3 | +| `win_prep` | yes | win_prep_bf16 | bf16 states, f32 t | minimaxmusic3 | diff --git a/docs/SYCL_PROGRESS.md b/docs/SYCL_PROGRESS.md index 0d2e5dc3..7f665538 100644 --- a/docs/SYCL_PROGRESS.md +++ b/docs/SYCL_PROGRESS.md @@ -9,8 +9,8 @@ from it alone. | phase | state | |---|---| | 0 environment check | done | -| 1 codebase study, `SYCL_PORTING.md` | in progress | -| 2 design | not started | +| 1 codebase study, `SYCL_PORTING.md` | done (`docs/SYCL_PORTING.md` §1-§3, Appendix A) | +| 2 design | written (`docs/SYCL_PORTING.md` §4); implementation next | | 3 correctness-first kernels | not started | | 4 performance | not started | | 5 broaden and finish | not started | @@ -171,6 +171,33 @@ Planned use: Milestone A = `minicpm5-2b-bf16.rad` (blocked, item 1); Milestone B - D1 (Phase 0): FP8 and FP4 weights are widened to bf16 in-register for XMX; int8 uses native s8 DPAS. Evidence above. +- D2 (Phase 1): no new device-runtime abstraction. `DeviceBackend` (`core/device/device.h:178`) + already is one and HIP/AQL sit behind it; the Intel backend is a fourth vtable, + `core/device/sycl.cpp`. The HIP path is not touched. (`SYCL_PORTING.md` §4.1) +- D3: plugins get the queue through `abi/rad_sycl.h`'s `RadSyclStream` (magic + own version + + `sycl::queue*`), not a `RAD_ABI_VERSION` bump: no existing shape changes. (§4.2) +- D4: kernel library `libxe2/`, AOT for `intel_gpu_bmg_g31`; `code_runs` under SYCL compares a + plugin's `build_target` with the device arch so libr4d rows are never selected on the B65. (§4.3) +- D5: on the SYCL backend the "host-only ops ... Not a hole" placement is fatal unless + `--debug-accept-host-ops`. (§4.4) +- D6: `RAD_SYCL=ON` builds everything with `icpx`, host code at `-ffp-model=precise` (icpx's default + is fast math); `-fsycl` only on SYCL sources. Fallback: ExternalProject for the SYCL pieces if + host results differ from GCC's. HIP + SYCL refused together at configure until a ROCm machine can + test it. (§4.5) +- D7: `advance` and `wtab` get SYCL launchers; `xprefetch` stays off. (§4.6) +- D8: `--tp > 1` refused at startup on the SYCL backend. (§4.7) + +## Next steps (Phase 2 implementation, in commit order) + +1. CMake: `RAD_SYCL`, the `icpx` check, `-ffp-model=precise`, `build.sh --sycl`, preset, `sycl` + label. Verify: default GCC build unchanged; SYCL build's host tier matches the baseline. +2. `abi/rad_sycl.h`; `__host__ __device__` macros' SYCL case. +3. `core/device/sycl.cpp` backend + selection + `RADIANCE_DEVICE_BACKEND`; a `sycl`-labelled + device test (the contract tests of `tests/device_test.cpp` run against it). +4. `advance` / `wtab` SYCL launchers; `--tp` refusal; fatal host-only placement. +5. `libxe2/` skeleton with one op (`add`) and its libref-checked test; `oot` rebuild. +6. Phase 3: the 13 + 13 ops of `SYCL_PORTING.md` §3.1, each with a libref test, then the tiny + llama end to end against the host backend. ## HIP-side edits awaiting a ROCm compile check @@ -181,6 +208,14 @@ None yet. ```sh . /opt/intel/oneapi/setvars.sh scripts/sycl/probe.sh # Phase 0 device tables +scripts/sycl/op_inventory.sh # SYCL_PORTING.md Appendix A +# the tiny llama containers and their graphs (Phase 1, SYCL_PORTING.md §3.1): +mkdir -p "$T/tmp" && env RADIANCE_HOME=$PWD/build/radiance_home RAD_TEST_TMPDIR=$T/tmp \ + ROCR_VISIBLE_DEVICES=99 RAD_E2E_KEEP=1 build/tests/engine_e2e_test -perf_ +# -> $T/tmp/radiance_e2e.*/{llama,llama_int4}/ checkpoints and llama*.rad containers +build/bin/rad-convert $D/llama -o $D/llama_bf16.rad # the bf16 analogue (no recipe) +build/bin/radiance --model $D/llama_bf16.rad --debug-graph +build/bin/radiance --model $D/llama.rad --kv-cache-dtype fp8 --debug-graph ./build.sh --no-hip # host backend + fast tests ctest --test-dir build -LE 'gpu|oot' # host baseline ``` diff --git a/scripts/README.md b/scripts/README.md index 1c098ec4..aaafaedb 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -55,3 +55,13 @@ output. `mcagent.sh` and `mcdecl.sh` start their own MiniCPM5-2B server through | `mcstream.sh` | Tool-call replies streamed, asserting on raw SSE fragments rather than the assembled message. Streamed content cannot be retracted, so a repair applied at the end is not a fix. | | `mcagent.sh` | What speculation is worth on an agentic workload: `/v1/chat/completions` with tools, a constrained decode. Speculation on and off alternate across restarts because the speculation depth is a server-level setting. | | `mcdecl.sh` | How often the drafter proposes, by context length. `draft_acceptance_ratio` is conditional on having drafted, so it can look healthy while tokens per step collapse; blocks per step separates the two. | + +## The Intel (SYCL) backend + +Tools for the port in `docs/SYCL_PORTING.md`; its log is `docs/SYCL_PROGRESS.md`. They need oneAPI +(`. /opt/intel/oneapi/setvars.sh`) only where they compile device code. + +| | | +|---|---| +| `sycl/probe.sh` | The card's limits, sub-group sizes and `joint_matrix` combinations, and whether XMX executes E4M3 / E5M2 DPAS, each checked against a host loop with bf16 and s8 DPAS as controls in the same harness (on the Arc Pro B65 fp8 DPAS compiles and returns garbage). | +| `sycl/op_inventory.sh` | The op vocabulary as a markdown table: libref's schemas, libr4d's kernels and dtypes per op (its rows read from source by `sycl/r4d_rows.py`, since a build without HIP has no `libr4d.so`), and which architectures name each op. | diff --git a/scripts/sycl/op_inventory.sh b/scripts/sycl/op_inventory.sh new file mode 100755 index 00000000..b2f25ecd --- /dev/null +++ b/scripts/sycl/op_inventory.sh @@ -0,0 +1,37 @@ +#!/bin/sh +# op_inventory.sh -- the op vocabulary as a markdown table, for docs/SYCL_PORTING.md. +# +# One row per op that libref or libr4d declares: whether libref has it (the oracle), the libr4d +# kernels that implement it (from the kKernels rows in libr4d/r4d_rows.cpp, read as source because a +# build without HIP has no libr4d.so), the dtypes those rows state, and the architecture plugins +# whose source names the op. "Architectures naming it" is a grep, so it over-counts an op a plugin +# names only conditionally; --debug-graph on a real container is the exact answer for one model. +# +# Usage: scripts/sycl/op_inventory.sh [BUILD_DIR] (default build/) +set -e +root=$(cd "$(dirname "$0")/../.." && pwd) +build=${1:-$root/build} +tmp=$(mktemp -d) +trap 'rm -rf "$tmp"' EXIT + +RADIANCE_HOME=$build/radiance_home "$build/bin/rad-schemas" "$build/radiance_home/kernels/libref.so" | + awk '/^ [a-z0-9_]+$/ {print $1}' | sort -u > "$tmp/libref" + +python3 -I "$root/scripts/sycl/r4d_rows.py" "$root/libr4d/r4d_rows.cpp" | sort > "$tmp/r4d" + +cut -f1 "$tmp/r4d" | sort -u > "$tmp/r4d_ops" +sort -u "$tmp/libref" "$tmp/r4d_ops" > "$tmp/all" + +echo "| op | libref | libr4d kernels | libr4d dtypes (first three rows' prose) | architectures naming it |" +echo "|---|---|---|---|---|" +while read -r op; do + ref=no; grep -qx "$op" "$tmp/libref" && ref=yes + kern=$(awk -F'\t' -v o="$op" '$1 == o {print $2}' "$tmp/r4d" | tr '\n' ' ' | sed 's/ $//; s/ /, /g') + dts=$(awk -F'\t' -v o="$op" '$1 == o && $3 != "" {print $3}' "$tmp/r4d" | sort -u | head -3 | + tr '\n' ';' | sed 's/;$//; s/;/; /g; s/|/\\|/g') + archs=$(grep -rlw --include=*.cpp --include=*.h -e "\"$op\"" "$root/arch" 2>/dev/null | + sed "s#$root/arch/##; s#/.*##" | sort -u | tr '\n' ' ' | sed 's/ $//; s/ /, /g') + [ -z "$kern" ] && kern="--" + [ -z "$archs" ] && archs="--" + echo "| \`$op\` | $ref | $kern | $dts | $archs |" +done < "$tmp/all" diff --git a/scripts/sycl/r4d_rows.py b/scripts/sycl/r4d_rows.py new file mode 100644 index 00000000..88754643 --- /dev/null +++ b/scripts/sycl/r4d_rows.py @@ -0,0 +1,44 @@ +"""r4d_rows.py ROWS_CPP -- the kKernels rows of libr4d/r4d_rows.cpp as TSV: op, kernel, dtypes, domain. + +Read as source because a build without HIP has no libr4d.so to ask. A row is +{ "kernel", "op", "family", "computes", "shape", "dtypes", RAD_DOMAIN_..., ... }; adjacent string +literals are joined as the C compiler joins them, so a dtypes string split over lines stays whole. +""" +import re +import sys + +src = open(sys.argv[1], encoding="utf-8").read() +start = src.index("static const RadKernelInfo kKernels[] = {") +body = src[start:] +# Comments out, so prose in them cannot look like a row. +body = re.sub(r"/\*.*?\*/", " ", body, flags=re.S) +body = re.sub(r"//[^\n]*", " ", body) + +body = body.replace("\\\n", "\n") # macro line continuations + +lit = r'"(?:[^"\\]|\\.)*"' +# Between literals a row may splice in a macro: R4D_XSTR(X), a stringised #PARAM, or a name such as +# KVDOC. Each is kept as , so a template row's kernel reads attn_window_h_gqa_. +mac = r"R4D_XSTR\(\s*\w+\s*\)|#\w+|\b(?!RAD_DOMAIN_)[A-Z][A-Z0-9_]*\b" +row_re = re.compile(r"\{\s*((?:(?:" + lit + "|" + mac + r")\s*,?\s*)+?)(RAD_DOMAIN_[A-Z]+)") +for m in row_re.finditer(body): + if not m.group(1).lstrip().startswith('"'): + continue + # Split the run into arguments at commas; join adjacent literals and macros within one. + args, cur = [], [] + for tok in re.finditer(lit + "|" + mac + r"|,", m.group(1)): + t = tok.group(0) + if t == ",": + args.append("".join(cur)) + cur = [] + elif t.startswith('"'): + cur.append(re.sub(r"\\(.)", r"\1", t[1:-1])) + else: + name = re.sub(r"^R4D_XSTR\(\s*|\s*\)$|^#", "", t) + cur.append(f"<{name}>") + if cur: + args.append("".join(cur)) + if len(args) < 6: + continue + kern, op, dtypes = args[0], args[1], " ".join(args[5].split()) + print(f"{op}\t{kern}\t{dtypes}\t{m.group(2)[len('RAD_DOMAIN_'):].lower()}")