Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
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
864fe25
Graph cache: effective settings have one digest for ranks to compare …
jayleaton Oct 16, 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
bf19238
TP RoCE: a failed transport halts its QPs, drains them and keeps its …
jayleaton Oct 11, 2026
beae7e8
TP RoCE: tf-tp-test failfast V transport checks the failed-transport …
jayleaton Oct 11, 2026
602aad5
Fix RoCE test smaps lookup for merged mappings
jayleaton Oct 11, 2026
890dfc6
TP RoCE: run_hosts.sh gives NCCL the RoCE picker's ports when neither…
jayleaton Oct 11, 2026
a3e2fb1
TP NCCL: all_reduce's doc says NCCL adds in its ring's order, so its …
jayleaton Oct 14, 2026
62a75ae
TP: keep Linux-only transport host tests off macOS builds
jayleaton Oct 15, 2026
e2504f6
TP: bootstrap compares the graph cache's effective settings, so a ran…
jayleaton Oct 16, 2026
5410eac
Session memory for paged-KV families: page pool, prefix trie, RAM res…
jayleaton Oct 10, 2026
0d0bdb2
Sessions: the page map is rehashed before tombstones fill it
jayleaton Oct 11, 2026
2cf61d3
Sessions: honor zero residency budgets and reserve uncapped requests
jayleaton Oct 15, 2026
dcdc30c
Keep the Linux NVMe lane test out of portable host tests
cwschroeder 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
Graph cache: effective settings have one digest for ranks to compare …
…at start; RUNBOOK says what a mismatch does

An off cache never calls Agree, so a rank left on waits at its first miss for a vote that never comes. Settings.effective
applies TF_GRAPH_CACHE, clamps min_keep and maps every off cache (0, off, OFF, a max of 0) to one value; Cache.init runs
with it, and Settings.digest gives ranks those bytes to compare before building a cache. Hits still make no collective.
  • Loading branch information
jayleaton committed Oct 16, 2026
commit 864fe253277eef5909680c5d5ed42e1aacce6874
6 changes: 4 additions & 2 deletions RUNBOOK.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,10 @@ budget free for the next states.
`TF_HEAT_HIGH` and `TF_HEAT_LOW`, in degrees Celsius and set together, make each prompt chunk wait while the hottest
thermal zone (under `/sys/class/thermal`, or `TF_HEAT_ROOT`) is above the high band, until it is at or under the low one.
The server logs `heat_wait_s`, a cancel ends the wait, and the reply's tokens do not change.
`TF_GRAPH_CACHE=0` (or `off`) runs every step eagerly in any family that installs the keyed CUDA graph cache, without a
rebuild; set it alike on every tensor-parallel rank.
`TF_GRAPH_CACHE=0` (or `off`, any case) runs every step eagerly in any family that installs the keyed CUDA graph cache,
without a rebuild. Set it alike on every tensor-parallel rank: an off rank never joins the cache's per-miss vote, so a
rank left on would wait at its first miss, and only the off rank logs the switch. Ranks that share a cache compare
`Settings.digest` of their effective settings at start, before building it, and refuse to start when they differ.
Archives whose names contain `host-only` are CPU verification artifacts and cannot serve CUDA inference.

## Flash Next and paired Metal serving
Expand Down
34 changes: 29 additions & 5 deletions zig/src/cuda/graph_cache.zig
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub const Body = struct {
run: *const fn (ctx: *anyopaque, stream: Stream) anyerror!void,
};

/// Every rank's verdict AND-ed on a miss (hits never call it), so ranks capture, evict and fall back together.
/// Every rank's verdict AND-ed on a miss, never a hit; an off cache never votes, so ranks match `Settings.digest`.
pub const Agree = struct {
ctx: *anyopaque,
all: *const fn (ctx: *anyopaque, ok: bool) anyerror!bool,
Expand All @@ -39,6 +39,30 @@ pub const Settings = struct {
if (std.mem.eql(u8, v, "0") or std.ascii.eqlIgnoreCase(v, "off")) out.on = false;
return out;
}

/// What a cache runs with: the operator's value, min_keep under max (0 with hold), and every off cache one value.
pub fn effective(s: Settings, value: ?[]const u8) Settings {
var out = s.operator(value);
if (!out.on or out.max == 0) return .{ .on = false, .max = 0, .min_keep = 0, .hold = false };
out.min_keep = if (out.hold) 0 else @min(out.min_keep, out.max);
return out;
}

/// `effective` under this process's TF_GRAPH_CACHE.
pub fn fromEnv(s: Settings) Settings {
return s.effective(if (std.c.getenv("TF_GRAPH_CACHE")) |v| std.mem.span(v) else null);
}

/// The effective settings as bytes for ranks to compare at start (a family's bootstrap agreement), never per step.
pub fn digest(s: Settings) [10]u8 {
const e = s.effective(null);
var out: [10]u8 = undefined;
out[0] = @intFromBool(e.on);
out[1] = @intFromBool(e.hold);
std.mem.writeInt(u32, out[2..6], e.max, .little);
std.mem.writeInt(u32, out[6..10], e.min_keep, .little);
return out;
}
};

pub const Outcome = enum { replayed, captured, eager };
Expand All @@ -60,11 +84,10 @@ pub fn Cache(comptime Key: type) type {
failed: bool = false, // a capture failed on some rank: eager from here on
stats: struct { replayed: u64 = 0, captured: u64 = 0, eager: u64 = 0, evicted: u64 = 0, dropped: u64 = 0, floor_hits: u64 = 0 } = .{},

/// The cache with `settings`, unless TF_GRAPH_CACHE turns it off (set it alike on every rank, as `settings`).
/// The cache with `settings.fromEnv()`: every rank sharing an `agree` must hold an equal `Settings.digest`.
pub fn init(gpa: std.mem.Allocator, engine: Engine, settings: Settings) Self {
var s = settings.operator(if (std.c.getenv("TF_GRAPH_CACHE")) |v| std.mem.span(v) else null);
if (!quiet and settings.on and !s.on) std.log.info("graph cache: off (TF_GRAPH_CACHE), every step eager", .{});
s.min_keep = @min(s.min_keep, s.max); // the floor never holds more than the configured max
const s = settings.fromEnv();
if (!quiet and settings.on and settings.max > 0 and !s.on) std.log.info("graph cache: off (TF_GRAPH_CACHE), every step eager", .{});
return .{ .gpa = gpa, .engine = engine, .settings = s, .cap = s.max };
}

Expand Down Expand Up @@ -421,4 +444,5 @@ test "graph cache: fingerprint" {

test {
_ = @import("graph_cache_regression_test.zig");
_ = @import("graph_cache_ranks_test.zig");
}
138 changes: 138 additions & 0 deletions zig/src/cuda/graph_cache_ranks_test.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
//! Two in-process ranks with fake engines: equal effective settings vote on misses only; a mismatch is a stall.

const std = @import("std");
const cache = @import("graph_cache.zig");
const Stream = @import("stream.zig").Stream;
const no_stream: Stream = .{ .d = undefined, .handle = null };
const equal = std.testing.expectEqual;
const Settings = cache.Settings;

const Engine = struct {
captures: usize = 0,
live: usize = 0,
handles: [8]u8 = undefined,

fn engine(e: *Engine) cache.Engine {
return .{ .ctx = e, .capture = capture, .launch = launch, .free = free };
}
fn capture(p: *anyopaque, _: Stream, _: cache.Body) !*anyopaque {
const e: *Engine = @ptrCast(@alignCast(p));
e.captures += 1;
e.live += 1;
return &e.handles[e.captures % e.handles.len];
}
fn launch(_: *anyopaque, _: *anyopaque, _: Stream) !void {}
fn free(p: *anyopaque, _: *anyopaque) void {
const e: *Engine = @ptrCast(@alignCast(p));
e.live -= 1;
}
fn body(e: *Engine) cache.Body {
return .{ .ctx = e, .run = run };
}
fn run(_: *anyopaque, _: Stream) !void {}
};

/// The two ranks' votes in call order; a rank waits at most `wait_ns` for the other's vote of the same round.
const Board = struct {
votes: [2][16]bool = undefined,
cast: [2]std.atomic.Value(u32) = .{ .init(0), .init(0) },
wait_ns: u64,

fn vote(b: *Board, rank: u1, ok: bool) !bool {
const r = b.cast[rank].load(.monotonic);
if (r == b.votes[rank].len) return error.TooManyVotes;
b.votes[rank][r] = ok;
b.cast[rank].store(r + 1, .release);
const other = 1 - rank;
const deadline = now() + b.wait_ns;
while (b.cast[other].load(.acquire) <= r) {
if (now() > deadline) return error.PeerNeverVoted;
std.Thread.yield() catch {};
}
return ok and b.votes[other][r];
}

fn now() u64 {
var ts: std.c.timespec = undefined;
_ = std.c.clock_gettime(.MONOTONIC, &ts);
return @as(u64, @intCast(ts.sec)) * std.time.ns_per_s + @as(u64, @intCast(ts.nsec));
}
};

const Rank = struct {
board: *Board,
id: u1,
engine: Engine = .{},
outcomes: [8]cache.Outcome = undefined,
err: ?anyerror = null,

fn all(ctx: *anyopaque, ok: bool) anyerror!bool {
const r: *Rank = @ptrCast(@alignCast(ctx));
return r.board.vote(r.id, ok);
}

/// One rank's steps over `keys` with `settings` exactly as its process resolved them.
fn steps(r: *Rank, settings: Settings, ks: []const u32) void {
var c = cache.Cache(u32).init(std.testing.allocator, r.engine.engine(), settings);
defer c.deinit();
c.agree = .{ .ctx = r, .all = all };
for (ks, 0..) |k, i| r.outcomes[i] = c.run(k, no_stream, 7, r.engine.body()) catch |e| {
r.err = e;
return;
};
}
};

const keys = [_]u32{ 1, 2, 1, 2, 1 };

test "graph cache ranks: equal enabled settings capture together and vote on each miss, never on a hit" {
var board: Board = .{ .wait_ns = 5 * std.time.ns_per_s };
var ranks = [2]Rank{ .{ .board = &board, .id = 0 }, .{ .board = &board, .id = 1 } };
const s = (Settings{ .max = 4 }).effective(null);
const t = try std.Thread.spawn(.{}, Rank.steps, .{ &ranks[1], s, &keys });
ranks[0].steps(s, &keys);
t.join();
const want = [_]cache.Outcome{ .captured, .captured, .replayed, .replayed, .replayed };
for (&ranks) |*r| {
try equal(@as(?anyerror, null), r.err);
try std.testing.expectEqualSlices(cache.Outcome, &want, r.outcomes[0..keys.len]);
try equal(@as(u32, 4), board.cast[r.id].load(.acquire)); // two misses: room and capture each, hits none
try equal(@as(usize, 0), r.engine.live);
}
}

test "graph cache ranks: TF_GRAPH_CACHE 0, off and OFF are one effective setting, and an off cache never votes" {
const d: Settings = .{};
const off = d.effective("0").digest();
try std.testing.expectEqualSlices(u8, &off, &d.effective("off").digest());
try std.testing.expectEqualSlices(u8, &off, &d.effective("OFF").digest());
try std.testing.expectEqualSlices(u8, &off, &(Settings{ .max = 0, .hold = true }).digest());
try std.testing.expect(!std.mem.eql(u8, &off, &d.effective(null).digest()));
const held: Settings = .{ .hold = true, .min_keep = 2 };
try std.testing.expectEqualSlices(u8, &held.digest(), &(Settings{ .hold = true, .min_keep = 30 }).digest());
try std.testing.expectEqualSlices(u8, &d.effective("1").digest(), &d.effective(null).digest());
var board: Board = .{ .wait_ns = 0 };
var ranks = [2]Rank{ .{ .board = &board, .id = 0 }, .{ .board = &board, .id = 1 } };
ranks[0].steps(d.effective("0"), &keys);
ranks[1].steps(d.effective("OFF"), &keys);
for (&ranks) |*r| {
try equal(@as(?anyerror, null), r.err);
for (r.outcomes[0..keys.len]) |o| try equal(cache.Outcome.eager, o);
try equal(@as(u32, 0), board.cast[r.id].load(.acquire));
try equal(@as(usize, 0), r.engine.captures);
}
}

test "graph cache ranks: one rank switched off leaves the other waiting at its first miss; digests show it first" {
const d: Settings = .{};
try std.testing.expect(!std.mem.eql(u8, &d.effective(null).digest(), &d.effective("off").digest()));
var board: Board = .{ .wait_ns = 50 * std.time.ns_per_ms };
var ranks = [2]Rank{ .{ .board = &board, .id = 0 }, .{ .board = &board, .id = 1 } };
ranks[1].steps(d.effective("off"), &keys);
try equal(@as(?anyerror, null), ranks[1].err);
try equal(@as(u32, 0), board.cast[1].load(.acquire)); // the off rank ran every step eagerly without a vote
ranks[0].steps(d.effective(null), &keys);
try equal(@as(?anyerror, error.PeerNeverVoted), ranks[0].err); // in production this wait has no deadline
try equal(@as(u32, 1), board.cast[0].load(.acquire));
try equal(@as(usize, 0), ranks[0].engine.live);
}