Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
6636e69
cuda: a one-shot RoCE all-gather for two ranks (roce.zig, roce_gather…
BobClawblaw Oct 14, 2026
39de039
lane core and native CUDA host for two-rank families with a vision to…
BobClawblaw Oct 14, 2026
bdc47c8
Merge branch 'pr/roce-gather' into pr/glm-flash-cuda
BobClawblaw Oct 14, 2026
cbe08cf
GLM-5.3-Flash on two CUDA ranks: the native family (zig/src/families/…
BobClawblaw Oct 14, 2026
a76f16a
glm kernels: the tensor-core fragment header beside them (qmm_frag.cu…
BobClawblaw Oct 14, 2026
abb8bbe
glm: the three Flash Next kernels the family loads (experts, experts_…
BobClawblaw Oct 14, 2026
2903dd7
cuda abi: the driver entries the GLM family uses (module function enu…
BobClawblaw Oct 14, 2026
87ef757
tf-cuda-test glm-*: exit right after the pass or summary line (the te…
BobClawblaw Oct 14, 2026
a759ccd
Merge branch 'pr/roce-gather' into pr/glm-flash-cuda
BobClawblaw Oct 15, 2026
db750c4
Merge branch 'pr/lane-host-vision' into pr/glm-flash-cuda
BobClawblaw Oct 15, 2026
a2eefa2
glm cuda: zig fmt
BobClawblaw Oct 15, 2026
22d92e4
lane host: a warm pass that steps aside is not launched after its can…
BobClawblaw Oct 15, 2026
a76651a
glm cuda: comments one line each, files under 600 lines, the long hea…
BobClawblaw Oct 15, 2026
ef73ec3
tf_video: the includes back under its one-line header
BobClawblaw Oct 15, 2026
e0d3baa
Merge branch 'pr/lane-host-vision' into pr/glm-flash-cuda
BobClawblaw Oct 15, 2026
0e50498
cuda: RoCE gather comments on one line each, the protocol notes in do…
BobClawblaw Oct 15, 2026
cc5d9d1
vision inputs: a server without --vision refuses image parts in the f…
BobClawblaw Oct 15, 2026
89c68c8
Merge branch 'pr/lane-host-vision' into pr/glm-flash-cuda
BobClawblaw Oct 15, 2026
aaed024
qwen_image.formatSeconds: t * 10 rounded in integers, not f128, so te…
BobClawblaw Oct 15, 2026
2cc423f
Merge branch 'pr/lane-host-vision' into pr/glm-flash-cuda
BobClawblaw Oct 15, 2026
9e6dfcd
lane host: a set-up job's kept entry stays pinned until its restore r…
BobClawblaw Oct 15, 2026
a8ea350
Merge remote-tracking branch 'fork/pr/lane-host-vision' into pr/glm-f…
BobClawblaw Oct 15, 2026
d069277
cuda: RoCE gather ranks agree one shard cap (each sends its max_bytes…
BobClawblaw Oct 15, 2026
22d2a30
Merge remote-tracking branch 'fork/pr/roce-gather' into pr/glm-flash-…
BobClawblaw Oct 15, 2026
b07b11b
glm cuda: the review's four fixes: a RoCE check after every sync that…
BobClawblaw Oct 15, 2026
52b82fc
prompt cache: an entry removed while pinned is dead to lookups and fr…
BobClawblaw Oct 15, 2026
468fa88
Merge branch 'pr/lane-host-vision' into pr/glm-flash-cuda
BobClawblaw Oct 15, 2026
c525ea9
glm cuda: the gather check and the agreed settings' doc comments on o…
BobClawblaw Oct 15, 2026
7c9d845
Merge remote-tracking branch 'origin/main' into pr/roce-gather
BobClawblaw Oct 16, 2026
b8d45de
cuda: the RoCE gather joins tp_group: its setup crosses the group's N…
BobClawblaw Oct 16, 2026
bb7e2a2
Merge origin/main (1.0.12) into pr/lane-host-vision: main's image pat…
BobClawblaw Oct 16, 2026
b416ec8
lane core: several queued prompts in one pass for a backend with pref…
BobClawblaw Oct 16, 2026
1ac97f6
Merge remote-tracking branch 'fork/pr/roce-gather' into tmp-855-base
BobClawblaw Oct 16, 2026
b982a3b
Merge #853 and #852 (both on main 1.0.12 with #804) into pr/glm-flash…
BobClawblaw Oct 16, 2026
aa9d4a7
glm cuda: the ranks' communicator is a tp_group.Group; on two ranks t…
BobClawblaw Oct 16, 2026
653bd37
glm cuda: EXL3 routed experts (Mia-AiLab's checkpoint: 4-bit mcg trel…
BobClawblaw Oct 16, 2026
8278074
kernel contract: glm_exl3's eight launches with their sm_80/86/89/120…
BobClawblaw Oct 16, 2026
084c253
glm cuda: the ranks watch each other (tp_watch): a rank that fails or…
BobClawblaw Oct 16, 2026
b090a7b
glm cuda: verify windows to the decode buffers' 8 rows, so the lane c…
BobClawblaw Oct 16, 2026
93f5261
glm cuda: the image tower (model.visual.*, rank 0's) on cuBLASLt and …
BobClawblaw Oct 16, 2026
f9d4f9f
glm cuda: images on two ranks (--vision): rank 0's tower encodes a pr…
BobClawblaw Oct 16, 2026
3cc4581
tools/glm_vision_ref.py: the torch reference tf-cuda-test glm-vision …
BobClawblaw Oct 16, 2026
edc2285
glm cuda: the bf16 linears on glm_mm (ours, from the glm_cuda family)…
BobClawblaw Oct 16, 2026
875b695
glm cuda: TF_GLM_PROF=1 also times prompt chunks by section (gate, fo…
BobClawblaw Oct 16, 2026
526ffd4
Merge the glm_cuda family's head (c525ea99): its work now lives in fa…
BobClawblaw Oct 16, 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
cuda: the RoCE gather joins tp_group: its setup crosses the group's N…
…CCL communicator (no TCP link: NCCL_COMM_ID and tp_watch do that now), Group.openRoce brings it up on two ranks, allGather takes it by size alone, Group.check after a sync that reads a gather; tf-cuda-test roce-gather (every size against NCCL's bytes, graph replays, time a call)
  • Loading branch information
BobClawblaw committed Oct 16, 2026
commit b8d45ded31edaacc80fb74f134159415c18ea847
10 changes: 7 additions & 3 deletions docs/roce-gather.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ One launch: (1) every block stages its share of the shard into send[seq & 1]; (2

## Host side

Small all-gathers between two ranks as one-shot RDMA writes over RoCE: b12x's "RoCEnante" exchange (https://github.com/local-inference-lab/b12x, b12x/comm/roce, Apache License 2.0), written for two ranks: the kernel (kernels/cuda/roce_gather.cu) stages this rank's shard in pinned host memory and rings a doorbell; a proxy thread here RDMA-writes it to the peer, striped over the HCAs, each stripe followed by its sequence flag on the same queue pair; the kernel waits for the peer's flags and copies both shards out. A decode step's gathers are a few rows of partials, where NCCL spends tens of microseconds a call in fixed costs; this path takes about ten. libibverbs is opened at run time (as the driver and NCCL are): without it, or without an active HCA, the caller keeps NCCL.
Small all-gathers between two ranks as one-shot RDMA writes over RoCE: b12x's "RoCEnante" exchange (https://github.com/local-inference-lab/b12x, b12x/comm/roce, Apache License 2.0), written for two ranks: the kernel (kernels/cuda/roce_gather.cu) stages this rank's shard in pinned host memory and rings a doorbell; a proxy thread here RDMA-writes it to the peer, striped over the HCAs, each stripe followed by its sequence flag on the same queue pair; the kernel waits for the peer's flags and copies both shards out. A decode step's gathers are a few rows of partials. On two GB10s with one ConnectX-7 cable (NCCL 2.30.7, `tf-cuda-test roce-gather`, 2,000 calls back to back) this path took 10.4 us a call at 4 KiB a rank against NCCL's 12.3, 11.6 against 13.5 at 8 KiB, 17.4 against 20.5 at 32 KiB, and 17.4 against 51.5 at 64 KiB. libibverbs is opened at run time (as the driver and NCCL are): without it, or without an active HCA, the caller keeps NCCL.

## Control link
## Setup and use

Two ranks over the hosts' network: a TCP control link (rank 0 listens, rank 1 connects; framed messages carry requests and per-round decisions) and the NCCL communicator it brings up (rank 0 makes the unique id and sends it).
`tp_group.Group.openRoce` brings the path up on a two-rank group: each rank opens its HCAs, and what each brings (its region, keys, queue pairs and the largest shard it would send) crosses the group's own NCCL communicator, as does each rank's verdict after connecting. Both ranks get the path or neither does (`TF_ROCE=0` on either rank keeps NCCL). From then on `Group.allGather` sends a gather of up to the smaller rank's cap (512 KiB by default) this way and leaves larger ones to NCCL; the size alone decides, so both ranks always take the same path. A rank whose buffers are not 16-byte aligned gets `error.Misaligned` instead of falling back alone. Liveness is `tp_watch`'s, as for every group.

A failed exchange writes nothing into the gathered rows. Call `Group.check` after any synchronize whose result reads a gather: it returns the error the GPU or the proxy recorded.

`tf-cuda-test roce-gather <rank>` runs on both ranks (NCCL_COMM_ID set): every size up to the cap and past it against NCCL's all-gather, byte for byte, then each path's time a call.
53 changes: 37 additions & 16 deletions zig/src/cuda/roce.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const memory = @import("memory.zig");
const Module = @import("module.zig").Module;
const Function = @import("module.zig").Function;
const launch = @import("launch.zig");
const tp_link = @import("tp_link.zig");
const tp_group = @import("tp_group.zig");
const Stream = @import("stream.zig").Stream;
const kernels = @import("kernels.zig");

const max_hcas = 2;
Expand Down Expand Up @@ -143,7 +144,20 @@ fn opsCall(comptime T: type, ctx: *Context, offset: usize) T {
return slot.*;
}

pub const Error = error{ VerbsUnavailable, NoHca, HcaFailed, PeerRefused, ProxyFailed, ExchangeTimedOut };
pub const Error = error{ VerbsUnavailable, NoHca, HcaFailed, PeerRefused, ProxyFailed, ExchangeTimedOut, Misaligned };

/// TF_ROCE=0 keeps every gather on NCCL; unset or any other value asks for this path (both ranks must ask).
pub fn wanted() bool {
const v = std.c.getenv("TF_ROCE") orelse return true;
return !std.mem.eql(u8, std.mem.span(v), "0");
}

/// The peer's `mine`: both ranks' values cross the group's communicator, rank order.
fn swap(comptime T: type, group: *const tp_group.Group, d: *const Driver, s: Stream, mine: T) !T {
var both: [2]T = undefined;
try group.gather(T, d, s, mine, &both);
return both[1 - group.rank];
}

// -- the region's layout (the same on both ranks) ---------------------------------------------------------------------
const Layout = struct {
Expand Down Expand Up @@ -219,20 +233,24 @@ pub const Gather = struct {
err: [256]u8 = @splat(0),
gathers: u64 = 0,

/// Both ranks' exchange, or null on both when either cannot; verdicts cross ``link``. ``max_bytes``: a shard.
pub fn init(gpa: std.mem.Allocator, io: std.Io, d: *const Driver, link: tp_link.Link, wanted: bool, max_bytes: usize) !?*Gather {
/// Both ranks' exchange or null on both; setup crosses ``group``'s communicator on ``s``. ``max_bytes``: a shard.
pub fn init(gpa: std.mem.Allocator, io: std.Io, d: *const Driver, group: *const tp_group.Group, s: Stream, want: bool, max_bytes: usize) !?*Gather {
if (group.world != 2) return error.PeerRefused;
const g = try gpa.create(Gather);
var mine: Blob = std.mem.zeroes(Blob);
const ok = wanted and blk: {
g.setup(gpa, io, d, link.rank, max_bytes) catch |e| {
const ok = want and blk: {
g.setup(gpa, io, d, @intCast(group.rank), max_bytes) catch |e| {
std.log.warn("RoCE all-gather: {s} ({s}); NCCL carries every gather", .{ @errorName(e), std.mem.sliceTo(&g.err, 0) });
break :blk false;
};
break :blk true;
};
if (ok) g.blob(&mine);
var theirs: Blob = undefined;
try link.swap(std.mem.asBytes(&mine), std.mem.asBytes(&theirs));
const theirs = swap(Blob, group, d, s, mine) catch |e| {
if (ok) g.teardown();
gpa.destroy(g);
return e;
};
if (!ok or theirs.ok == 0 or theirs.n_hca != mine.n_hca or theirs.slot_bytes != mine.slot_bytes) {
if (ok) g.teardown();
gpa.destroy(g);
Expand All @@ -246,10 +264,12 @@ pub const Gather = struct {
};
break :blk true;
};
var v: [1]u8 = .{@intFromBool(connected)};
var pv: [1]u8 = undefined;
try link.swap(&v, &pv);
if (!connected or pv[0] == 0) {
const peer_connected = swap(u32, group, d, s, @intFromBool(connected)) catch |e| {
g.teardown();
gpa.destroy(g);
return e;
};
if (!connected or peer_connected == 0) {
g.teardown();
gpa.destroy(g);
return null;
Expand Down Expand Up @@ -472,13 +492,14 @@ pub const Gather = struct {
return @intCast(@min(mine, theirs));
}

/// Whether a gather of ``bytes`` a rank (from and to 16-byte aligned buffers) goes this way.
pub fn fits(g: *const Gather, bytes: usize, send: abi.DevicePtr, recv: abi.DevicePtr) bool {
return bytes > 0 and bytes <= g.max_bytes and bytes % 16 == 0 and send % 16 == 0 and recv % 16 == 0;
/// Whether a gather of ``bytes`` a rank goes this way: the size alone decides, so both ranks pick the same path.
pub fn fits(g: *const Gather, bytes: usize) bool {
return bytes > 0 and bytes <= g.max_bytes and bytes % 16 == 0;
}

/// Both ranks' ``bytes`` from ``send`` into ``recv`` in rank order (as ncclAllGather), on ``stream``.
/// Both ranks' ``bytes`` from ``send`` into ``recv`` in rank order (as ncclAllGather); misaligned is an error.
pub fn gather(g: *Gather, stream: abi.Stream, send: abi.DevicePtr, recv: abi.DevicePtr, bytes: usize) !void {
if (send % 16 != 0 or recv % 16 != 0) return error.Misaligned;
const packs = bytes / 16;
const need = @max(1, std.math.divCeil(usize, packs, 2 * threads) catch unreachable);
const grid: u32 = @intCast(@min(std.math.ceilPowerOfTwo(usize, need) catch max_blocks, max_blocks));
Expand Down
2 changes: 0 additions & 2 deletions zig/src/cuda/root.zig
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ pub const Dim3 = launch.Dim3;
pub const graph = @import("graph.zig");
pub const cublaslt = @import("cublaslt.zig");
pub const nccl = @import("nccl.zig");
pub const tp_link = @import("tp_link.zig");
pub const roce = @import("roce.zig");
pub const triton = @import("triton.zig");
pub const aot = @import("aot.zig");
Expand Down Expand Up @@ -64,7 +63,6 @@ test {
_ = carveout;
_ = @import("nvfp4.zig");
_ = @import("modelopt.zig");
_ = @import("tp_link.zig");
_ = @import("ck.zig");
_ = @import("tp_watch.zig");
}
18 changes: 17 additions & 1 deletion zig/src/cuda/tp_group.zig
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//! A tensor-parallel group over NCCL: NCCL_COMM_ID gives every rank the same id; rows meet in rank order.
//! A tensor-parallel group over NCCL (NCCL_COMM_ID; rows in rank order); two ranks add RoCE small gathers (roce.zig).
const std = @import("std");
const nccl = @import("nccl.zig");
const driver = @import("driver.zig");
const stream_ = @import("stream.zig");
const memory = @import("memory.zig");
const roce = @import("roce.zig");

const Stream = stream_.Stream;

Expand All @@ -12,6 +13,7 @@ pub const Group = struct {
comm: nccl.Comm,
rank: usize,
world: usize,
fast: ?*roce.Gather = null, // two ranks' small all-gathers by RoCE writes (openRoce), when both ranks brought it up

/// Rank `rank` of `world` (NCCL opened at run time; NCCL_COMM_ID names rank 0's address, every rank the same).
pub fn open(rank: usize, world: usize) !Group {
Expand All @@ -26,13 +28,26 @@ pub const Group = struct {
}

pub fn close(g: *Group) void {
if (g.fast) |f| f.deinit();
_ = g.lib.api.ncclCommDestroy(g.comm);
g.lib.close();
g.* = undefined;
}

/// Two ranks: gathers up to `max_bytes` a rank go by RoCE writes if both ranks bring it up; else NCCL keeps them.
pub fn openRoce(g: *Group, gpa: std.mem.Allocator, io: std.Io, d: *const driver.Driver, s: Stream, max_bytes: usize) !void {
if (g.world != 2 or g.fast != null) return;
g.fast = try roce.Gather.init(gpa, io, d, g, s, roce.wanted(), max_bytes);
}

/// A failed RoCE gather's error (its rows hold nothing valid): call it after a synchronize that reads a gather.
pub fn check(g: *const Group) !void {
if (g.fast) |f| try f.check();
}

/// `bytes` at `mine` from every rank into `all` in rank order (world * bytes there), on `s`.
pub fn allGather(g: *const Group, s: Stream, mine: u64, all: u64, bytes: usize) !void {
if (g.fast) |f| if (f.fits(bytes)) return f.gather(s.handle, mine, all, bytes);
try g.lib.check(g.lib.api.ncclAllGather(mine, all, bytes, .u8, g.comm, s.handle), "ncclAllGather");
}

Expand Down Expand Up @@ -68,6 +83,7 @@ pub const Group = struct {
try dev.uploadAsync(g.rank * size, std.mem.asBytes(&mine), s.handle);
try g.allGather(s, dev.ptr + g.rank * size, dev.ptr, size);
try s.synchronize();
try g.check();
try dev.download(0, std.mem.sliceAsBytes(out));
}
};
169 changes: 0 additions & 169 deletions zig/src/cuda/tp_link.zig

This file was deleted.

Loading
Loading