Skip to content

refactor(kernels): neutral ownership for generic bf16 matmul + embedding helpers (#112) - #117

Merged
LiangSu8899 merged 7 commits into
flashrt-project:mainfrom
heiheiha798:cleanup/generic-kernel-helper-names
Jun 27, 2026
Merged

LiangSu8899 merged 7 commits into
flashrt-project:mainfrom
heiheiha798:cleanup/generic-kernel-helper-names

Conversation

@heiheiha798

Copy link
Copy Markdown
Contributor

What

Ownership/name cleanup for issue #112. Several model-neutral CUDA helpers
still lived under Qwen3.6 file/symbol names while non-Qwen3.6 paths reused
them. This moves the generic helpers into neutral files and migrates the
non-Qwen3.6 call sites, keeping legacy names as thin wrappers.

Refactor-only. No kernel algorithm, dtype policy, dispatch, graph
capture, or runtime fallback change.

Changes

  • Neutral bf16_matmul_bf16 (csrc/kernels/bf16_matmul_bf16.{cu,cuh}):
    the model-neutral small-M warp matmul (former bf16_matmul_qwen36_bf16
    body) plus bf16_matmul_cublaslt_bf16 (already a neutral symbol; only its
    file moved). bf16_matmul_qwen36.cu keeps the Qwen3.6-specific AB96
    kernels and a thin bf16_matmul_qwen36_bf16 wrapper that forwards.
  • Neutral embedding_lookup_bf16 (csrc/kernels/embedding_lookup_bf16.{cu,cuh}):
    the generic bf16 embedding gather (former qwen36_embedding_lookup_bf16
    body). qwen36_misc.cu keeps its Qwen3.6-specific helpers and a thin
    forwarding wrapper.
  • Bindings: both neutral and legacy names are bound; no binding removed.
  • Qwen3-VL dedicated module no longer compiles the Qwen3.6 matmul TU —
    it only needed bf16_matmul_cublaslt_bf16, now in the neutral file.
  • Call sites: non-Qwen3.6 frontends (Qwen3, Qwen3-VL, Qwen3-VL FP8 SM89,
    GROOT N1.7) migrate to the neutral names. Qwen3.6 frontends keep the legacy
    names for auditability. Higgs docstrings updated.

Commits (each independently buildable)

  1. test: baseline binding-name net (legacy names)
  2. refactor: neutral bf16_matmul_bf16 ownership
  3. build: drop the Qwen3.6 matmul TU from the Qwen3-VL module (isolated, revertible)
  4. refactor: neutral embedding_lookup_bf16 ownership
  5. docs: point non-Qwen3.6 refs at neutral names + 2 missed call sites
  6. docs: update a stale cuBLASLt link comment

Verification (local, RTX 4090 / SM89)

  • flash_rt_kernels, flash_rt_fa2, flash_rt_qwen3_vl_kernels build clean.
  • Binding test asserts both neutral and legacy names exist on the modules.
  • Embedding CUDA equivalence: neutral == reference and legacy == neutral,
    bit-identical.
  • Qwen3-VL-2B SM89 multimodal smoke matches the pre-cleanup baseline:
    prefill_graph cos_vs_eager=1.0, decode cos_vs_eager=1.0.

Closes #112.

…t#112)

Move the model-neutral small-M bf16 matmul and the cuBLASLt BF16 GEMM out
of the Qwen3.6-named translation unit into a neutral file, sharing one
implementation. No kernel algorithm, dtype, or dispatch change.

- Add csrc/kernels/bf16_matmul_bf16.{cu,cuh} with bf16_matmul_bf16
  (former bf16_matmul_qwen36_bf16 body) and bf16_matmul_cublaslt_bf16
  (already a neutral symbol name; only its file moved).
- Reduce bf16_matmul_qwen36.cu to the Qwen3.6-specific AB96 kernels plus a
  thin bf16_matmul_qwen36_bf16 wrapper that forwards to bf16_matmul_bf16.
- Bind the neutral name bf16_matmul_bf16 in flash_rt_kernels; keep the
  legacy binding for compatibility.
- qwen3_vl_bindings.cpp now includes the neutral header for the cuBLASLt
  symbol. Both flash_rt_kernels and flash_rt_qwen3_vl_kernels compile the
  neutral file (the Qwen3-VL source-list now also has it; the redundant
  Qwen3.6 matmul TU is dropped from the VL module in the next commit).
- Migrate non-Qwen3.6 call sites (qwen3_rtx, qwen3_vl_rtx,
  qwen3_vl_fp8_sm89) to the neutral name. Qwen3.6 call sites keep legacy
  names for auditability.
- Activate the neutral-name binding assertion in the cleanup test.
…roject#112)

The Qwen3-VL dedicated module only needs bf16_matmul_cublaslt_bf16, which
now lives in the neutral bf16_matmul_bf16 translation unit. Remove
bf16_matmul_qwen36.cu from QWEN3_VL_SOURCES so flash_rt_qwen3_vl_kernels no
longer compiles the Qwen3.6-specific AB96/MTP-adjacent matmul code just to
get one cuBLASLt wrapper.

Isolated, independently revertible sub-step. Verified: flash_rt_qwen3_vl_kernels
builds, exposes no AB96 symbols, still resolves bf16_matmul_cublaslt_bf16,
and the Qwen3-VL-2B SM89 multimodal smoke matches the pre-cleanup baseline
(prefill_graph cos_vs_eager=1.0, decode cos_vs_eager=1.0).
…roject#112)

Move the model-neutral bf16 embedding lookup out of qwen36_misc into a
neutral file, sharing one implementation. No kernel change.

- Add csrc/kernels/embedding_lookup_bf16.{cu,cuh} with embedding_lookup_bf16
  (former qwen36_embedding_lookup_bf16 body).
- Reduce qwen36_misc.cu: the embedding kernel/body move out; the legacy
  qwen36_embedding_lookup_bf16 becomes a thin wrapper that forwards to
  embedding_lookup_bf16. Qwen3.6-specific misc helpers stay put.
- Bind the neutral name embedding_lookup_bf16 in flash_rt_kernels; keep the
  legacy binding for compatibility.
- Migrate non-Qwen3.6 call sites (qwen3_rtx, qwen3_vl_fp8_sm89,
  groot_n17_thor, groot_n17_thor_fp8) to the neutral name. Qwen3.6 call
  sites keep legacy names for auditability.
- Activate the neutral-name binding assertion in the cleanup test.

Verified: flash_rt_kernels builds, both bindings resolve, and a CUDA
equivalence check confirms neutral == reference and legacy == neutral
(bit-identical).
…t-project#112)

- Higgs BF16/RTX docstrings now reference bf16_matmul_bf16 instead of the
  legacy bf16_matmul_qwen36_bf16 (comment-only; Higgs calls the matvec and
  GemmRunner, not this matmul). silu_mul_qwen36_bf16 is left as-is since it
  stays Qwen3.6-specific.
- Migrate two Qwen3 lm_head matmul call sites in qwen3_rtx.py that the
  Unit 1 sweep missed (full_logits and the M=1 branch) to bf16_matmul_bf16.
  Behavior is unchanged (the legacy name is a thin wrapper); this only
  completes the non-Qwen3.6 ownership migration.
…t-project#112)

The flash_rt_qwen3_vl_kernels SM89 cuBLASLt link comment still named the
old bf16_matmul_qwen36 translation unit; the module now compiles
bf16_matmul_bf16.cu for that cuBLASLt path. Comment-only.
@heiheiha798
heiheiha798 requested a review from LiangSu8899 as a code owner June 27, 2026 03:49
Copilot AI review requested due to automatic review settings June 27, 2026 03:49

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@LiangSu8899
LiangSu8899 merged commit c5b841e into flashrt-project:main Jun 27, 2026
@heiheiha798
heiheiha798 deleted the cleanup/generic-kernel-helper-names branch June 28, 2026 12:38
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.

Track generic CUDA kernels under qwen36 filenames

3 participants