Repository navigation
[CuTeDSL] clc_response: query get_first_ctaid only when is_canceled is true - #3937
Open
builtin-pb wants to merge 1 commit into
Open
builtin-pb wants to merge 1 commit into
builtin-pb wants to merge 1 commit into
Conversation
…s true PTX leaves clusterlaunchcontrol.query_cancel.get_first_ctaid undefined when the try_cancel request failed, but clc_response issued the three get_first_ctaid queries unconditionally, and every persistent CTA decodes a failed response once no cluster is left to cancel. Issue the queries in one inline PTX block, with get_first_ctaid.v4 predicated on is_canceled as in the C++ sm100 tile scheduler, and return 0 coordinates when the request failed. A branch around the NVVM ops would not be enough: LLVM marks the query intrinsics speculatable, so it may hoist them above the branch. Signed-off-by: Bo Peng <builtin.pb@gmail.com>
fengxie
approved these changes
Dec 2, 2026
fengxie
left a comment
Collaborator
There was a problem hiding this comment.
Thanks for fixing. Approved.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary.
cute.arch.clc_responseissuesclusterlaunchcontrol.query_cancel.get_first_ctaidwhether or not thetry_cancelrequest succeeded, but the PTX ISA leaves that query undefined after a failed request, and every persistent CTA decodes a failed response once no cluster is left to cancel. This PR issues the query only under theis_canceledpredicate, in one inline PTX block like the C++ sm100 tile scheduler's, and returns 0 coordinates when the request failed.Problem
clc_response(python/CuTeDSL/cutlass/cute/arch/clc.py) loads the 16-byte response, then emits four NVVM queries in a row:is_canceled, thenget_first_cta_id_x,_yand_z. Nothing makes the last three depend on the first; callers testis_validafterwards.cutlass.utils.ClcDynamicPersistentTileScheduler.work_tile_info_from_clc_response, its copy inexamples/python/CuTeDSL/helpers/dynamic_persistent_tile_scheduler.py,examples/python/CuTeDSL/helpers/fmha_helpers.pyandpython/CuTeDSL/cutlass/experimental/task_scheduling/resources.py.dense_gemm_persistent_dynamic.py(v4.8.1, sm_100a, 2×1 cluster, 2-CTA MMA), two of the four decode sites read::xand::ybefore the branch onis_canceled. At the other two, LLVM placed the reads after the branch, on the fall-through path, which runs when the request failed. The second site, with the{ .reg .b128 %clc_handle; ... }wrappers elided:ClcDynamicPersistentTileScheduler, has five such sites in a head-dim-128 build and five in a head-dim-256 2-CTA build.examples/python/CuTeDSL/experimental/rubin/kernel/slice_k/sm107_slicek_gemm_wdm.py(ClcPersistentScheduler.get_task_info) issues the same four queries itself, through the experimental 1:1 primitives, in the same order. We left that example alone.Change
clc_responsekeeps its signature and its 128-bit load, and decodes the response in one PTX block:A failed request now returns
(0, 0, 0, 0)instead of undefined coordinates;is_validkeeps its meaning. The docstring says so.Why this is correct
PTX ISA 9.4, §9.7.15.19 (
clusterlaunchcontrol.query_cancel): "If the request fails the behavior of clusterlaunchcontrol.query_cancel.get_first_ctaid is undefined.".v4form's fourth element unspecified, so it separates an unspecified value from undefined behavior, and a decode after a failed request is the latter..v4form used here, andinclude/cutlass/gemm/kernel/sm100_tile_scheduler.hpp:416–428does the same with@p1. The Examples also list the scalar::x,::yand::zforms without a predicate, but those lines show syntax; the Description's sentence above defines the behavior.if: LLVM defines these intrinsics withNVVMPureIntrinsic, which addsIntrNoMemandIntrSpeculatable(IntrinsicsNVVM.td at 109bda6, L3965–L3974). LLVM already moves these queries freely: at two of the GEMM's sites above it sank them past the branch.IntrSpeculatablealso lets it hoist a query out of anifonis_canceled. With the predicate inside the asm block, no transformation can separate the query from its guard.Cost and alternatives
.v4query instead of one to three scalar ones, plus threemovs and aselp.ifonis_validaround the three NVVM ops. Shorter, but it relies on LLVM not moving speculatable intrinsics out of the branch.IntrSpeculatablefromget_first_ctaid. This change doesn't depend on it.Testing
nvidia-cutlass-dsl4.8.1 with this PR'sclc.pyloaded over the installed one, target sm_100a. The 4.8.1 file differs from main's only by keyword-only markers.examples/python/CuTeDSL/cute/blackwell/kernel/dense_gemm/dense_gemm_persistent_dynamic.pyat v4.8.1, through itscompile_bmmwith fake tensors (fp16, 1024×1024×512, MMA tile 256×256, 2×1 cluster, 2-CTA). It compiles, and all 4 decode sites becomeis_canceledplus@p get_first_ctaid.v4. Before: 4 sites with unguarded::xand::y.is_canceled.try_cancel: 11 sites, all predicated. Before: 5 unguarded sites and 6 that read onlyis_canceled.-arch=sm_100a) assembles every PTX, before and after.