This is an automated email from the ASF dual-hosted git repository.

tlopex pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm-tirx.git


The following commit(s) were added to refs/heads/main by this push:
     new 8c2548af2 [FIX][CUDA] Register tcgen05.mma .ashift without a collector 
qualifier (#257)
8c2548af2 is described below

commit 8c2548af20bb43fd74e3a4b0665c73663c07a8b1
Author: Hongyi Jin <[email protected]>
AuthorDate: Sat Nov 21 23:34:05 2026 -0500

    [FIX][CUDA] Register tcgen05.mma .ashift without a collector qualifier 
(#257)
    
    ## Motivation
    
    `.ashift` shifts the rows of the A matrix in Tensor Memory down by one
    between MMAs. Convolution and sliding-window kernels use it to step the
    activation window without reloading A. PTX ISA 8.6 introduced the dense
    form with A in Tensor Memory,
    `tcgen05.mma.cta_group.kind.ashift{.collector_a_usage}`, and every
    collector qualifier on it is optional.
    
    TIRx only registers `.ashift` spellings that also carry a collector B
    qualifier (the PTX 9.4 collector-B entries). The plain form is rejected:
    
    ```python
    T.ptx["tcgen05.mma.cta_group::1.kind::f16.ashift"](...)
    # ValueError: no ptx instruction matches these operands; ...
    #   tcgen05_mma_ashift_collector_b_ts: missing required modifier(s): 
collector_b
    ```
    
    So `.ashift` cannot be written for sm_100a at all, and on sm_107 users
    have to add a semantically redundant `.collector::b::discard`.
    
    ## Changes
    
    - Register `tcgen05_mma_ashift_ts` for `kind::f16`, `kind::tf32`,
    `kind::f8f6f4` and `kind::i8`, certified at sm_100a.
    - Collector A is optional, limited to `lastuse` and `discard`; PTX
    forbids `fill` and `use` together with `.ashift`. Spellings with
    collector B stay owned by the existing entries.
    - Regenerate the `tirx.pyi` stub and update the variant and
    address-operand counts.
    
    ## Testing
    
    - Dispatch with no collector, collector A `lastuse`/`discard`, and
    collector B `discard`.
    - Collector A `fill`/`use` is not offered.
    - ptxas certification of every new variant at sm_100a.
    - The new tests and the existing tcgen05 dialect tests pass on an
    sm_103a machine.
    - The full non-GPU Python suite passes.
---
 python/tvm_tirx/backend/cuda/ptx/table.py     | 39 ++++++++++++++++++--
 python/tvm_tirx/script/tirx.pyi               |  2 +-
 tests/python/tirx/codegen/test_ptx_addr.py    |  4 +--
 tests/python/tirx/codegen/test_ptx_dialect.py | 52 ++++++++++++++++++++++++++-
 4 files changed, 90 insertions(+), 7 deletions(-)

diff --git a/python/tvm_tirx/backend/cuda/ptx/table.py 
b/python/tvm_tirx/backend/cuda/ptx/table.py
index e304e53fb..6cccbcbad 100644
--- a/python/tvm_tirx/backend/cuda/ptx/table.py
+++ b/python/tvm_tirx/backend/cuda/ptx/table.py
@@ -11963,9 +11963,9 @@ _ENTRIES = [
     # NOT REGISTERED:
     # - `{, scale-input-d}`: an instruction-text immediate in [0, 15], no
     #   call site uses it.
-    # - Pre-9.4 sparse MMA forms without `.kind::ti16` or collector B, and
-    #   convolution ashift forms: no call sites. The shared-A dense form below
-    #   carries optional collector A for SM107 kernels.
+    # - Pre-9.4 sparse MMA forms without `.kind::ti16` or collector B: no call
+    #   sites. The shared-A dense form below carries optional collector A for
+    #   SM107 kernels; the dense convolution `.ashift` form follows it.
     #   PTX 9.4's ti16 dense/sparse/WS shapes and every SM107 collector-B
     #   shape are registered in `_PTX_94_ENTRIES`.
     # - The pre-9.4 .ws kinds without zero-column-mask-desc: every existing
@@ -12007,6 +12007,39 @@ _ENTRIES = [
         )
         for form in ("ss", "ts")
     ],
+    # PTX ISA 8.6 dense convolution MMA, A in Tensor Memory:
+    # `tcgen05.mma.cta_group.kind.ashift{.collector_a_usage}`. Collector B is
+    # optional in the manual; the spellings that carry it are owned by
+    # `tcgen05_mma_ashift_collector_b_ts` and `tcgen05_mma_collector_ab_ts`.
+    InstructionEntry(
+        name="tcgen05_mma_ashift_ts",
+        mnemonic="tcgen05",
+        slots=(
+            ModifierSlot("action", ("mma",)),
+            ModifierSlot("cta_group", ("cta_group::1", "cta_group::2")),
+            ModifierSlot("kind", ("kind::f16", "kind::tf32", "kind::f8f6f4", 
"kind::i8")),
+            ModifierSlot("ashift", ("ashift",)),
+            # .ashift cannot be combined with collector A fill/use.
+            ModifierSlot(
+                "collector_a",
+                ("collector::a::lastuse", "collector::a::discard"),
+                optional=True,
+            ),
+        ),
+        cert_arch="sm_100a",
+        operands=(
+            OperandSlot("d_tmem", kind="addr", space="tmem"),
+            OperandSlot("a_tmem", kind="addr", space="tmem"),
+            OperandSlot("b_desc", dtype="u64"),
+            OperandSlot("idesc", dtype="u32"),
+            OperandSlot(
+                "disable_output_lane",
+                dtype="u32",
+                lanes=_tcgen05_mma_mask_lanes,
+            ),
+            OperandSlot("enable_input_d", dtype="pred"),
+        ),
+    ),
     *[
         InstructionEntry(  # block-scaled: A/B scale factors live in tmem
             name=f"tcgen05_mma_block_scale_{form}",
diff --git a/python/tvm_tirx/script/tirx.pyi b/python/tvm_tirx/script/tirx.pyi
index 1106ae0fe..839f510ce 100644
--- a/python/tvm_tirx/script/tirx.pyi
+++ b/python/tvm_tirx/script/tirx.pyi
@@ -2213,7 +2213,7 @@ class _Chain_tanh:
     def __call__(self, *args: Any, pred: Any = None, preserve_dst: bool = 
False) -> None: ...
 
 class _Chain_tcgen05:
-    """`tcgen05` — 60 entries sharing this mnemonic; PTX puts their difference 
in the operand
+    """`tcgen05` — 61 entries sharing this mnemonic; PTX puts their difference 
in the operand
     list, so the call selects one. Shapes: (dst, ncols); (taddr, ncols); 
(mbar, cta_mask);
     (mbar); (*__operands); (d_tmem, a_desc, b_desc, idesc, enable_input_d); 
(d_tmem, a_desc,
     b_desc, idesc, enable_input_d, zero_col_mask); (d_tmem, a_tmem, b_desc, 
idesc,
diff --git a/tests/python/tirx/codegen/test_ptx_addr.py 
b/tests/python/tirx/codegen/test_ptx_addr.py
index fb8f29908..9de836e25 100644
--- a/tests/python/tirx/codegen/test_ptx_addr.py
+++ b/tests/python/tirx/codegen/test_ptx_addr.py
@@ -53,10 +53,10 @@ def test_ptx_addr_registration_and_table_capabilities():
     assert "tirx.ptx.addr" in CODEGEN_REGISTRY
 
     addresses = [slot for entry in TABLE.values() for slot in entry.operands 
if slot.kind == "addr"]
-    assert len(addresses) == 499
+    assert len(addresses) == 501
     assert sum(slot.allow_imm_offset for slot in addresses) == 309
     assert sum(slot.bracket is not None and not slot.allow_imm_offset for slot 
in addresses) == 85
-    assert sum(slot.space == "tmem" and not slot.allow_imm_offset for slot in 
addresses) == 105
+    assert sum(slot.space == "tmem" and not slot.allow_imm_offset for slot in 
addresses) == 107
 
 
 def test_ptx_addr_table_validation_rejects_wrong_operand_classes():
diff --git a/tests/python/tirx/codegen/test_ptx_dialect.py 
b/tests/python/tirx/codegen/test_ptx_dialect.py
index ca6694fb9..8e3bab379 100644
--- a/tests/python/tirx/codegen/test_ptx_dialect.py
+++ b/tests/python/tirx/codegen/test_ptx_dialect.py
@@ -2328,6 +2328,56 @@ def test_ptx_tcgen05_mma_ws_collectors_certify_sm100a():
     _assert_certifications_ok(by_arch)
 
 
[email protected]("collector", ("", "a::lastuse", "a::discard", 
"b::discard"))
+def test_ptx_tcgen05_mma_ashift_collector_optional(collector):
+    """PTX makes every collector qualifier optional on the convolution 
`.ashift` form."""
+    opcode = "tcgen05.mma.cta_group::1.kind::f16.ashift"
+    if collector:
+        opcode += f".collector::{collector}"
+
+    @T.function
+    def kernel():
+        T.device_entry(launch=T.cuda.LaunchConfig(grid=1, block=32))
+        T.ptx[opcode](
+            T.uint32(0),
+            T.uint32(0),
+            T.uint64(0),
+            T.uint32(0),
+            T.uint32(0),
+            T.uint32(0),
+            T.uint32(0),
+            T.uint32(0),
+            T.ptx.pred(T.uint32(0)),
+        )
+
+    src = _cuda_source(kernel, tvm_tirx.target.Target({"kind": "cuda", "arch": 
"sm_107a"}))
+    assert f"{opcode} [%0], [%1], %2, %3, " in src
+
+
+def test_ptx_tcgen05_mma_ashift_rejects_collector_a_fill():
+    from tvm_tirx.backend.cuda.ptx.render import render_variant
+    from tvm_tirx.backend.cuda.ptx.table import TABLE, variants
+
+    entry = TABLE["tcgen05_mma_ashift_ts"]
+    opcodes = {render_variant(entry, tokens)[0] for tokens in variants(entry)}
+    assert "tcgen05.mma.cta_group::1.kind::f16.ashift" in opcodes
+    assert not any("collector::a::fill" in v or "collector::a::use" in v for v 
in opcodes)
+
+
+@requires_nvcc
+def test_ptx_tcgen05_mma_ashift_certify_sm100a():
+    """The convolution `.ashift` form without collector B assembles on 
SM100a."""
+    from tvm_tirx.backend.cuda.ptx.render import render_variant
+    from tvm_tirx.backend.cuda.ptx.table import TABLE, renderings
+
+    by_arch = {}
+    entry = TABLE["tcgen05_mma_ashift_ts"]
+    for rendering in renderings(entry):
+        _, helper, source = render_variant(entry, *_as_render_args(rendering))
+        _append_certification(by_arch, "sm_100a", helper, source)
+    _assert_certifications_ok(by_arch)
+
+
 @pytest.mark.parametrize("mismatch", ("modifier", "operand"))
 def test_ptx_codegen_rejects_stale_table_layout(mismatch):
     """A traced call must not silently feed modifier strings to an old 
helper."""
@@ -4823,7 +4873,7 @@ def test_ptx_all_variants_render_unique():
             _, helper, _ = render_variant(entry, *args, 
addr_offsets=addr_offsets)
             assert helper not in names, f"address-offset helper name 
collision: {helper}"
             names.add(helper)
-    assert total == 791291  # update when the table grows or a ptxas gap 
narrows it
+    assert total == 791315  # update when the table grows or a ptxas gap 
narrows it
 
 
 def test_ptx_no_instruction_registered_twice():

Reply via email to