Skip to content

feat(gemv_q8): plain and SwiGLU-fused MoE gather kernels, bf16 casts, f16-scale rename#69

Merged
TheTom merged 5 commits into
feature/cuda-hip-vulkanfrom
tom/laguna-moe-gather-kernels
Jul 23, 2026
Merged

feat(gemv_q8): plain and SwiGLU-fused MoE gather kernels, bf16 casts, f16-scale rename#69
TheTom merged 5 commits into
feature/cuda-hip-vulkanfrom
tom/laguna-moe-gather-kernels

Conversation

@TheTom

@TheTom TheTom commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

What

Kernel-side companion to the Laguna decode PR in the FFAI tree (thewafflehaus/FFAI#69).

  • ffai_moe_gather_q4: plain (no-activation) expert gather GEMV, the gated-FFN sibling of the ReLU2 gather; experts indexed in-kernel via the idx buffer
  • ffai_moe_gather_q4_swiglu: fused gate+up+SwiGLU gather; both dot products share each activation load in one j-loop, silu applied in-lane before the single store
  • ffai_cast_f32_bf16 / ffai_cast_bf16_f32: elementwise casts for bf16 residual streams
  • Rename: the five kernels whose per-block scales are f16 had the parameter misleadingly named d_f32; now d_f16, with an explicit scale-dtype contract documented on every kernel in the family. Uploading f32 scale bytes into an f16-typed buffer silently reinterprets them as garbage and inflates every output; this naming cost a full debugging session downstream.

Validation

  • Unit-tested from the consumer tree on GB10: fused swiglu gather matches the unfused compose to 1e-3 relative; plain gather exercised by the full Laguna decode which is token-for-token identical to the reference implementation
  • cargo check clean for metaltile-std
  • Behavior-neutral for existing callers: the rename is signature-order-preserving and all call sites updated in the consumer tree

Perf context

These kernels carry the Laguna MoE decode path that reaches 36.5 tok/s single-stream on GB10 (reference implementation on identical weights and box: 21.24).

…rename

Add ffai_moe_gather_q4, the no-activation sibling of the ReLU2 gather, so
gated (SwiGLU) MoE paths can gather the gate and up expert stacks with
in-kernel expert indexing. Add ffai_cast_f32_bf16 / ffai_cast_bf16_f32
elementwise casts for bf16 residual streams.

Rename the misleading d_f32 parameter to d_f16 on the five kernels whose
per-block scales are f16 (gemv_q4 coalesced/relu2/accum, moe_gather_q4
relu2/down) and document the scale dtype contract on each kernel in the
family; uploading f32 scale bytes into these silently reinterprets them
as garbage f16 and inflates every output.
@github-actions github-actions Bot added the feature New feature label Jul 23, 2026
TheTom added 4 commits July 22, 2026 22:57
…ifiers

Mechanical cargo fmt over the crate (the CUDA feature line had never run
through repo CI, so format debt across many files surfaces on the first
PR from it) plus a typos config accepting the intentional short
accumulator/nibble names (ba/bb/na/nb) in the hand-rolled GEMV kernels.
No behavior change; cargo check clean.
Repo-wide cargo fmt, clippy fixes across the codegen crates (collapsed
ifs, dropped useless format! calls, allow on the 9-arg spirv emit_op),
typos config for the intentional optin identifiers, and the missing
metaltile-core/metaltile-codegen dev-dependencies that the in-module
smoke tests in metaltile-std reference (this also un-breaks the full
test-target build, which previously failed with unresolved-crate errors
before any test ran). No behavior change.
The CI clippy gate runs with --all-features, which pulls the cuda and
vulkan device modules into the lint set: allow attrs on the FFI-handle
wrappers (not_unsafe_ptr_arg_deref on graph_launch/_batch, dead_code on
the CUDA FFI constant surface, too_many_arguments on the grouped-CUTLASS
entry), a dropped never-read init, and doc-comment list formatting.
Typos config gains dout/ERRO (d-out signal name, log-level tag). No
behavior change.
The typos gate reads .github/configs/typos-cli.toml explicitly; add the
short GEMV accumulator/nibble identifiers (ba/bb/na/nb) and the
dout/erro/optin word stems there and drop the stray root config the
checker never consults.
@TheTom
TheTom marked this pull request as ready for review July 23, 2026 12:10
@TheTom
TheTom merged commit 3518572 into feature/cuda-hip-vulkan Jul 23, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant