Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
101 commits
Select commit Hold shift + click to select a range
3688f3c
CUDA keyed graph cache and device arena, both off until a family inst…
jayleaton Oct 10, 2026
b7be793
A failed CUDA kernel launch names its kernel and launch configuration…
jayleaton Oct 10, 2026
faf5901
fix(cuda): correct RDMA VMM capability attribute
jrb-ai Oct 10, 2026
3cc0397
Graph cache: a capture is freed until the map holds it, the keep floo…
jayleaton Oct 11, 2026
c58d83c
CUDA arena: the address maps are rehashed before tombstones fill them
jayleaton Oct 11, 2026
25c02d3
Tensor parallelism across CUDA processes: bootstrap, NCCL, mailbox an…
jayleaton Oct 10, 2026
6b5404d
TP tests: a drain on rank 0 then its clean stop ends rank 1's loop at…
jayleaton Oct 10, 2026
06c4e75
TP RoCE: with no TF_TP_ROCE_HCA, each rank picks the ports on an IPv4…
jayleaton Oct 11, 2026
062af8b
TP README: when -Dtp-nvcc, TF_TP_ROCE_HCA, NCCL_IB_HCA, NCCL_SOCKET_I…
jayleaton Oct 11, 2026
d7510ef
TP test runner: a binary built without the mailbox kernel refuses the…
jayleaton Oct 11, 2026
e16e331
TP RoCE: every RDMA post is bounds-checked before the verb, and peers…
jayleaton Oct 11, 2026
649e788
TP RoCE: no RDMA write past 1 MiB, and boot refuses any setting that …
jayleaton Oct 11, 2026
664a8e2
TP RoCE: TF_TP_ROCE_CHUNKED_KB gathers strides past the slot in slot-…
jayleaton Oct 11, 2026
4ad5029
TP RoCE: a failed transport halts its QPs, drains them and keeps its …
jayleaton Oct 11, 2026
9bbc21a
TP RoCE: tf-tp-test failfast V transport checks the failed-transport …
jayleaton Oct 11, 2026
cf19042
Fix RoCE test smaps lookup for merged mappings
jayleaton Oct 11, 2026
0ba7d30
Sessions: the page map is rehashed before tombstones fill it
jayleaton Oct 11, 2026
0918809
Let a family's round planner drive the lane host with prompt pieces
jayleaton Oct 10, 2026
361f063
Lane host halt: a stop's drain deadline ends the rounds at the next b…
jayleaton Oct 10, 2026
e9f9210
Round planner test: both prompts queue before the host starts, and it…
jayleaton Oct 10, 2026
96ae865
Server hooks for a model family's own chat rules.
jayleaton Oct 10, 2026
df480e0
Server: a stop logs its signal and the open connections when the acce…
jayleaton Oct 10, 2026
2c4d837
Server: SIGTERM / SIGINT drains before stopping.
jayleaton Oct 10, 2026
55bf0a7
Server tests: a stop that lands between a request's count and its dra…
jayleaton Oct 10, 2026
9fbc2b3
Server: a stream that has not sent its first token gets keepalives ev…
jayleaton Oct 10, 2026
bb53ff4
Server tests: the drain test's reply in progress is held until its dr…
jayleaton Oct 10, 2026
9eb765d
DeepSeek-V4.1 host side: release config, EXL3 pack headers, a rank's …
jayleaton Oct 11, 2026
865335e
DeepSeek-V4.1 weight forms built at load, and prepared weight folders…
jayleaton Oct 11, 2026
7ccfc5c
DeepSeek-V4.1 Engram host side: table layout, n-gram hashes of a wind…
jayleaton Oct 11, 2026
b775815
DeepSeek-V4.1 phase timers: where a serving round's time goes, by nam…
jayleaton Oct 11, 2026
def4859
DeepSeek-V4.1 Engram rows from packed per-rank shards on local NVMe, …
jayleaton Oct 11, 2026
989ca7e
TP RoCE: run_hosts.sh gives NCCL the RoCE picker's ports when neither…
jayleaton Oct 11, 2026
05c5213
Session memory for paged-KV families: page pool, prefix trie, RAM res…
jayleaton Oct 10, 2026
a3303c7
CUDA keyed graph cache and device arena, both off until a family inst…
jayleaton Oct 10, 2026
69e8a65
A failed CUDA kernel launch names its kernel and launch configuration…
jayleaton Oct 10, 2026
d7e89df
fix(cuda): correct RDMA VMM capability attribute
jrb-ai Oct 10, 2026
5826f89
Graph cache: a capture is freed until the map holds it, the keep floo…
jayleaton Oct 11, 2026
5806e55
CUDA arena: the address maps are rehashed before tombstones fill them
jayleaton Oct 11, 2026
d335520
Graph cache: TF_GRAPH_CACHE=0 or off runs every step eagerly in any f…
jayleaton Oct 14, 2026
7ff83d8
Tensor parallelism across CUDA processes: bootstrap, NCCL, mailbox an…
jayleaton Oct 10, 2026
9af2ea2
TP tests: a drain on rank 0 then its clean stop ends rank 1's loop at…
jayleaton Oct 10, 2026
7c9a26e
TP RoCE: with no TF_TP_ROCE_HCA, each rank picks the ports on an IPv4…
jayleaton Oct 11, 2026
8ebb0be
TP README: when -Dtp-nvcc, TF_TP_ROCE_HCA, NCCL_IB_HCA, NCCL_SOCKET_I…
jayleaton Oct 11, 2026
e9e0056
TP test runner: a binary built without the mailbox kernel refuses the…
jayleaton Oct 11, 2026
0472cbf
TP RoCE: every RDMA post is bounds-checked before the verb, and peers…
jayleaton Oct 11, 2026
9688398
TP RoCE: no RDMA write past 1 MiB, and boot refuses any setting that …
jayleaton Oct 11, 2026
72132f0
TP RoCE: TF_TP_ROCE_CHUNKED_KB gathers strides past the slot in slot-…
jayleaton Oct 11, 2026
e65583c
Server hooks for a model family's own chat rules.
jayleaton Oct 10, 2026
bf19238
TP RoCE: a failed transport halts its QPs, drains them and keeps its …
jayleaton Oct 11, 2026
9a486bb
Server: a stop logs its signal and the open connections when the acce…
jayleaton Oct 10, 2026
beae7e8
TP RoCE: tf-tp-test failfast V transport checks the failed-transport …
jayleaton Oct 11, 2026
467504a
Server: SIGTERM / SIGINT drains before stopping.
jayleaton Oct 10, 2026
602aad5
Fix RoCE test smaps lookup for merged mappings
jayleaton Oct 11, 2026
23bf7d8
Server tests: a stop that lands between a request's count and its dra…
jayleaton Oct 10, 2026
890dfc6
TP RoCE: run_hosts.sh gives NCCL the RoCE picker's ports when neither…
jayleaton Oct 11, 2026
5410eac
Session memory for paged-KV families: page pool, prefix trie, RAM res…
jayleaton Oct 10, 2026
a5b8b35
Server: a stream that has not sent its first token gets keepalives ev…
jayleaton Oct 10, 2026
a3e2fb1
TP NCCL: all_reduce's doc says NCCL adds in its ring's order, so its …
jayleaton Oct 14, 2026
0d0bdb2
Sessions: the page map is rehashed before tombstones fill it
jayleaton Oct 11, 2026
2b3cccf
Server tests: the drain test's reply in progress is held until its dr…
jayleaton Oct 10, 2026
62a75ae
TP: keep Linux-only transport host tests off macOS builds
jayleaton Oct 15, 2026
2cf61d3
Sessions: honor zero residency budgets and reserve uncapped requests
jayleaton Oct 15, 2026
9367784
server: keep shared halt and drain on the existing template path
jayleaton Oct 15, 2026
864fe25
Graph cache: effective settings have one digest for ranks to compare …
jayleaton Oct 16, 2026
e2504f6
TP: bootstrap compares the graph cache's effective settings, so a ran…
jayleaton Oct 16, 2026
dcdc30c
Keep the Linux NVMe lane test out of portable host tests
cwschroeder Oct 16, 2026
368a0d3
Keep the Linux NVMe lane test out of portable host tests
cwschroeder Oct 16, 2026
7a6b32f
server: main's drain stop closes the engine without the closed lane-h…
jayleaton Oct 16, 2026
abcad7d
Merge ashhart/main into stack/02-graph-cache-arena
jayleaton Oct 16, 2026
02d455e
Merge stack/02-graph-cache-arena (with ashhart/main) into stack/03-tp…
jayleaton Oct 16, 2026
9266f3f
Merge stack/03-tp-fabric (with ashhart/main) into stack/04-sessions
jayleaton Oct 16, 2026
001ac2e
Merge stack/04-sessions (with ashhart/main) into stack/07-server
jayleaton Oct 16, 2026
33c0ef6
Merge stack/07-server (sessions, TP, graph cache, current main) into …
jayleaton Oct 16, 2026
af0bc53
Server tests: the drain test imports the named json module
jayleaton Oct 16, 2026
7051a3c
Merge stack/07-server's drain-test json import fix into stack/08a-config
jayleaton Oct 16, 2026
e6df8ad
merge origin/main: the round planner and halt on main's split lane host
jayleaton Oct 16, 2026
4da2618
Merge shared/lane-host-core (#861, on current main) into stack/08a-co…
jayleaton Oct 16, 2026
6b9bede
Merge stack/08a-config (current main, shared layers, #861) into stack…
jayleaton Oct 16, 2026
8900c7c
Sessions: a failed prefix insert leaves the index as it was
jayleaton Oct 17, 2026
3aeebb9
CUDA arena: a reuse whose address-map insertion fails keeps its range…
jayleaton Oct 17, 2026
46161ac
Merge stack/02-graph-cache-arena (the #635 arena fix) into stack/03-t…
jayleaton Oct 17, 2026
78ce706
Merge stack/03-tp-fabric (the #635 arena and #637 prefix fixes) into …
jayleaton Oct 17, 2026
9c5bd60
Merge stack/04-sessions (the #635 arena and #637 prefix fixes) into s…
jayleaton Oct 17, 2026
eaa7953
Merge stack/07-server (the #635 arena and #637 prefix fixes) into sta…
jayleaton Oct 17, 2026
4370f91
Merge stack/08a-config (the #635 arena and #637 prefix fixes) into st…
jayleaton Oct 17, 2026
88418d8
test(tp): reject malformed runner commands before configuration
cwschroeder Oct 17, 2026
4c69b0d
fix(tp): parse runner commands before opening sessions
cwschroeder Oct 17, 2026
4df28ce
test(tp): retain verbs load failures in HCA diagnostics
cwschroeder Oct 17, 2026
0a80da0
fix(tp): distinguish verbs load errors from absent HCA ports
cwschroeder Oct 17, 2026
999cb03
Merge stack/03-tp-fabric (adopted #636 runner CLI validation and HCA …
jayleaton Oct 18, 2026
5f14a64
Merge the layer below (adopted #636 runner CLI validation and HCA ver…
jayleaton Oct 18, 2026
749240a
Merge the layer below (adopted #636 runner CLI validation and HCA ver…
jayleaton Oct 18, 2026
7122563
Merge the layer below (adopted #636 runner CLI validation and HCA ver…
jayleaton Oct 18, 2026
cdde1a4
Merge ashhart/main (1.1.0, 76aafcf2) into stack/02-graph-cache-arena
jayleaton Oct 18, 2026
adbdb8a
CUDA launches: a not-ready launch returns NotReady unlogged, as Drive…
jayleaton Oct 18, 2026
3bd6a6a
Merge stack/02-graph-cache-arena (adbdb8ab, main 76aafcf2) into stack…
jayleaton Oct 18, 2026
54141a1
Merge stack/03-tp-fabric (3bd6a6ab, main 76aafcf2) into stack/04-sess…
jayleaton Oct 18, 2026
80d4ed5
Merge stack/04-sessions (54141a1e, main 76aafcf2) into stack/07-server
jayleaton Oct 18, 2026
aebceae
Merge stack/07-server (80d4ed5c, main 76aafcf2) into stack/08a-config
jayleaton Oct 18, 2026
1003f08
Build: DeepSeek-V4.1's host tests on hosts other than Windows, whose …
jayleaton Oct 18, 2026
aa96782
Merge stack/08a-config (1003f08f, main 76aafcf2) into stack/08b-engram
jayleaton Oct 18, 2026
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
Prev Previous commit
Next Next commit
TP RoCE: TF_TP_ROCE_CHUNKED_KB gathers strides past the slot in slot-…
…sized ops, at most 2 MiB in flight

Default off. allGatherV strides past the slot, up to TF_TP_ROCE_CHUNKED_KB, go RoCE as ceil(n / slot) launches of
the tp_roce kernel: op c moves at most a slot of each shard from c x slot (RoceArgs.chunk), and an op empty on both
ranks rings no doorbell and leaves the epoch. Every RDMA write keeps the 1 MiB cap. The kernel poisons the transport
rather than stage past a slot, and its four failure-record blocks fold into fail_record (same stores and fences).

VerbsWire.post waits for completions while the bytes posted and not completed over both HCAs would pass
max_inflight (2 MiB, a constant in the post path); a wait that sees no completion for 10 s fails the proxy. Boot
refuses TF_TP_ROCE_CHUNKED_KB when the kernel image lacks the tp_roce_chunk_abi marker. The setting is part of the
digest both ranks agree on.

Tests: chunked strides from 300 KB to a 128 MiB union posted back to back on fake verbs whose completions lag keep at
most 2 MiB in flight and no write past 1 MiB, and reach the cap; the wire's own in-flight count and peak match the
fake HCAs'. Over the shm wire, 2,000 chunked variable-length gathers of up to four slots arrive bit for bit.
  • Loading branch information
jayleaton committed Oct 16, 2026
commit 72132f08eca54c36e13dab4fa7dfb853182646fc
4 changes: 4 additions & 0 deletions zig/src/fabric/tp/config.zig
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ pub const Config = struct {
device: u32 = 0,
backend: Backend = .nccl,
mailbox_max_bytes: usize = 256 * 1024,
/// TF_TP_ROCE_CHUNKED_KB: `allGatherV` strides up to this go RoCE in ops of at most a slot (0: off).
roce_chunked_bytes: usize = 0,
/// A mailbox wait for the peer gives up after this long and poisons the transport (fail-stop).
mailbox_timeout_ns: u64 = 120 * std.time.ns_per_s,
failfast: bool = true,
Expand Down Expand Up @@ -83,6 +85,7 @@ pub const Config = struct {
log.warn("TF_TP_MAILBOX_MAX_KB={d}: a RoCE write is capped at {d} KiB; refusing to start", .{ c.mailbox_max_bytes / 1024, max_rdma_write / 1024 });
return error.BadSetting;
}
c.roce_chunked_bytes = 1024 * try int(usize, get, "TF_TP_ROCE_CHUNKED_KB", 0, 0, 64 * 1024);
c.mailbox_timeout_ns = try seconds(get, "TF_TP_MAILBOX_TIMEOUT_S", 120, 0.001, 86400);
if (get("TF_TP_FAILFAST")) |v| c.failfast = !(std.mem.eql(u8, v, "0") or std.mem.eql(u8, v, "off"));
c.grace_ns = try seconds(get, "TF_TP_FAILFAST_GRACE_S", 1.0, 0, 60);
Expand Down Expand Up @@ -141,6 +144,7 @@ pub const Config = struct {
h.update(std.mem.asBytes(&c.world));
h.update(std.mem.asBytes(&c.backend));
h.update(std.mem.asBytes(&c.mailbox_max_bytes));
h.update(std.mem.asBytes(&c.roce_chunked_bytes));
h.update(std.mem.asBytes(&c.failfast));
h.update(std.mem.asBytes(&c.roce_wire));
h.update(std.mem.asBytes(&c.roce_fallback));
Expand Down
24 changes: 20 additions & 4 deletions zig/src/fabric/tp/hybrid.zig
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,18 @@ pub const Small = union(enum) {
}
};

/// Whether a variable-length gather of `n`-byte strides one op cannot take goes RoCE in slot-sized ops (needs the ABI).
pub fn chunkRoute(chunked_bytes: usize, n: usize, single: bool, abi: bool) bool {
return abi and !single and n > 0 and n <= chunked_bytes;
}

pub const Hybrid = struct {
small: Small,
nccl: *Nccl,
/// Largest shard a rank sends through the small path.
max_bytes: usize,
/// Largest stride a variable-length gather takes on RoCE in slot-sized ops (TF_TP_ROCE_CHUNKED_KB; 0: none).
chunked_bytes: usize = 0,
/// Every rank's `varFits(16)`, agreed at `Session.open` (the bootstrap's all-gather): `varAgreed`'s answer.
var_agreed: bool = false,

Expand Down Expand Up @@ -117,19 +124,28 @@ pub const Hybrid = struct {
fn allGatherV(ptr: *anyopaque, s: DevicePtr, r: DevicePtr, stride: usize, lens: DevicePtr, t: DType, stream: collective.Stream) Error!void {
const h = self_(ptr);
const n = stride * t.size();
if (varFits(ptr, n)) return h.small.roce.allGatherV(s, r, n, lens, stream);
if (singleFits(h, n)) return h.small.roce.allGatherV(s, r, n, lens, stream);
if (varFits(ptr, n)) return h.small.roce.allGatherVChunked(s, r, n, lens, stream);
return allGather(ptr, s, r, stride, t, stream);
}

/// RoCE with its device side, for a stride the small path takes (the route is the size's alone: every rank alike).
pub fn varFits(ptr: *anyopaque, n: usize) bool {
const h = self_(ptr);
fn singleFits(h: *const Hybrid, n: usize) bool {
return switch (h.small) {
.roce => |p| n > 0 and h.routed(n) and p.d != null,
.mailbox => false,
};
}

/// RoCE with its device side, in one op or in slot-sized ops (the route is the size's alone: every rank alike).
pub fn varFits(ptr: *anyopaque, n: usize) bool {
const h = self_(ptr);
const single = singleFits(h, n);
return single or switch (h.small) {
.roce => |p| chunkRoute(h.chunked_bytes, n, single, p.d != null and p.chunk_abi),
.mailbox => false,
};
}

fn varAgreed(ptr: *anyopaque) Error!bool {
return self_(ptr).var_agreed;
}
Expand Down
80 changes: 44 additions & 36 deletions zig/src/fabric/tp/mailbox.cu
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,21 @@ __device__ __noinline__ bool wait_flag_shared(const uint32_t *flag, uint32_t seq
}
}

// One failure record a rank (the first failing wait's): its fields, then its valid word, each fenced at system scope.
__device__ __forceinline__ void fail_record(uint32_t *poison, uint32_t *rec, uint32_t seq, uint32_t seen, uint32_t who,
uint32_t why, uint32_t waited) {
if (atom_cas_gpu(poison, 0u, 1u) == 0u) {
st_relaxed_sys(rec + 1, seq);
st_relaxed_sys(rec + 2, seen);
st_relaxed_sys(rec + 3, who);
st_relaxed_sys(rec + 4, why);
st_relaxed_sys(rec + 5, waited);
fence_sc_sys();
st_relaxed_sys(rec, 1u);
fence_sc_sys();
}
}

} // namespace tftp

using namespace tftp;
Expand Down Expand Up @@ -313,17 +328,7 @@ extern "C" __global__ void __launch_bounds__(512) tp_mailbox(MailArgs a) {
uint32_t seen = 0u, why = 0u, waited = 0u;
if (!wait_flag(a.my_flags + flag_at, seq, a.ctrl, a.timeout_ns, &seen, &why, &waited)) {
s_bad = 1u;
if (atom_cas_gpu(a.state + 2, 0u, 1u) == 0u) { // one failure record a rank
uint32_t *rec = a.ctrl + kCtrlRank + 8u * a.rank;
st_relaxed_sys(rec + 1, seq);
st_relaxed_sys(rec + 2, seen);
st_relaxed_sys(rec + 3, blockIdx.x);
st_relaxed_sys(rec + 4, why);
st_relaxed_sys(rec + 5, waited);
fence_sc_sys();
st_relaxed_sys(rec, 1u);
fence_sc_sys();
}
fail_record(a.state + 2, a.ctrl + kCtrlRank + 8u * a.rank, seq, seen, blockIdx.x, why, waited);
}
}
__syncthreads();
Expand Down Expand Up @@ -391,6 +396,7 @@ struct RoceArgs {
uint32_t opts; // TF_TP_ROCE_FAST: bit 0 fast, bits 8-15 pollers a flag, bits 16-31 start stagger ns; 0: classic
// gather only (nullptr: every shard is nbytes): lens[r] = rank r's bytes, padded to 16 on the wire
const int32_t *lens;
uint64_t chunk; // chunked gathers: this op's offset into each shard (at most a slot of each from there; else 0)
};

// Rank r's bytes this op: ``nbytes``, or lens[r] capped at nbytes.
Expand All @@ -411,8 +417,17 @@ __device__ __forceinline__ uint64_t roce_span(const RoceArgs &a, uint64_t n) {
return (n + 15u) & ~uint64_t(15u);
}

// A shard's bytes past `off`, at most a slot (chunked gathers; off 0 and a shard within the slot: the shard).
__device__ __forceinline__ uint64_t roce_part(const RoceArgs &a, uint64_t shard, uint64_t off) {
const uint64_t rest = shard > off ? shard - off : 0u;
return rest < a.slot_bytes ? rest : a.slot_bytes;
}

} // namespace tftp

// Present in images whose RoceArgs carry ``chunk`` (roce.zig refuses TF_TP_ROCE_CHUNKED_KB without it); never launched.
extern "C" __global__ void tp_roce_chunk_abi() {}

extern "C" __global__ void __launch_bounds__(512) tp_roce(RoceArgs a) {
__shared__ uint32_t s_head[2]; // poison, seq
__shared__ uint32_t s_bad;
Expand All @@ -438,12 +453,23 @@ extern "C" __global__ void __launch_bounds__(512) tp_roce(RoceArgs a) {
const uint32_t seq = s_head[1];
const uint64_t slot = seq & 1u;
const bool var = a.mode == kGather && a.lens != nullptr;
const uint64_t mine = var ? roce_shard(a, a.rank) : a.nbytes;
const uint64_t theirs = var ? roce_shard(a, 1u - a.rank) : a.nbytes;
const uint64_t off = var ? a.chunk : 0u;
const uint64_t mine = var ? roce_part(a, roce_shard(a, a.rank), off) : a.nbytes;
const uint64_t theirs = var ? roce_part(a, roce_shard(a, 1u - a.rank), off) : a.nbytes;
const uint64_t padded = var ? (mine < 16u ? 16u : (mine + 15u) & ~uint64_t(15u)) : (a.nbytes + 15u) & ~uint64_t(15u);
if (off != 0u && mine == 0u && theirs == 0u) {
return; // nothing past this offset on either rank: no op, the epoch stays (both ranks skip alike)
}
if (padded > a.slot_bytes) { // never staged past a slot: a refused wait (why 3), the transport poisoned
if (tid == 0 && blockIdx.x == 0) {
fail_record(a.state + 2, a.ctrl + kRoceFailed, seq, 0u, 0u, 3u, 0u);
}
return;
}

// 1. stage this block's share into the send slot; the last block to finish rings the doorbell
copy_any<false>(fast, a.send_slots + slot * a.slot_bytes, a.in, var ? roce_span(a, mine) : a.nbytes, index, stride);
copy_any<false>(fast, a.send_slots + slot * a.slot_bytes, a.in + off, var ? roce_span(a, mine) : a.nbytes, index,
stride);
__syncthreads();
if (tid == 0 && fast) {
// lean doorbell: release RMW per block arrival, the last acquires, then a release store (no SC system fences)
Expand All @@ -468,7 +494,7 @@ extern "C" __global__ void __launch_bounds__(512) tp_roce(RoceArgs a) {
}
}
if (a.mode == kGather) {
copy_any<false>(fast, a.out + static_cast<uint64_t>(a.rank) * a.nbytes, a.in,
copy_any<false>(fast, a.out + static_cast<uint64_t>(a.rank) * a.nbytes + off, a.in + off,
var ? roce_span(a, mine) : a.nbytes, index, stride);
}

Expand All @@ -486,16 +512,7 @@ extern "C" __global__ void __launch_bounds__(512) tp_roce(RoceArgs a) {
if (!wait_flag_shared(a.flags + (slot * kRoceHcas + lane) * kFlagStride, seq, a.ctrl + kRoceAbort,
a.timeout_ns, &seen, &why, &waited, &s_done[lane])) {
s_bad = 1u;
if (atom_cas_gpu(a.state + 2, 0u, 1u) == 0u) {
st_relaxed_sys(a.ctrl + kRoceFailed + 1, seq);
st_relaxed_sys(a.ctrl + kRoceFailed + 2, seen);
st_relaxed_sys(a.ctrl + kRoceFailed + 3, lane);
st_relaxed_sys(a.ctrl + kRoceFailed + 4, why);
st_relaxed_sys(a.ctrl + kRoceFailed + 5, waited);
fence_sc_sys();
st_relaxed_sys(a.ctrl + kRoceFailed, 1u);
fence_sc_sys();
}
fail_record(a.state + 2, a.ctrl + kRoceFailed, seq, seen, lane, why, waited);
}
}
} else if (tid == 0) {
Expand All @@ -504,16 +521,7 @@ extern "C" __global__ void __launch_bounds__(512) tp_roce(RoceArgs a) {
if (!wait_flag(a.flags + (slot * kRoceHcas + h) * kFlagStride, seq, a.ctrl + kRoceAbort, a.timeout_ns, &seen,
&why, &waited)) {
s_bad = 1u;
if (atom_cas_gpu(a.state + 2, 0u, 1u) == 0u) {
st_relaxed_sys(a.ctrl + kRoceFailed + 1, seq);
st_relaxed_sys(a.ctrl + kRoceFailed + 2, seen);
st_relaxed_sys(a.ctrl + kRoceFailed + 3, h);
st_relaxed_sys(a.ctrl + kRoceFailed + 4, why);
st_relaxed_sys(a.ctrl + kRoceFailed + 5, waited);
fence_sc_sys();
st_relaxed_sys(a.ctrl + kRoceFailed, 1u);
fence_sc_sys();
}
fail_record(a.state + 2, a.ctrl + kRoceFailed, seq, seen, h, why, waited);
break;
}
}
Expand All @@ -525,7 +533,7 @@ extern "C" __global__ void __launch_bounds__(512) tp_roce(RoceArgs a) {
const uint8_t *inbox = a.recv_slots + slot * a.slot_bytes;
switch (a.mode) {
case kGather:
copy_any<true>(fast, a.out + static_cast<uint64_t>(1u - a.rank) * a.nbytes, inbox,
copy_any<true>(fast, a.out + static_cast<uint64_t>(1u - a.rank) * a.nbytes + off, inbox,
var ? roce_span(a, theirs) : a.nbytes, index, stride);
break;
case kExchange:
Expand Down
48 changes: 40 additions & 8 deletions zig/src/fabric/tp/roce.zig
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ const RoceArgs = extern struct {
opts: u32 = 0,
/// gather only: device int32 [2] of each rank's bytes (0: every shard is `nbytes`)
lens: DevicePtr = 0,
/// Chunked gathers: this op's byte offset into each rank's shard (it moves at most a slot from there; 0 otherwise).
chunk: u64 = 0,
};

pub const WireKind = enum {
Expand Down Expand Up @@ -125,6 +127,8 @@ pub const Roce = struct {
state: ?cuda.DeviceBuffer = null,
module: ?cuda.Module = null,
func: ?cuda.Function = null,
/// The kernel image takes `RoceArgs.chunk` (it exports tp_roce_chunk_abi): TF_TP_ROCE_CHUNKED_KB needs it.
chunk_abi: bool = false,
// the proxy thread
thread: ?std.Thread = null,
running: std.atomic.Value(bool) = .init(false),
Expand Down Expand Up @@ -233,6 +237,7 @@ pub const Roce = struct {
try r.state.?.fill8(0, null);
r.module = try cuda.Module.load(d, image);
r.func = try r.module.?.function("tp_roce");
r.chunk_abi = if (r.module.?.function("tp_roce_chunk_abi")) |_| true else |_| false;
return true;
}

Expand Down Expand Up @@ -311,8 +316,12 @@ pub const Roce = struct {
}

fn launch(r: *Roce, mode: Mode, in: DevicePtr, out: DevicePtr, n: usize, lens: DevicePtr, stream: collective.Stream) Error!void {
return r.launchAt(mode, in, out, n, lens, 0, stream);
}

fn launchAt(r: *Roce, mode: Mode, in: DevicePtr, out: DevicePtr, n: usize, lens: DevicePtr, chunk: u64, stream: collective.Stream) Error!void {
if (r.aborted.load(.acquire)) return error.Aborted;
if (n > r.slot_bytes) return error.Unsupported;
if (n > r.slot_bytes and (lens == 0 or !r.chunk_abi)) return error.Unsupported;
if (n == 0) return;
const d = r.d orelse return error.Unsupported;
var a: RoceArgs = .{
Expand All @@ -331,9 +340,10 @@ pub const Roce = struct {
.n_hca = r.wire.hcas(),
.opts = r.fast,
.lens = lens,
.chunk = chunk,
};
var params = [1]?*anyopaque{@ptrCast(&a)};
const blocks = @min(@import("mailbox.zig").blocksFor(n), r.max_grid);
const blocks = @min(@import("mailbox.zig").blocksFor(@min(n, r.slot_bytes)), r.max_grid);
d.check(d.api.cuLaunchKernel(r.func.?.handle, blocks, 1, 1, threads, 1, 1, 0, stream, &params, null), "cuLaunchKernel tp_roce") catch return error.BackendFailed;
}

Expand All @@ -347,6 +357,14 @@ pub const Roce = struct {
return r.launch(.gather, s, o, n, lens, stream);
}

/// `allGatherV` past the slot: op c moves at most a slot of each shard from c x slot (empty on both ranks: no op).
pub fn allGatherVChunked(r: *Roce, s: DevicePtr, o: DevicePtr, n: usize, lens: DevicePtr, stream: collective.Stream) Error!void {
if (lens == 0) return error.Invalid;
if (!r.chunk_abi) return error.Unsupported;
var off: usize = 0;
while (off < n) : (off += r.slot_bytes) try r.launchAt(.gather, s, o, n, lens, off, stream);
}

pub fn exchangeBytes(r: *Roce, s: DevicePtr, o: DevicePtr, n: usize, stream: collective.Stream) Error!void {
return r.launch(.exchange, s, o, n, 0, stream);
}
Expand Down Expand Up @@ -391,17 +409,31 @@ pub const Roce = struct {

/// `hostGather` with variable lengths (`allGatherV`): rank k's first lens[k] bytes land at out + k x n.
pub fn hostGatherV(r: *Roce, in: []const u8, out: []u8, lens: ?[2]u32) Error!void {
if (in.len > r.slot_bytes) return error.Invalid;
return r.hostGatherAt(in, out, lens, 0);
}

/// `allGatherVChunked`'s ops done by the host (the kernel's side of each, as `hostGatherV`).
pub fn hostGatherVChunked(r: *Roce, in: []const u8, out: []u8, lens: [2]u32) Error!void {
var off: usize = 0;
while (off < in.len) : (off += r.slot_bytes) try r.hostGatherAt(in, out, lens, off);
}

/// One op from shard offset `off`: each rank's bytes past it, at most a slot; an op empty on both ranks is skipped.
fn hostGatherAt(r: *Roce, in: []const u8, out: []u8, lens: ?[2]u32, off: usize) Error!void {
const n = in.len;
if (n == 0 or n > r.slot_bytes or out.len < 2 * n) return error.Invalid;
if (n == 0 or out.len < 2 * n) return error.Invalid;
if (lens) |l| if (l[0] > n or l[1] > n) return error.Invalid;
const mine: usize = if (lens) |l| l[r.me] else n;
const theirs: usize = if (lens) |l| l[1 - r.me] else n;
const full: [2]usize = if (lens) |l| .{ l[0], l[1] } else .{ n, n };
const mine: usize = @min(full[r.me] -| off, r.slot_bytes);
const theirs: usize = @min(full[1 - r.me] -| off, r.slot_bytes);
if (off > 0 and mine == 0 and theirs == 0) return;
const seq = r.host_epoch +% 1;
const slot: usize = seq & 1;
@memcpy(r.region[send_off + slot * r.slot_bytes ..][0..mine], in[0..mine]);
@memcpy(r.region[send_off + slot * r.slot_bytes ..][0..mine], in[off..][0..mine]);
r.word(w_slot_bytes + slot).store(@intCast(@max(16, std.mem.alignForward(usize, mine, 16))), .release);
r.word(w_seq).store(seq, .release);
@memcpy(out[r.me * n ..][0..mine], in[0..mine]);
@memcpy(out[r.me * n + off ..][0..mine], in[off..][0..mine]);
const t0 = sock.nowNs();
for (0..r.wire.hcas()) |h| {
const flag: *std.atomic.Value(u32) = @ptrCast(@alignCast(r.region[flag_off + (slot * 2 + h) * flag_stride ..].ptr));
Expand All @@ -411,7 +443,7 @@ pub const Roce = struct {
std.atomic.spinLoopHint();
}
}
@memcpy(out[(1 - r.me) * n ..][0..theirs], r.region[send_off + 2 * r.slot_bytes + slot * r.slot_bytes ..][0..theirs]);
@memcpy(out[(1 - r.me) * n + off ..][0..theirs], r.region[send_off + 2 * r.slot_bytes + slot * r.slot_bytes ..][0..theirs]);
r.host_epoch = seq;
}
};
Expand Down
26 changes: 26 additions & 0 deletions zig/src/fabric/tp/roce_inflight_test.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//! VerbsWire on fake verbs whose completions lag: what it holds in flight and what a failed transport leaves behind.
const std = @import("std");
const rv = @import("roce_verbs.zig");
const fake = @import("roce_fake.zig");
const Roce = @import("roce.zig").Roce;
const Fake = fake.Fake;
const slot = fake.slot;

test "chunked posts: the wire's own in-flight count and peak match the HCAs', and reach the 2 MiB cap" {
const region = try std.testing.allocator.alignedAlloc(u8, .fromByteUnits(4096), Roce.regionBytes(slot));
defer std.testing.allocator.free(region);
Fake.region = region;
Fake.slot_bytes = slot;
Fake.reset(3);
var hw: fake.Hw = .{};
var w = hw.wire(region);
for (1..9) |seq| {
try w.post(@intCast(seq & 1), @intCast(seq), slot);
try std.testing.expectEqual(Fake.inflight, w.inflight());
try std.testing.expect(w.inflight() <= rv.max_inflight);
}
while (w.inflight() > 0) try w.reap();
try std.testing.expectEqual(@as(u64, 0), Fake.inflight);
try std.testing.expectEqual(Fake.max_inflight, w.peak.load(.monotonic));
try std.testing.expectEqual(@as(u64, 2 << 20), w.peak.load(.monotonic));
}
Loading