Skip to content

Commit 475b698

Browse files
committed
[TLE][MTHREADS] Support transposed operands in tle.wgmma
1 parent f7560f0 commit 475b698

6 files changed

Lines changed: 749 additions & 97 deletions

File tree

python/triton/experimental/tle/language/gpu/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@ def wgmma(
813813
trans_b = _require_wgmma_bool(trans_b, "trans_b")
814814
mthreads_enabled = mthreads_common.enabled()
815815
if mthreads_enabled:
816-
mthreads_wgmma.validate_operands(a, b, acc, trans_a, trans_b)
816+
a, b = mthreads_wgmma.prepare_operands(a, b, acc, trans_a, trans_b, _semantic)
817817
else:
818818
a, b = _canonicalize_wgmma_operands(a, b, trans_a, trans_b, _semantic)
819819

python/triton/experimental/tle/language/gpu/mthreads/wgmma.py

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
import triton.language as tl
2222

23+
from .. import types as tle
24+
2325

2426
def _unwrap(value):
2527
return value.value if isinstance(value, tl.constexpr) else value
@@ -36,9 +38,7 @@ def mark_auto_shared_layout(builder, handle) -> None:
3638
builder.mark_musa_tle_auto_shared_layout(handle)
3739

3840

39-
def validate_operands(a, b, acc, trans_a: bool, trans_b: bool) -> None:
40-
if trans_a or trans_b:
41-
raise ValueError("initial mthreads TLE wgmma does not support trans_a/trans_b")
41+
def validate_operands(a, b, acc) -> None:
4242
for name, operand in (("a", a), ("b", b)):
4343
operand_type = getattr(operand, "type", None)
4444
if not hasattr(operand_type, "storage"):
@@ -56,6 +56,38 @@ def validate_operands(a, b, acc, trans_a: bool, trans_b: bool) -> None:
5656
raise ValueError("mthreads TLE wgmma requires an f32 accumulator")
5757

5858

59+
def _transpose_smem_operand(operand, semantic):
60+
order = [1, 0]
61+
handle = semantic.builder.create_memdesc_trans(operand.handle, order)
62+
shape = [operand.type.shape[index] for index in order]
63+
64+
alloc_shape = operand.type.alloc_shape
65+
leading_rank = len(alloc_shape) - len(operand.type.shape)
66+
alloc_tail = alloc_shape[leading_rank:]
67+
transposed_alloc_shape = alloc_shape[:leading_rank] + [alloc_tail[index] for index in order]
68+
69+
layout = operand.type.layout.make_permute(order)
70+
return tle.buffered_tensor(
71+
handle,
72+
operand.dtype,
73+
shape,
74+
operand.type.storage,
75+
layout,
76+
semantic,
77+
alloc_shape=transposed_alloc_shape,
78+
)
79+
80+
81+
def prepare_operands(a, b, acc, trans_a: bool, trans_b: bool, semantic):
82+
"""Validate mthreads SQMMA operands and build descriptor transpose views."""
83+
validate_operands(a, b, acc)
84+
if trans_a:
85+
a = _transpose_smem_operand(a, semantic)
86+
if trans_b:
87+
b = _transpose_smem_operand(b, semantic)
88+
return a, b
89+
90+
5991
def validate_options(max_num_imprecise_acc: int, out_dtype) -> None:
6092
if max_num_imprecise_acc != 0:
6193
raise ValueError("mthreads TLE wgmma requires max_num_imprecise_acc=0")

0 commit comments

Comments
 (0)