Skip to content

Commit d4b4b49

Browse files
authored
[CLI] Recover ssd and blockwise group gemm perf (#3344)
* cggemm * cggemm * mggemm * quick fix for 13.3 * fix ssd * typo * update
1 parent c88b280 commit d4b4b49

4 files changed

Lines changed: 18 additions & 31 deletions

File tree

examples/python/CuTeDSL/cute/blackwell/kernel/attention/mamba2_ssd/mamba2_ssd.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,10 @@ def __init__(
142142
)
143143

144144
# Number of registers used by each warp
145-
self.num_regs_uniform_warps = 24
145+
self.num_regs_uniform_warps = 32
146146
self.num_regs_pre_inter_warps = 168
147147
self.num_regs_pre_intra_warps = 208
148-
self.num_regs_epilogue_warps = 112
148+
self.num_regs_epilogue_warps = 104
149149

150150
# Shared storage
151151
self.shared_storage = None

examples/python/CuTeDSL/cute/blackwell/kernel/blockwise_gemm/blockwise_gemm.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2706,18 +2706,6 @@ def run(
27062706
torch_stream = torch.cuda.current_stream()
27072707
# Get the raw stream pointer as a CUstream
27082708
current_stream = cuda.CUstream(torch_stream.cuda_stream)
2709-
# try to check CUDA version to decide the opt level
2710-
try:
2711-
from cutlass import CUDA_VERSION
2712-
2713-
opt_level = (
2714-
3
2715-
if CUDA_VERSION.major < 13
2716-
or (CUDA_VERSION.major == 13 and CUDA_VERSION.minor < 1)
2717-
else 2
2718-
)
2719-
except ImportError:
2720-
opt_level = 3
27212709
# Compile gemm kernel
27222710
compiled_gemm = cute.compile(
27232711
gemm,
@@ -2728,7 +2716,7 @@ def run(
27282716
sfb_tensor,
27292717
max_active_clusters,
27302718
current_stream,
2731-
options=f"--opt-level {opt_level}",
2719+
options=f"--opt-level=2" if cutlass.__version__[0:3]=="4.6" else "",
27322720
)
27332721

27342722
# Execution

examples/python/CuTeDSL/cute/blackwell/kernel/blockwise_gemm/contiguous_grouped_gemm.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,13 +1664,11 @@ def kernel(
16641664
tTR_rSFA_subtile = tTR_rSFA[(None, None, None, subtile_idx)]
16651665
tTR_rSFB_subtile = tTR_rSFB[(None, None, None, subtile_idx)]
16661666

1667-
acc_vec = tTR_rAcc.load()
1668-
final_vec = tTR_rAcc_subtile.load()
1669-
scale_a = tTR_rSFA_subtile.load()
1670-
scale_b = tTR_rSFB_subtile.load()
1671-
scale = scale_a * scale_b
1672-
final_vec = acc_vec * scale + final_vec
1673-
tTR_rAcc_subtile.store(final_vec.to(self.acc_dtype))
1667+
scale = cute.make_rmem_tensor(tTR_rSFA_subtile.shape, self.acc_dtype)
1668+
for fma_idx in cutlass.range_constexpr(cute.size(scale)):
1669+
scale[fma_idx] = tTR_rSFA_subtile[fma_idx] * tTR_rSFB_subtile[fma_idx]
1670+
for fma_idx in cutlass.range_constexpr(cute.size(tTR_rAcc_subtile)):
1671+
tTR_rAcc_subtile[fma_idx] = tTR_rAcc[fma_idx] * scale[fma_idx] + tTR_rAcc_subtile[fma_idx]
16741672

16751673
#
16761674
# Async arrive accumulator buffer empty
@@ -3041,4 +3039,3 @@ def parse_comma_separated_ints(s: str) -> Tuple[int, ...]:
30413039
args.use_cold_l2,
30423040
args.fixed_m,
30433041
)
3044-
print("PASS")

examples/python/CuTeDSL/cute/blackwell/kernel/blockwise_gemm/masked_grouped_gemm.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,6 @@ def kernel(
875875
cute.slice_(self.cta_tile_shape_mnk, (0, None, None)),
876876
(None, None, None),
877877
)
878-
k_tile_cnt = cute.size(gA_mkl, mode=[3])
879878

880879
#
881880
# Partition global tensor for TiledMMA_A/B/C
@@ -1081,6 +1080,7 @@ def kernel(
10811080
is_valid_tile = cutlass.Boolean(1)
10821081
is_valid_tile = tile_info[3] == 1
10831082

1083+
k_tile_cnt = cute.arch.make_warp_uniform(cute.size(gA_mkl, mode=[3]))
10841084
while is_valid_tile:
10851085
mma_tile_coord_mnl = (
10861086
tile_info[0] // cute.size(tiled_mma.thr_id.shape),
@@ -1200,6 +1200,7 @@ def kernel(
12001200
is_valid_tile = cutlass.Boolean(1)
12011201
is_valid_tile = tile_info[3] == 1
12021202

1203+
k_tile_cnt = cute.arch.make_warp_uniform(cute.size(gA_mkl, mode=[3]))
12031204
while is_valid_tile:
12041205
#
12051206
# Prepare the mask for scaleA/scaleB
@@ -1389,6 +1390,7 @@ def kernel(
13891390
is_valid_tile = cutlass.Boolean(1)
13901391
is_valid_tile = tile_info[3] == 1
13911392

1393+
k_tile_cnt = cute.arch.make_warp_uniform(cute.size(gA_mkl, mode=[3]))
13921394
while is_valid_tile:
13931395
# Peek (try_wait) AB buffer full for k_tile = 0
13941396
ab_consumer_state.reset_count()
@@ -1579,6 +1581,7 @@ def kernel(
15791581
is_valid_tile = cutlass.Boolean(1)
15801582
is_valid_tile = tile_info[3] == 1
15811583

1584+
k_tile_cnt = cute.arch.make_warp_uniform(cute.size(gA_mkl, mode=[3]))
15821585
while is_valid_tile:
15831586
# initialize the final accumulator
15841587
tTR_rAcc_final.fill(0.0)
@@ -1666,13 +1669,11 @@ def kernel(
16661669
tTR_rSFA_subtile = tTR_rSFA[(None, None, None, subtile_idx)]
16671670
tTR_rSFB_subtile = tTR_rSFB[(None, None, None, subtile_idx)]
16681671

1669-
acc_vec = tTR_rAcc.load()
1670-
final_vec = tTR_rAcc_subtile.load()
1671-
scale_a = tTR_rSFA_subtile.load()
1672-
scale_b = tTR_rSFB_subtile.load()
1673-
scale = scale_a * scale_b
1674-
final_vec = acc_vec * scale + final_vec
1675-
tTR_rAcc_subtile.store(final_vec.to(self.acc_dtype))
1672+
scale = cute.make_rmem_tensor(tTR_rSFA_subtile.shape, self.acc_dtype)
1673+
for fma_idx in cutlass.range_constexpr(cute.size(scale)):
1674+
scale[fma_idx] = tTR_rSFA_subtile[fma_idx] * tTR_rSFB_subtile[fma_idx]
1675+
for fma_idx in cutlass.range_constexpr(cute.size(tTR_rAcc_subtile)):
1676+
tTR_rAcc_subtile[fma_idx] = tTR_rAcc[fma_idx] * scale[fma_idx] + tTR_rAcc_subtile[fma_idx]
16761677

16771678
#
16781679
# Async arrive accumulator buffer empty
@@ -1828,6 +1829,7 @@ def kernel(
18281829

18291830
num_prev_subtiles = cutlass.Int32(0)
18301831

1832+
k_tile_cnt = cute.arch.make_warp_uniform(cute.size(gA_mkl, mode=[3]))
18311833
while is_valid_tile:
18321834
mma_tile_coord_mnl = (
18331835
tile_info[0] // cute.size(tiled_mma.thr_id.shape),

0 commit comments

Comments
 (0)