Skip to content

cuda: cp.async commit and wait from common/cp_async.cuh, SASS unchanged (#1409 step 5) - #1588

Merged
ashhart merged 1 commit into
ashhart:mainfrom
jschmied:prims-1409-step5b
Oct 30, 2026
Merged

ashhart merged 1 commit into
ashhart:mainfrom
jschmied:prims-1409-step5b

Conversation

@jschmied

Copy link
Copy Markdown
Contributor

#1409, step 5: the cp.async group fences. This is independent of #1550, #1555, #1556 and #1564, and based on current main.

What

Eleven files each kept their own cp.async.commit_group and cp.async.wait_group N, under five names (cp_commit/cp_wait, cp_async_commit/cp_async_wait, wait_group, wait_all). The new common/cp_async.cuh holds one tf_common::cp_commit() and cp_wait<N>(), and the files take them with using declarations, as in #1440:

  • exl3_block/pfdense.cuh, exl3_block/x3gm.cu, experts.cuh: using only, no caller changes.
  • exl3_prompt.cuh: cp_async_commit/cp_async_wait are renamed to cp_commit/cp_wait.
  • glm_index_scores.cuh: cp_wait() (a hard-coded wait_group 0) becomes cp_wait<0>().
  • prefill_attention.cu and prefill_attention_rows.cuh, plus tree_attention.cu, window_attention.cu, window_rows.cuh: wait_group<N> becomes cp_wait<N>.
  • block_attention.cu: wait_all() becomes cp_wait<0>().

experts.cuh's gradient-serving pin takes the new bytes. The two prefill_attention pins already differ on main and are left as they are.

Not here:

Checks

  • tools/zig/cuda_sass_identity.py origin/main HEAD: identical cuobjdump -sass for every function of the 27 images this change reaches. That is 2,245 functions over sm_80/86/89/120/121 with nvcc 13.0.
    • The tool's warp_sum control goes red.
    • Its fp4pair control changes nothing here, because none of these images uses fp4pair; that is why the tool exits 1.
  • A planted control in cp_async.cuh (cp_wait<N> waiting for N − 1 groups) changes 1,190 functions, so the comparison can see this header.
  • Lean checker: no new problems.
  • zig build test: passes.

@ashhart

ashhart commented Oct 29, 2026

Copy link
Copy Markdown
Owner

Thank you, this is a nice cleanup, and the SASS receipt with the planted control is just what we need.

There is one thing to fix before we can land it. tools/glm_index_emulate/emulate.cpp builds glm_index_scores.cuh as host C++ with GLM_INDEX_HOST defined, and it supplies its own stub inline void cp_wait() {}. Now that the kernel calls cp_wait<0>(), the host build fails:

glm_index_scores.cuh:95:5: error: use of undeclared identifier 'cp_wait'

You can reproduce it with zig build test-glm-index-emulate. That step is not part of zig build test, so it is easy to miss. Making the stub a template fixes it:

template <int N> inline void cp_wait() {}

With that change the emulator builds and passes (0 failures) on our side. Could you add it to this PR? Everything else looks good to land.

ashhart added a commit to jschmied/TensorFold that referenced this pull request Oct 29, 2026
ashhart pushed a commit to jschmied/TensorFold that referenced this pull request Oct 29, 2026
ashhart#1409 step 6, the copies that are the same instruction:
- prefill_attention.cu and qwen35_attn_tc.cuh kept their own ldmatrix4t, qmm_frag's
  text: both take qmm_frag::ldmatrix4t.
- the exl3 kernels' ldsm4 (x3gm.cu, pfdense.cuh), ldsm2 (x3gm2.cuh) and ldmatrix_x4
  (exl3_prompt.cuh) are qmm_frag's ldmatrix4 and ldmatrix2 with their own address
  cast; they take qmm_frag's, and their callers (x3gm, x3gm2, x3gm3, pfdense,
  exl3_prompt) the names.
- experts_grouped.cuh's f16 mma16816 is exl3_decode.cuh's text: tf_exl3x takes
  tf_exl3's through a using declaration.

Not here: mma_z (nvfp4_experts, flashnext_fexp) and experts.cuh's mma take scalar
operands where qmm_frag's take arrays; pfdense's mma16816_bf16 is asm volatile where
qmm_frag::mma is not; the glm glue copies follow ashhart#1564.

cuobjdump -sass is identical for every function of the 14 images this reaches (1,935
functions, sm_80/86/89/120/121, nvcc 13.0), base ashhart#1588. The tool's warp_sum control
goes red; a planted control in exl3_decode.cuh (the f16 mma as bf16) changes 2,238 of
2,803 functions.
ashhart added a commit that referenced this pull request Oct 29, 2026
ashhart pushed a commit that referenced this pull request Oct 29, 2026
#1409 step 6, the copies that are the same instruction:
- prefill_attention.cu and qwen35_attn_tc.cuh kept their own ldmatrix4t, qmm_frag's
  text: both take qmm_frag::ldmatrix4t.
- the exl3 kernels' ldsm4 (x3gm.cu, pfdense.cuh), ldsm2 (x3gm2.cuh) and ldmatrix_x4
  (exl3_prompt.cuh) are qmm_frag's ldmatrix4 and ldmatrix2 with their own address
  cast; they take qmm_frag's, and their callers (x3gm, x3gm2, x3gm3, pfdense,
  exl3_prompt) the names.
- experts_grouped.cuh's f16 mma16816 is exl3_decode.cuh's text: tf_exl3x takes
  tf_exl3's through a using declaration.

Not here: mma_z (nvfp4_experts, flashnext_fexp) and experts.cuh's mma take scalar
operands where qmm_frag's take arrays; pfdense's mma16816_bf16 is asm volatile where
qmm_frag::mma is not; the glm glue copies follow #1564.

cuobjdump -sass is identical for every function of the 14 images this reaches (1,935
functions, sm_80/86/89/120/121, nvcc 13.0), base #1588. The tool's warp_sum control
goes red; a planted control in exl3_decode.cuh (the f16 mma as bf16) changes 2,238 of
2,803 functions.
@jschmied

Copy link
Copy Markdown
Contributor Author

Thanks @ashhart. Done in 6c92b2685: the stub is now template <int N> inline void cp_wait() {}. zig build test-glm-index-emulate builds and passes here, and zig build test plus the CI set (test-kernel-contract test-golden test-server-security test-pull-security fuzz-cortheon), git diff --check and lean (0 new) pass on the new head.

@ashhart
ashhart merged commit 7a9fc41 into ashhart:main Oct 30, 2026
9 checks passed
@ashhart

ashhart commented Oct 31, 2026

Copy link
Copy Markdown
Owner

Thank you @jschmied. This is in TensorFold 1.2.0, released today: https://github.com/ashhart/TensorFold/releases/tag/v1.2.0

It landed with your commits under your own name, so you're listed as a TensorFold contributor, and it's credited to you in the release notes and the changelog.

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