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
2 changes: 1 addition & 1 deletion scripts/build_deb.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
AARCH64 = 183
# Explicit runtime manifest for the default slim .deb payload.
RUNTIME_TOP_DIRS = frozenset({
"runtime", "spark_transport", "integrations", "packaging",
"runtime", "spark_transport", "sparkring_fabric", "integrations", "packaging",
"profiles", "recipes", "scripts", "third_party",
})
RUNTIME_ROOT_FILES = frozenset({
Expand Down
2 changes: 1 addition & 1 deletion scripts/check_repository_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def validate_locked_profile_assets(root=ROOT):

def validate_imports(root=ROOT):
paths = []
for directory in ('runtime', 'integrations', 'scripts', 'spark_transport/fabric'):
for directory in ('runtime', 'integrations', 'scripts', 'spark_transport/fabric', 'sparkring_fabric'):
paths.extend((root/directory).rglob('*.py'))
for path in paths:
tree = ast.parse(path.read_text(encoding='utf-8-sig'), filename=str(path))
Expand Down
57 changes: 47 additions & 10 deletions spark_transport/libsircl/tests/test_site_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,21 @@
from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]
PACKAGE = os.environ.get("SIRCL_PACKAGE", "")
REPO_ROOT = ROOT.parents[1]
FABRIC_PACKAGE = str(REPO_ROOT / "sparkring_fabric")
SHARE = 393216 # 75 % of SIRCL's 512 KiB hairpin queue (routes.RELAY_QUEUE_SHARE x DEFAULT_HAIRPIN_QUEUE)


def _clean_env() -> dict[str, str]:
"""Environment with no spark_transport/sircl on PYTHONPATH or SIRCL_PACKAGE."""
env = {k: v for k, v in os.environ.items() if k not in ("PYTHONPATH", "SIRCL_PACKAGE")}
env["PYTHONIOENCODING"] = "utf-8"
return env


def plan(*arguments: str) -> dict:
environment = dict(os.environ, PYTHONPATH=PACKAGE, PYTHONIOENCODING="utf-8")
process = subprocess.run([sys.executable, str(ROOT / "tools" / "site_routes.py"), *arguments, "--json"],
env=environment, capture_output=True, text=True, timeout=120)
env=_clean_env(), capture_output=True, text=True, timeout=120)
if process.returncode:
raise AssertionError(f"site_routes.py {' '.join(arguments)}: {process.stderr}")
return json.loads(process.stdout)
Expand All @@ -52,13 +59,17 @@ def windows(text: str) -> dict[int, list[int]]:
return found


@unittest.skipUnless(PACKAGE and (Path(PACKAGE) / "sparkring_sircl").is_dir(),
"SIRCL_PACKAGE does not name a directory holding sparkring_sircl")
@unittest.skipUnless((Path(FABRIC_PACKAGE) / "sparkring_fabric").is_dir(),
"sparkring_fabric package directory is not present")
class SiteRoutesP2PTests(unittest.TestCase):
@classmethod
def setUpClass(cls):
sys.path.insert(0, PACKAGE)
from sparkring_sircl import routes
if FABRIC_PACKAGE not in sys.path:
sys.path.insert(0, FABRIC_PACKAGE)
existing = sys.modules.get("sparkring_fabric")
if existing is not None and getattr(existing, "__file__", None) is None:
del sys.modules["sparkring_fabric"]
from sparkring_fabric import routes

cls.routes = routes

Expand Down Expand Up @@ -157,7 +168,7 @@ def test_session_shares_outside_zero_to_one_are_refused(self):
with self.subTest(value=value):
process = subprocess.run([sys.executable, str(ROOT / "tools" / "site_routes.py"), "--layout", "ring:8",
"--session-share", value],
env=dict(os.environ, PYTHONPATH=PACKAGE), capture_output=True, text=True,
env=_clean_env(), capture_output=True, text=True,
timeout=120)
self.assertEqual(process.returncode, 2)
self.assertIn("--session-share", process.stderr)
Expand Down Expand Up @@ -197,7 +208,7 @@ def test_a_plan_that_overfills_a_relay_queue_is_refused(self):
one relay queue then hold more than its share, and the tool refuses the plan, naming the queue."""
process = subprocess.run([sys.executable, str(ROOT / "tools" / "site_routes.py"), "--layout", "path:0-7",
"--lanes", "2", "--chunk", "65536"],
env=dict(os.environ, PYTHONPATH=PACKAGE), capture_output=True, text=True,
env=_clean_env(), capture_output=True, text=True,
timeout=120)
self.assertEqual(process.returncode, 1, process.stdout)
self.assertIn("above its share of 393216", process.stderr)
Expand Down Expand Up @@ -236,12 +247,38 @@ def test_ring_only_emits_neighbor_routes_without_relays(self):
def test_ring_only_refuses_relayed_closing_edge(self):
process = subprocess.run([sys.executable, str(ROOT / "tools" / "site_routes.py"), "--layout", "path:0-3",
"--lanes", "2", "--ring-only"],
env=dict(os.environ, PYTHONPATH=PACKAGE), capture_output=True, text=True,
env=_clean_env(), capture_output=True, text=True,
timeout=120)
self.assertEqual(process.returncode, 1, process.stdout)
self.assertIn("--ring-only", process.stderr)
self.assertEqual(process.stdout, "")

def test_runs_without_sparkring_sircl_on_sys_path(self):
"""site_routes.py depends only on sparkring_fabric and never imports sparkring_sircl."""
script = (
"import importlib.util, json, sys\n"
"class BlockSircl:\n"
" def find_spec(self, fullname, path, target=None):\n"
" if fullname == 'sparkring_sircl' or fullname.startswith('sparkring_sircl.'):\n"
" raise AssertionError(f'unexpected import of {fullname}')\n"
" return None\n"
"sys.meta_path.insert(0, BlockSircl())\n"
"assert not any('spark_transport/sircl' in p.replace('\\\\', '/') for p in sys.path)\n"
f"spec = importlib.util.spec_from_file_location('site_routes', {str(ROOT / 'tools' / 'site_routes.py')!r})\n"
"mod = importlib.util.module_from_spec(spec)\n"
"spec.loader.exec_module(mod)\n"
"rc = mod.main(['--layout', 'ring:8', '--lanes', '2', '--json'])\n"
"assert rc == 0, rc\n"
"assert 'sparkring_sircl' not in sys.modules\n"
"assert 'sparkring_fabric.routes' in sys.modules\n"
)
process = subprocess.run([sys.executable, "-I", "-c", script], env=_clean_env(),
capture_output=True, text=True, timeout=120)
self.assertEqual(process.returncode, 0, process.stderr)
payload = json.loads(process.stdout)
self.assertEqual(payload["layout"], "ring:8")
self.assertEqual(len(payload["ranks"]), 8)


if __name__ == "__main__":
unittest.main(verbosity=2)
56 changes: 38 additions & 18 deletions spark_transport/libsircl/tools/site_routes.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/env python3
"""Per-rank libsircl settings of a SIRCL layout, from SIRCL's own route planner.
"""Per-rank libsircl settings of a fabric layout, from sparkring_fabric's route planner.

For a layout such as ``path:0-1``, ``path:0-3`` or ``ring:8`` and a lane count, SIRCL's routes module
(``sparkring_sircl.routes``: ``Layout.parse``, ``derive_routes``, ``chain_order``, ``forward_windows``,
``ring_window`` and ``ring_queues``) gives every rank's route map, the chain order of cable neighbors,
the forward window of every lane that crosses relays and the plan of the ring that closes the chain, and
SIRCL's point-to-point budget (``sparkring_sircl.p2p.budget``: ``LaneSet``, ``session_reservation``,
``allocate``) the window of every relayed lane of a point-to-point channel. This tool prints them as
libsircl's environment, one line per rank (rank r of the layout runs at libsircl position r):
For a layout such as ``path:0-1``, ``path:0-3`` or ``ring:8`` and a lane count, ``sparkring_fabric.routes``
(``Layout.parse``, ``derive_routes``, ``chain_order``, ``forward_windows``, ``ring_window`` and ``ring_queues``)
gives every rank's route map, the chain order of cable neighbors, the forward window of every lane that crosses
relays and the plan of the ring that closes the chain, and ``sparkring_fabric.budget`` (``LaneSet``,
``session_reservation``, ``allocate``) gives the window of every relayed lane of a point-to-point channel.
This tool has zero dependency on ``sparkring_sircl`` and prints them as libsircl's environment, one line per
rank (rank r of the layout runs at libsircl position r):

LIBSIRCL_POSITION=r SIRCL_PEER_ROUTES=... LIBSIRCL_CHAIN_ORDER=... LIBSIRCL_RELAYED_LANES=...
LIBSIRCL_FORWARD_WINDOWS=... LIBSIRCL_RING_WINDOW=... LIBSIRCL_P2P_WINDOWS=...
Expand Down Expand Up @@ -60,15 +60,17 @@
layout whose ring closes over direct cables (zero relay rules, zero diagonal routes or queue pairs). Layouts
whose ring has a relayed edge (such as ``path:0-3``) are refused with exit status 1.

Usage (SIRCL's package on PYTHONPATH, or installed):
Usage (runs uninstalled from a repository checkout, or with sparkring-fabric installed):
python3 tools/site_routes.py --layout ring:8 --lanes 2 [--ring-only] [--p2p-reserve session|none]
[--ring-schedules] [--session-share F] [--json]
"""
from __future__ import annotations

import argparse
import importlib
import json
import sys
from pathlib import Path

# The native layers' window caps: SIRCL's native proxy accepts a forward or ring window of 1 to 60 chunks
# (ROCE_CREDIT - 4), its point-to-point library 1 to 120 chunks.
Expand All @@ -77,6 +79,26 @@
P2P_MAX_CHUNKS = 120


def _ensure_sparkring_fabric() -> None:
"""Make standalone ``sparkring_fabric`` importable from a checkout without touching ``spark_transport/sircl``."""
try:
importlib.import_module("sparkring_fabric.routes")
return
except ModuleNotFoundError:
pass
for parent in Path(__file__).resolve().parents:
pkg_root = parent / "sparkring_fabric"
if (pkg_root / "sparkring_fabric" / "__init__.py").is_file():
pkg_str = str(pkg_root)
if pkg_str not in sys.path:
sys.path.insert(0, pkg_str)
existing = sys.modules.get("sparkring_fabric")
if existing is not None and getattr(existing, "__file__", None) is None:
del sys.modules["sparkring_fabric"]
importlib.invalidate_caches()
return


def share_value(text: str) -> float:
value = float(text)
if not 0 < value <= 1:
Expand All @@ -103,9 +125,8 @@ def main(argv: list[str] | None = None) -> int:
help="the fraction of every relay queue's share the collective session is sized against")
parser.add_argument("--json", action="store_true")
args = parser.parse_args(argv)
from sparkring_sircl import routes
from sparkring_sircl.p2p import budget
from sparkring_sircl.p2p import protocol as p2p_protocol
_ensure_sparkring_fabric()
from sparkring_fabric import budget, routes

layout = routes.Layout.parse(args.layout)
group = routes.derive_routes(layout, args.lanes)
Expand All @@ -120,10 +141,9 @@ def main(argv: list[str] | None = None) -> int:
# link window chunk; a rank whose ring lanes cross a relay queue gets the window, the others 0.
ring_window, problems, relayed = None, ["no chain order"], set()
if order is not None:
from sparkring_sircl import protocol
ring_window, problems = routes.ring_window(layout, maps, order, chunk=protocol.LINK_WINDOW_CHUNK,
ring_window, problems = routes.ring_window(layout, maps, order, chunk=routes.LINK_WINDOW_CHUNK,
queue_bytes=session_queue)
ring_window = min(ring_window, RING_MAX_CHUNKS * protocol.LINK_WINDOW_CHUNK)
ring_window = min(ring_window, RING_MAX_CHUNKS * routes.LINK_WINDOW_CHUNK)
relayed = {rank for members in routes.ring_queues(layout, maps, order).values() for rank, _, _ in members}
if args.ring_only:
if order is None or problems or relayed:
Expand Down Expand Up @@ -151,9 +171,9 @@ def main(argv: list[str] | None = None) -> int:
for row in rows:
print(" ".join(f"{name}={value}" for name, value in row["env"].items()))
return 0
# Point-to-point windows of every ordered pair's relayed lanes (SIRCL's p2p/budget.py).
p2p_max = p2p_protocol.DEFAULT_WINDOW_BYTES if args.p2p_max_window is None else args.p2p_max_window
p2p_chunk = p2p_protocol.DEFAULT_CHUNK_BYTES if args.p2p_chunk is None else args.p2p_chunk
# Point-to-point windows of every ordered pair's relayed lanes (sparkring_fabric.budget).
p2p_max = budget.DEFAULT_P2P_WINDOW_BYTES if args.p2p_max_window is None else args.p2p_max_window
p2p_chunk = budget.DEFAULT_P2P_CHUNK_BYTES if args.p2p_chunk is None else args.p2p_chunk
lane_set = budget.LaneSet.of("layout", layout, args.lanes)
reserved = {}
if args.p2p_reserve == "session":
Expand Down
65 changes: 31 additions & 34 deletions spark_transport/sircl/sparkring_sircl/fabric/__init__.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,37 @@
"""Relay plan installer for SIRCL ring sessions on a switchless ring of DGX Sparks.
"""Compatibility shim: canonical fabric relay installer now lives in ``sparkring_fabric.fabric``."""

SIRCL sessions read host networking but never configure it: members of a
group that share no cable reach each other through ConnectX-7 relays, and the
relay plan is installed by site tooling before a session starts. This
subpackage is that tooling. It derives a layout's plan from SIRCL's own route
module (:mod:`sparkring_sircl.routes`), so the lanes SIRCL derives and the
relays installed cannot disagree, and it installs, compares and removes the
plan on the Sparks over SSH. SIRCL's session code never imports it.
from __future__ import annotations

Per Spark the plan holds:
import importlib
import sys
from pathlib import Path

- origin routes: a /32 route, scope link, over the lane's local network
device, with a permanent neighbour entry holding the adjacent Spark's MAC;
- relay count tags: one marker process per RDMA device (``mesh_marker.c``)
installs mlx5 RDMA-TX rules that rewrite the EtherType of RoCE packets to
each routed destination into ``TAG(k) = 0x88b4 + k``, ``k`` relays left;
- relay filters: on the ingress of the device that receives a relayed lane, a
hardware flower filter per tag that sets the next Spark's MAC, rewrites the
tag to ``TAG(k - 1)`` (``TAG(0)`` is IPv4) and redirects out of the other
port.
_SUBMODULES = ("layouts", "plan", "commands", "state", "diff", "ops", "report", "cli")

Layouts (:mod:`.layouts`): ``ring8`` (the universal relay table), ``2xTP4``,
``4xTP2`` and custom groups of consecutive Sparks, wrap-around included. With
several groups on one ring, routes and tags exist only for same-group
destinations on that group's members, and relay filters only where a member
lies inside a carried path of its own group.

Modules: :mod:`.layouts` (groups), :mod:`.plan` (derivation, isolation and
trace checks), :mod:`.commands` (shell commands and ownership marks),
:mod:`.state` (parsing what a Spark holds), :mod:`.diff` (comparison and
apply scripts), :mod:`.ops` (read, compare, apply), :mod:`.report` (text) and
:mod:`.cli` (``python -m sparkring_sircl.fabric``). The host-command
simulator for tests is :mod:`sparkring_sircl.testing.relay_hosts`.
def _ensure_sparkring_fabric() -> None:
try:
importlib.import_module("sparkring_fabric.fabric")
return
except ModuleNotFoundError:
pass
for parent in Path(__file__).resolve().parents:
pkg_root = parent / "sparkring_fabric"
if (pkg_root / "sparkring_fabric" / "__init__.py").is_file():
pkg_str = str(pkg_root)
if pkg_str not in sys.path:
sys.path.insert(0, pkg_str)
existing = sys.modules.get("sparkring_fabric")
if existing is not None and getattr(existing, "__file__", None) is None:
del sys.modules["sparkring_fabric"]
importlib.invalidate_caches()
return

Status: implemented; CPU-tested against the simulator. The ``ring8`` plan
reproduces the universal relay table object for object; the table's shell
installer is the tests' reference (``tests/fabric_reference.py``). The
installer has not run on a ring.
"""

_ensure_sparkring_fabric()
_canonical = importlib.import_module("sparkring_fabric.fabric")
for _name in _SUBMODULES:
_mod = importlib.import_module(f"sparkring_fabric.fabric.{_name}")
sys.modules[f"{__name__}.{_name}"] = _mod
setattr(_canonical, _name, _mod)
sys.modules[__name__] = _canonical
Loading
Loading