2020
2121import triton .language as tl
2222
23+ from .. import types as tle
24+
2325
2426def _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+
5991def 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