Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions python/mori/ops/dispatch_combine_v2/flydsl_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,10 @@ def __init__(self, cfg: EpDispatchCombineConfig, comm):
self.total_recv = torch.zeros(1, dtype=torch.int32, device=device)
self.combine_barrier = torch.zeros(1, dtype=torch.int32, device=device)
# Per-block xdb flag counters for the gather combine entry barrier: one
# i64 per block, fixed at xdb_flag_slots (== CU count, the max combine
# block_num). Every block owns a private counter and block 0 fills the
# unused tail so all stay in lockstep across calls with different block_num.
# i64 per block, fixed at xdb_flag_slots (combine block_num is clamped
# to it, see tuning_configs._MAX_COMBINE_BLOCKS). Every block owns a
# private counter and block 0 fills the unused tail so all stay in
# lockstep across calls with different block_num.
self.cross_device_flag = torch.ones(
xdb_flag_slots, dtype=torch.int64, device=device
)
Expand Down
5 changes: 3 additions & 2 deletions python/mori/ops/dispatch_combine_v2/intranode_kernels.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,8 +555,9 @@ def zero_accum():


# Fixed size of the per-block xdb flag counter array for the gather combine entry
# barrier: one i64 per block. 256 == the CU count (the max combine block_num), so
# block_num never exceeds it. Deliberately a hard-coded compile-time constant.
# barrier: one i64 per block. combine block_num must not exceed it: the untuned
# fallback clamps to tuning_configs._MAX_COMBINE_BLOCKS, which must equal this.
# Deliberately a hard-coded compile-time constant.
xdb_flag_slots = 256


Expand Down
15 changes: 11 additions & 4 deletions python/mori/ops/dispatch_combine_v2/tuning_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,21 @@ def _device_key():
return None


# Capacity of the per-block xdb flag array in intranode_kernels (xdb_flag_slots):
# a combine block_num above it fails at op construction. Kept here because this
# module must not import the kernels (flydsl); test_tuning_configs.py checks the
# two stay equal.
_MAX_COMBINE_BLOCKS = 256


def _cu_scaled_default():
"""Untuned fallback: ~1 block/CU for combine (<= CU count), many warps for
dispatch, few warps for combine, no per-token schedule (single-shot). Used
for devices without a measured table."""
"""Untuned fallback: ~1 block/CU for combine (<= CU count, and <=
_MAX_COMBINE_BLOCKS), many warps for dispatch, few warps for combine, no
per-token schedule (single-shot). Used for devices without a measured table."""
cu = _cu_count() or 80
return dict(
dispatch_block_num=cu,
combine_block_num=cu,
combine_block_num=min(cu, _MAX_COMBINE_BLOCKS),
warp_num_per_block=16,
combine_warp_num_per_block=4,
schedule=None,
Expand Down
54 changes: 54 additions & 0 deletions tests/python/ops/dispatch_combine_v2/test_tuning_configs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Copyright © Advanced Micro Devices, Inc. All rights reserved.
#
# MIT License
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
"""Host-only checks of the flydsl EP v2 geometry lookup (no GPU needed).

The untuned fallback sizes combine blocks from the CU count. A part with more
CUs than the xdb flag array has slots used to fail at op construction.
"""

import pytest

from mori.ops.dispatch_combine_v2 import tuning_configs as tc


@pytest.mark.parametrize("cu, expected", [(80, 80), (256, 256), (304, 256)])
def test_untuned_combine_blocks_fit_flag_slots(monkeypatch, cu, expected):
monkeypatch.setattr(tc, "_cu_count", lambda: cu)
monkeypatch.setattr(tc, "_device_key", lambda: None)
cfg = tc.lookup(8, 7168, 8)
assert cfg["combine_block_num"] == expected
assert cfg["dispatch_block_num"] == cu # only combine has the slot limit


def test_device_without_default_uses_the_clamped_fallback(monkeypatch):
# A known device whose default is None takes the same CU-scaled path.
monkeypatch.setattr(tc, "_cu_count", lambda: 304)
monkeypatch.setattr(tc, "_device_key", lambda: "tuned_none")
monkeypatch.setitem(tc._DEVICES, "tuned_none", (None, {}))
assert tc.lookup(2, 7168, 8)["combine_block_num"] <= tc._MAX_COMBINE_BLOCKS


def test_max_combine_blocks_matches_kernel_flag_slots():
pytest.importorskip("flydsl")
from mori.ops.dispatch_combine_v2.intranode_kernels import xdb_flag_slots

assert tc._MAX_COMBINE_BLOCKS == xdb_flag_slots
Loading