Skip to content

Commit 5dce3bf

Browse files
committed
one-shot limit
1 parent 5a9b63b commit 5dce3bf

4 files changed

Lines changed: 33 additions & 7 deletions

File tree

benchmark/ops/bench_matmul_all_reduce.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from tritonblas.matmul import persistent_matmul_lt
1313

1414

15-
_MAX_ONE_SHOT_INBOX_ELEMENTS = 2**32
15+
_MAX_ONE_SHOT_INBOX_ELEMENTS = 2**31
1616

1717

1818
@bench.register
@@ -106,9 +106,9 @@ def matmul_all_reduce(state, ctx):
106106
world_size = ctx.get_num_ranks()
107107
rank = ctx.get_rank()
108108

109-
if variant == "one_shot" and world_size * M * N >= _MAX_ONE_SHOT_INBOX_ELEMENTS:
109+
if variant == "one_shot" and world_size * M * N > _MAX_ONE_SHOT_INBOX_ELEMENTS:
110110
state.skip(
111-
"one_shot requires world_size * M * N < 2**32 elements "
111+
"one_shot requires world_size * M * N <= 2**31 elements "
112112
f"(got {world_size * M * N})"
113113
)
114114

benchmark/ops/bench_matmul_all_reduce_copy_engine.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
from tritonblas.matmul import _make_matmul_selector
1717

1818

19+
_MAX_ONE_SHOT_INBOX_ELEMENTS = 2**31
20+
21+
1922
def _make_selector(M: int, N: int, K: int, dtype: torch.dtype, device: torch.device):
2023
return _make_matmul_selector(
2124
M,
@@ -44,6 +47,11 @@ def _register_copy_engine(state, ctx, *, variant: str) -> None:
4447
state.skip(f"N={N} must be divisible by block_size_n={selector.block_n}")
4548
if K % selector.block_k != 0:
4649
state.skip(f"K={K} must be divisible by block_size_k={selector.block_k}")
50+
if variant == "one_shot" and world_size * M * N > _MAX_ONE_SHOT_INBOX_ELEMENTS:
51+
state.skip(
52+
"one_shot requires world_size * M * N <= 2**31 elements "
53+
f"(got {world_size * M * N})"
54+
)
4755

4856
torch.manual_seed(123 + rank)
4957
A = ctx.randn((M, K), dtype=dtype)

iris/ops/matmul_all_reduce.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424

2525
_SUPPORTED_VARIANTS = ("one_shot", "two_shot")
26-
_MAX_ONE_SHOT_INBOX_ELEMENTS = 2**32
26+
_MAX_ONE_SHOT_INBOX_ELEMENTS = 2**31
2727

2828

2929
@triton.jit()
@@ -371,9 +371,9 @@ def _validate_variant(variant: str):
371371

372372
def _validate_one_shot_inbox_size(M: int, N: int, world_size: int):
373373
inbox_elements = world_size * M * N
374-
if inbox_elements >= _MAX_ONE_SHOT_INBOX_ELEMENTS:
374+
if inbox_elements > _MAX_ONE_SHOT_INBOX_ELEMENTS:
375375
raise ValueError(
376-
"matmul_all_reduce one_shot requires world_size * M * N < 2**32 elements "
376+
"matmul_all_reduce one_shot requires world_size * M * N <= 2**31 elements "
377377
"because the current publish/reduce kernels use 32-bit element offsets; "
378378
f"got world_size={world_size}, M={M}, N={N}, elements={inbox_elements}."
379379
)

iris/ops/matmul_all_reduce_copy_engine.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
from .tritonblas_launch_wave_schedule import build_launch_wave_plan
2525

2626

27+
_MAX_ONE_SHOT_INBOX_ELEMENTS = 2**31
28+
29+
2730
@triton.jit()
2831
def _partitioned_xcd_matmul_kernel(
2932
A,
@@ -423,6 +426,16 @@ def _ceil_div(value: int, divisor: int) -> int:
423426
return (value + divisor - 1) // divisor
424427

425428

429+
def _validate_one_shot_inbox_size(M: int, N: int, world_size: int):
430+
inbox_elements = world_size * M * N
431+
if inbox_elements > _MAX_ONE_SHOT_INBOX_ELEMENTS:
432+
raise ValueError(
433+
"matmul_all_reduce_copy_engine one_shot requires world_size * M * N <= 2**31 elements "
434+
"because the current local-reduce kernels use 32-bit element offsets; "
435+
f"got world_size={world_size}, M={M}, N={N}, elements={inbox_elements}."
436+
)
437+
438+
426439
def _partitioned_xcd_gemm_num_sms(launch: dict, world_size: int) -> int:
427440
cached = launch.get("gemm_num_sms")
428441
if cached is not None:
@@ -916,9 +929,11 @@ def matmul_all_reduce_copy_engine_preamble(
916929
dtype = A.dtype
917930
world_size = shmem.get_num_ranks()
918931

919-
# Validate config
920932
config.validate(world_size=world_size)
921933

934+
if config.all_reduce_variant == "one_shot":
935+
_validate_one_shot_inbox_size(M, N, world_size)
936+
922937
if config.all_reduce_variant == "two_shot" and M % world_size != 0:
923938
raise ValueError(
924939
"matmul_all_reduce_copy_engine two_shot requires M to be divisible by world_size "
@@ -1047,6 +1062,9 @@ def matmul_all_reduce_copy_engine(
10471062

10481063
config.validate(world_size=world_size)
10491064

1065+
if config.all_reduce_variant == "one_shot":
1066+
_validate_one_shot_inbox_size(M, N, world_size)
1067+
10501068
# Prepare workspace if needed
10511069
if workspace is None:
10521070
workspace = matmul_all_reduce_copy_engine_preamble(

0 commit comments

Comments
 (0)