|
1 | 1 | # Copyright (c) 2025, Tri Dao. |
2 | 2 |
|
3 | | -from typing import Type, Union, Optional |
| 3 | +from typing import Literal, Type, Union, Optional |
4 | 4 |
|
5 | 5 | import cutlass |
6 | 6 | import cutlass.cute as cute |
@@ -42,6 +42,38 @@ def make_smem_layout( |
42 | 42 | make_smem_layout_epi = make_smem_layout |
43 | 43 |
|
44 | 44 |
|
| 45 | +def make_tiled_mma( |
| 46 | + a_dtype: Type[Numeric], |
| 47 | + a_major: Literal["K", "MN"], |
| 48 | + b_major: Literal["K", "MN"], |
| 49 | + tiler_n: int, |
| 50 | + source: Literal["SS", "RS"] = "SS", |
| 51 | + atom_layout_mnk: tuple = (1, 1, 1), |
| 52 | + swap_AB: bool = False, |
| 53 | + b_dtype: Optional[Type[Numeric]] = None, |
| 54 | + acc_dtype: Type[Numeric] = Float32, |
| 55 | +) -> cute.TiledMma: |
| 56 | + """`b_dtype` defaults to `a_dtype`; pass it for mixed-precision MMAs (e.g. fp8). |
| 57 | + `acc_dtype` defaults to Float32.""" |
| 58 | + if b_dtype is None: |
| 59 | + b_dtype = a_dtype |
| 60 | + mode = {"K": warpgroup.OperandMajorMode.K, "MN": warpgroup.OperandMajorMode.MN} |
| 61 | + a_mode, b_mode = mode[a_major], mode[b_major] |
| 62 | + if swap_AB: |
| 63 | + a_mode, b_mode = b_mode, a_mode |
| 64 | + a_source = warpgroup.OperandSource.RMEM if source == "RS" else warpgroup.OperandSource.SMEM |
| 65 | + return sm90_utils_og.make_trivial_tiled_mma( |
| 66 | + a_dtype, |
| 67 | + b_dtype, |
| 68 | + a_mode, |
| 69 | + b_mode, |
| 70 | + acc_dtype, |
| 71 | + atom_layout_mnk=atom_layout_mnk, |
| 72 | + tiler_mn=(64, tiler_n), |
| 73 | + a_source=a_source, |
| 74 | + ) |
| 75 | + |
| 76 | + |
45 | 77 | @dsl_user_op |
46 | 78 | def partition_for_epilogue( |
47 | 79 | cT: cute.Tensor, |
|
0 commit comments