Repository navigation
Conversation
…edicate The kernel computed frgPred but never used it, so tensors whose shape is not a multiple of the tile size were read and written out of bounds. Load and store through predicated cute.copy, and remap the blocks of the coordinate tensor like the data tensors so the predicate is correct for non-square block grids.
fengxie
approved these changes
Nov 29, 2026
fengxie
left a comment
Collaborator
There was a problem hiding this comment.
Good catch on both the unused frgPred and the missing remap_block composition on cC. I verified on B200 that this eliminates all out-of-bounds reads and writes (0 errors under PYTORCH_NO_CUDA_MEMORY_CACHING=1 compute-sanitizer --tool memcheck on non-tile-aligned shapes).
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.
elementwise_apply.pycomputesfrgPred("predicate for out of boundary checks") and then never uses it: the kernel loads and stores throughthrInput.load()/thrC.store()unconditionally. For a tensor whose shape is not a multiple of the(64, 256)tile, the edge blocks read and write past the end of the tensor.Using the predicate also exposed that it was computed from the wrong coordinates: the data tensors are composed with
remap_block((RestM, RestN) -> (RestN, RestM)), the coordinate tensorcCwas not, sofrgPredwas only right when the block grid is square.Changes, all in the example:
cute.copy(..., pred=frgPred), the same wayelementwise_add.pydoes;((AtomV, AtomRest), Rest...)profilecute.copyexpects by prepending a unit mode;cCwithremap_blocklike the data tensors.Verification
nvidia-cutlass-dsl 4.9.0.dev1 (cu13), B200. The output is a view of the first
Mrows of a larger buffer pre-filled with a sentinel, so any sentinel overwritten past rowMis an out-of-bounds store.--op add:After the change the result is also correct and in bounds for 512x512, 64x2048, 2048x64, 3x1000, 1x7 and 777x1234, and the example's own reference check passes for
add,mul,sub,truedivandleaky_reluat 1000x1000.Performance at the default 4096x4096 (
--benchmark --skip_ref_check --iterations 300, four alternating runs on a GPU shared with other jobs): 0.053-0.069 ms before, 0.060-0.076 ms after. The ranges overlap and the run-to-run noise is larger than any difference, so I can't claim it is neutral to better than that.