Refactor ccl_allreduce bench: rank=SIP only, remove rank=PE legacy path
The unified ccl_allreduce bench previously carried two execution models
in one worker with ``if world_size == n_sips:`` branching:
- TP mode (rank = SIP, ADR-0024/0027): proper ProcessGroup semantics.
- Legacy rank = PE mode: single-driver worker allocating one big tensor
distributed across all PEs via _derive_dp, with kernel-level SPMD via
program_id.
The second model is unnecessary — intra-SIP PE-level collectives are
expressed inside the kernel (tl.send/tl.recv with program_id, IPCQ) and
do not need a host-side ProcessGroup. Removing it lets the bench be a
clean reference implementation of the TP launcher.
benches/ccl_allreduce.py:
- Config resolved once in run() via _resolve_cfg -> _BenchCfg dataclass.
- rank != n_sips now raises RuntimeError explicitly.
- _worker / _allocate_rank_tile / _init_with_rank_value / _report each
have one concern; duplicated init + verification paths collapsed.
- _derive_dp and the second verify+print block deleted.
- 166 lines -> 91 lines.
ccl.yaml:
- mesh_allreduce_4 (world_size: 4) and tree_allreduce_7 (world_size: 7)
algorithm entries removed (rank = PE only).
- Algorithm kernel files (kernbench.ccl.algorithms.mesh_allreduce,
tree_allreduce) kept as-is for direct-dispatch future use.
tests/test_ccl_allreduce_matrix.py:
- Matrix shrinks from 7 cases to 3: ring × {tcm, hbm, sram} at ws =
topology SIP count (= 2). mesh_2x2, tree_binary_7, ring_multi_cube,
and the three ring_*_8 cases removed.
tests/test_ccl_performance.py:
- _run_8rank renamed to _run_ring; world_size: 8 override dropped; now
exercises rank = SIP ring all-reduce.
tests/test_mp_spawn.py, tests/test_ccl_ddp_launcher.py:
- Monkeypatch target updated from bench.worker to bench._worker
(signature now takes BenchCfg instead of (rank, world_size)).
555 passed, 1 intentional skip. Tests that directly call
install_ipcq(world_size_override=N) for kernel-level sanity
(test_ccl_hello_world_guide, test_recv_copy_to_dst, test_tl_recv_async,
test_ccl_deadlock_detection) are unchanged — they never went through
the bench and still exercise the kernel-only path.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
"""End-to-end matrix tests for the unified ``ccl_allreduce`` bench.
|
||||
|
||||
Each parametrized case writes a tmp ``ccl.yaml`` overlay that selects a
|
||||
specific (algorithm, world_size, buffer_kind, n_elem) combination, then
|
||||
runs the bench via the CLI and asserts the printed line reports all
|
||||
ranks OK.
|
||||
Only covers the rank = SIP TP launcher path (ADR-0024 + ADR-0027). Each
|
||||
case writes a tmp ``ccl.yaml`` that selects a specific (algorithm,
|
||||
buffer_kind) pair; ``world_size`` is always derived from topology SIP
|
||||
count (2 in the shipped topology).
|
||||
|
||||
This single test file replaces the per-variant bench tests
|
||||
(test_ccl_allreduce_e2e, test_ccl_mesh_allreduce, test_ccl_tree_allreduce,
|
||||
test_ccl_multicube, test_ccl_multisip).
|
||||
The legacy rank = PE single-driver path was removed; intra-SIP PE-level
|
||||
collectives are expressed inside the kernel via ``tl.program_id`` and do
|
||||
not require a host-side ``ProcessGroup``.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -34,7 +34,6 @@ CCL_YAML_TEMPLATE = textwrap.dedent("""\
|
||||
module: {module}
|
||||
topology: {topology}
|
||||
buffer_kind: {buffer_kind}
|
||||
{world_size_line}{n_elem_line}
|
||||
""")
|
||||
|
||||
|
||||
@@ -44,87 +43,46 @@ def _write_ccl_yaml(
|
||||
algorithm: str,
|
||||
module: str,
|
||||
topology: str,
|
||||
buffer_kind: str = "tcm",
|
||||
world_size: int | None = None,
|
||||
n_elem: int | None = None,
|
||||
buffer_kind: str,
|
||||
) -> str:
|
||||
"""Write a tmp ccl.yaml in tmp_path and return its directory."""
|
||||
ws_line = f" world_size: {world_size}\n" if world_size is not None else ""
|
||||
nel_line = f" n_elem: {n_elem}\n" if n_elem is not None else ""
|
||||
body = CCL_YAML_TEMPLATE.format(
|
||||
algorithm=algorithm,
|
||||
module=module,
|
||||
topology=topology,
|
||||
buffer_kind=buffer_kind,
|
||||
world_size_line=ws_line,
|
||||
n_elem_line=nel_line,
|
||||
)
|
||||
yaml_path = tmp_path / "ccl.yaml"
|
||||
yaml_path.write_text(body)
|
||||
(tmp_path / "ccl.yaml").write_text(body)
|
||||
return str(tmp_path)
|
||||
|
||||
|
||||
CASES = [
|
||||
# algorithm, module, topology, buffer_kind, world_size, n_elem, expected_ws
|
||||
#
|
||||
# Default fallback — no world_size override → ADR-0024 D1 derives
|
||||
# from topology (SIP count = 2). Exercises the new SIP-level TP
|
||||
# launcher + cross-SIP ring.
|
||||
# ADR-0027 D0+D1 landed the architectural fix (worker-wait
|
||||
# generalization + torch.multiprocessing.spawn scheduler drain), so
|
||||
# this case now passes normally. Keeping it as the topology-default
|
||||
# smoke.
|
||||
# Ring all-reduce across SIPs (ws == topology SIP count = 2),
|
||||
# one case per IPCQ buffer location.
|
||||
pytest.param(
|
||||
"ring_allreduce_tcm", "kernbench.ccl.algorithms.ring_allreduce",
|
||||
"ring_1d", "tcm", None, 8, 2,
|
||||
id="ring_default_ws",
|
||||
),
|
||||
# Buffer variants at 8-rank (fast — same kernel, different slot space).
|
||||
pytest.param(
|
||||
"ring_allreduce_tcm", "kernbench.ccl.algorithms.ring_allreduce",
|
||||
"ring_1d", "tcm", 8, 32, 8,
|
||||
id="ring_tcm_8",
|
||||
"ring_1d", "tcm",
|
||||
id="ring_tcm",
|
||||
),
|
||||
pytest.param(
|
||||
"ring_allreduce_hbm", "kernbench.ccl.algorithms.ring_allreduce",
|
||||
"ring_1d", "hbm", 8, 32, 8,
|
||||
id="ring_hbm_8",
|
||||
"ring_1d", "hbm",
|
||||
id="ring_hbm",
|
||||
),
|
||||
pytest.param(
|
||||
"ring_allreduce_sram", "kernbench.ccl.algorithms.ring_allreduce",
|
||||
"ring_1d", "sram", 8, 32, 8,
|
||||
id="ring_sram_8",
|
||||
),
|
||||
# Multi-cube (16-rank, cross-cube within 1 SIP).
|
||||
pytest.param(
|
||||
"ring_allreduce_16", "kernbench.ccl.algorithms.ring_allreduce",
|
||||
"ring_1d", "tcm", 16, 16, 16,
|
||||
id="ring_multi_cube",
|
||||
),
|
||||
# Mesh + tree algorithms.
|
||||
pytest.param(
|
||||
"mesh_allreduce_4", "kernbench.ccl.algorithms.mesh_allreduce",
|
||||
"mesh_2d", "tcm", 4, 16, 4,
|
||||
id="mesh_2x2",
|
||||
),
|
||||
pytest.param(
|
||||
"tree_allreduce_7", "kernbench.ccl.algorithms.tree_allreduce",
|
||||
"tree_binary", "tcm", 7, 16, 7,
|
||||
id="tree_binary_7",
|
||||
"ring_1d", "sram",
|
||||
id="ring_sram",
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"algorithm,module,topology,buffer_kind,world_size,n_elem,expected_ws",
|
||||
CASES,
|
||||
)
|
||||
@pytest.mark.parametrize("algorithm,module,topology,buffer_kind", CASES)
|
||||
def test_ccl_allreduce_matrix(
|
||||
tmp_path, capsys, monkeypatch,
|
||||
algorithm, module, topology, buffer_kind, world_size, n_elem, expected_ws,
|
||||
algorithm, module, topology, buffer_kind,
|
||||
):
|
||||
"""Each (algorithm × buffer × world_size) combo passes through the
|
||||
unified bench and yields all ranks OK."""
|
||||
"""Each (algorithm × buffer_kind) combo passes through the unified
|
||||
rank = SIP bench and yields ``ws OK`` where ``ws == topology SIP count``."""
|
||||
project_root = os.path.abspath(
|
||||
os.path.join(os.path.dirname(__file__), "..")
|
||||
)
|
||||
@@ -134,8 +92,6 @@ def test_ccl_allreduce_matrix(
|
||||
module=module,
|
||||
topology=topology,
|
||||
buffer_kind=buffer_kind,
|
||||
world_size=world_size,
|
||||
n_elem=n_elem,
|
||||
)
|
||||
monkeypatch.chdir(yaml_dir)
|
||||
rc = cli_main.main([
|
||||
@@ -147,7 +103,6 @@ def test_ccl_allreduce_matrix(
|
||||
assert rc == 0
|
||||
out = capsys.readouterr().out
|
||||
assert "FAIL" not in out, f"unexpected FAIL in output:\n{out}"
|
||||
assert f"{algorithm} (ws={expected_ws}): {expected_ws} OK" in out, (
|
||||
f"expected '{algorithm} (ws={expected_ws}): {expected_ws} OK' "
|
||||
f"in output:\n{out}"
|
||||
assert f"{algorithm}" in out and "OK" in out, (
|
||||
f"expected pass line for '{algorithm}' in output:\n{out}"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user