[Layout] Add tmem duplication attribute and tcgen05.copy multicast#152
Open
yaoyaoding wants to merge 1 commit intomainfrom
Open
[Layout] Add tmem duplication attribute and tcgen05.copy multicast#152yaoyaoding wants to merge 1 commit intomainfrom
yaoyaoding wants to merge 1 commit intomainfrom
Conversation
…icasts
Two coupled additions, paving the way for block-scaled MMAs (NVFP4, MXFP4)
that need scale-factor tensors replicated across TMEM warp sub-partitions.
TMemoryLayout duplication:
- New `TMemoryDuplication` enum: NONE / WARPX4 / WARPX2_02_13 / WARPX2_01_23.
- `TMemoryLayout.create()` cross-validates shape[0] against duplication:
WARPX4 requires shape[0]=32; WARPX2_* require shape[0]=64; NONE accepts
{32, 64, 128}. WARPX* layouts disallow non-zero lane_offset (they span all
128 physical lanes via replication); NONE requires
lane_offset + shape[0] <= 128.
- `tmemory_row_major` accepts a `duplication` kwarg.
- `tmemory_slice` preserves the parent's duplication on column-dim slicing;
rejects lane-dim slicing on WARPX* tensors.
- `Tcgen05AllocRule` pins WARPX4 for shape[0]=32 and NONE for shape[0]=128;
defers shape[0]=64 (ambiguous between NONE and WARPX2_*) to the copy rule.
- 21 new unit tests under tests/ir/layout/test_tmem_layout.py.
tcgen05.copy multicast kwarg + emitter:
- `Tcgen05CopyInst` gains a `multicast: str = ""` field (primitive type so
IR functors walk it generically; converted to Tcgen05CopyMulticastKind in
the codegen emitter).
- User-facing `Tcgen05Module.copy(..., multicast=None)` accepts None,
"warpx4", "warpx2_02_13", or "warpx2_01_23"; unknown names raise
`InstructionError`.
- Emitter implements all three multicast modes by mapping each to its
required source-row count (32 / 64) and shape kind (R32x128B / R64x128B),
loosening the K-major alignment to `inst_n % T == 0` so the smaller shape
kinds are accepted.
- Alloc emitter accepts shape[0] in {32, 64, 128}.
- `Tcgen05CopyRule` infers TMEM duplication from the multicast kwarg
(covers the deferred shape[0]=64 cases).
- Fixed the PTX modifier strings on `Tcgen05CopyMulticastKind`
(`.warpx2_02_13` -> `.warpx2::02_13`, `.warpx2_01_23` -> `.warpx2::01_23`)
as required by ptxas.
- New SMEM->TMEM->global round-trip tests in test_tcgen05_copy.py exercise
all three multicast modes plus the unknown-name validation.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: Yaoyao Ding <dingyaoyao.cs@gmail.com>
3b59fc7 to
b454685
Compare
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.
Two coupled additions, paving the way for block-scaled MMAs (NVFP4, MXFP4) that need scale-factor tensors replicated across TMEM warp sub-partitions.
TMemoryLayout duplication (PR1a):
TMemoryDuplicationenum: NONE / WARPX4 / WARPX2_02_13 / WARPX2_01_23.TMemoryLayout.create()cross-validates shape[0] against duplication: WARPX4 requires shape[0]=32; WARPX2_* require shape[0]=64; NONE accepts {32, 64, 128}. WARPX* layouts disallow non-zero lane_offset (they span all 128 physical lanes via replication); NONE requires lane_offset + shape[0] <= 128.tmemory_row_majoraccepts aduplicationkwarg.tmemory_slicepreserves the parent's duplication on column-dim slicing; rejects lane-dim slicing on WARPX* tensors.Tcgen05AllocRule(layout inference) pins WARPX4 for shape[0]=32 and NONE for shape[0]=128; defers shape[0]=64 (ambiguous between NONE and WARPX2_*) to downstream inference (e.g. a copy with multicast hint).tcgen05.copy multicast kwarg (PR1b):
Tcgen05CopyInstgains amulticast: str = ""field (primitive type so IR functors walk it generically; converted to Tcgen05CopyMulticastKind in the codegen emitter).Tcgen05Module.copy(..., multicast=None)accepts None, "warpx4", "warpx2_02_13", or "warpx2_01_23"; unknown names raiseInstructionError.split_canonical_layout/generate_instructions/ thetcgen05_copyPTX call. The NONE path is unchanged. Multicast modes raiseNotImplementedError("not yet supported in emitter") until the smaller-shape codegen lands as part of the NVFP4 matmul work.Tests: 61 passed, 4 xfailed across all TMEM-related instruction + layout suites. matmul_v0..v6 examples still build cleanly.