Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
b731206
feat(hip): the model-free kernels on #463's runtime: attention, Delta…
BlivionIaG Oct 10, 2026
67d9479
feat(core): weight formats behind one interface, MLX affine 2- to 8-b…
BlivionIaG Oct 10, 2026
48abd99
feat(core): a kernel registry that picks a product's tile by tuned co…
BlivionIaG Oct 10, 2026
6254228
feat(hip): the MLX affine products: dot2 tiles, the gfx11 matrix-core…
BlivionIaG Oct 10, 2026
9b6b260
docs(hip): the device bitcode of Ubuntu's packaged HIP, and no rocWMM…
BlivionIaG Oct 11, 2026
1152c67
Merge branch 'hip-kernels-ops' into hip-kernels-affine
BlivionIaG Oct 11, 2026
df83c6f
Merge branch 'hip-kernels-ops' into hip-kernels-affine
BlivionIaG Oct 11, 2026
5d05894
chore(hip): gdn_prefill.hip drops the vLLM SPDX lines it kept from th…
BlivionIaG Oct 11, 2026
a579284
Merge branch 'hip-kernels-affine' into fam-new
BlivionIaG Oct 11, 2026
e6c11fb
feat(qwen3_5): the GPU backends' checkpoint loader, on the host
BlivionIaG Oct 10, 2026
eb9bd0f
fix(qwen3_5): un-center an MTP head shipped zero-centered
BlivionIaG Oct 11, 2026
4c231bf
feat(qwen3_5): the HIP config refuses what the kernels do not compute…
BlivionIaG Oct 11, 2026
02c1dd6
Merge remote-tracking branch 'upstream/main' into fam-r2
BlivionIaG Oct 12, 2026
57fadd1
feat(hip): the runtime pieces an engine uses beyond #463's model-free…
BlivionIaG Oct 10, 2026
211ea81
feat(hip): the kernels a tensor-parallel rank and the MTP head add
BlivionIaG Oct 10, 2026
42664f9
feat(qwen3_5): the Qwen3.5 / Qwen3.6 engine on HIP, its native server…
BlivionIaG Oct 10, 2026
3d9bd2e
feat(hip): one rank source: --speed-up is refused, the HIP engine's r…
BlivionIaG Oct 10, 2026
a25c8e2
feat(qwen3_5): the HIP prompt cache serves serial requests too
BlivionIaG Oct 10, 2026
3092774
test(qwen3_5): chat with the prompt cache equals chat without it thro…
BlivionIaG Oct 10, 2026
9a4e10f
feat(qwen3_5): a prompt runs 512-row chunks while other streams decode
BlivionIaG Oct 11, 2026
3f396fc
feat(hip): RDNA4 runs on the dot2 tiles; matrix=on is refused where n…
BlivionIaG Oct 11, 2026
fc795cb
test(qwen3_5): serve_rewind.py's docstring on one line, as the lean c…
BlivionIaG Oct 11, 2026
10f67d9
refactor(qwen3_5): the engine reaches the other ranks through hip/col…
BlivionIaG Oct 11, 2026
7f5fd5b
build(hip): the HIP server's CLI module takes EXLR8's import, as main…
BlivionIaG Oct 12, 2026
badbb6f
feat(qwen3_5): structured output on HIP: the lane core's grammar mask…
BlivionIaG Oct 11, 2026
1ae1078
style(hip): the ops headers end without a blank line, as git diff --c…
BlivionIaG Oct 14, 2026
47612d0
Merge branch 'hip-kernels-ops' into qwen35-family (ops headers end wi…
BlivionIaG Oct 14, 2026
deec0a9
Merge branch 'qwen35-family' into qwen35-structured (ops headers end …
BlivionIaG Oct 14, 2026
5537d6a
fix(hip): the paged prefill tile calls expf, as the flat tile does
BlivionIaG Oct 14, 2026
9178585
Merge branch 'hip-kernels-ops' into qwen35-family (the paged prefill …
BlivionIaG Oct 14, 2026
28c3160
Merge branch 'qwen35-family' into qwen35-structured (the paged prefil…
BlivionIaG Oct 14, 2026
d91b074
fix(hip): one fp32 DeltaNet recurrence at every length; the chunked p…
BlivionIaG Oct 14, 2026
1da7042
Merge branch 'hip-kernels-ops' into qwen35-family (one fp32 DeltaNet …
BlivionIaG Oct 14, 2026
81d6529
Merge branch 'qwen35-family' into qwen35-structured (one fp32 DeltaNe…
BlivionIaG Oct 14, 2026
edc5b3f
refactor(hip): the policy's gdn switch goes with the chunked recurren…
BlivionIaG Oct 14, 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
refactor(qwen3_5): the engine reaches the other ranks through hip/col…
…lective.zig; RCCL becomes its own PR

The engine called RCCL and the ranks' TCP link directly. It now takes a collective.Group (the rank's link, its
communicator opened once the GPU is current, its close) and a collective.Comm (all-reduce, all-gather,
broadcast); tf-qwen35-test's group joins through the same hip.joinGroup as the server. This PR builds with no
collectives backend: joinGroup refuses more than one rank, the server lists no --tp, and the rccl_lib policy key
goes. RCCL (comm/: the library, the link, the group) returns behind the interface in the next PR, as #491's
order has it; the engine's tensor-parallel paths and their kernels stay here, with their tests.
  • Loading branch information
BlivionIaG committed Oct 12, 2026
commit 10f67d94f63fb61766e899413b4e2652df512ff8
27 changes: 8 additions & 19 deletions zig/src/families/qwen3_5/backend/hip/engine/engine.zig
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ pub const Options = struct {
device: c_int = 0,
/// Positions past a reply a verify writes (the window's rows and one more).
slack: usize = 0,
/// Tensor parallelism: this rank of `world`, `id` being the communicator's unique id, the same on every rank.
/// Tensor parallelism: this rank of `world`, and the group it joined (it opens the communicator).
rank: usize = 0,
world: usize = 1,
id: ?hip.rccl.UniqueId = null,
group: ?hip.collective.Group = null,
/// Replay rounds from captured graphs (the policy's `graphs` turns it off).
graphs: bool = true,
/// What the run may use, resolved once by whoever opens the engine.
Expand Down Expand Up @@ -85,9 +85,8 @@ pub const Engine = struct {
/// The keys and values of every stream and prefix entry.
pool: pages.Pool,
drawer: draw.Drawer,
/// Tensor parallelism: RCCL and this rank's communicator.
rccl: hip.rccl.Rccl = undefined,
comm: hip.rccl.Comm = undefined,
/// Tensor parallelism: this rank's communicator.
comm: hip.collective.Comm = undefined,
graphs: round_graphs.Graphs,
/// The draft head's batches replay graphs (the head holds no collective, so under tp too unless graphs=off).
head_graphs: bool = true,
Expand Down Expand Up @@ -117,15 +116,8 @@ pub const Engine = struct {
e.stream = try hip.Stream.init(&e.driver);
errdefer e.stream.deinit();
const group: ?slicing.Rank = if (o.world > 1) .{ .rank = o.rank, .world = o.world } else null;
if (group != null) {
e.rccl = try hip.rccl.Rccl.open(o.policy.rccl_lib.slice());
errdefer e.rccl.close();
e.comm = try hip.rccl.Comm.init(&e.rccl, o.id orelse return error.NoUniqueId, o.rank, o.world);
}
errdefer if (group != null) {
e.comm.deinit();
e.rccl.close();
};
if (group != null) e.comm = try (o.group orelse return error.NoGroup).open();
errdefer if (group != null) e.comm.close();
if (o.preflight) |pf| {
// a rank loads its share of the checkpoint, near enough to refuse before reading it
pf.* = .{ .pool = try e.budget(io), .held = hip.usage(false).device, .weights = admission.weightBytes(io, dir) / o.world };
Expand Down Expand Up @@ -264,10 +256,7 @@ pub const Engine = struct {
e.weights.deinit();
e.stream.deinit();
e.lib.unload();
if (e.o.world > 1) {
e.comm.deinit();
e.rccl.close();
}
if (e.o.world > 1) e.comm.close();
e.ctx.deinit();
e.driver.close();
e.gpa.destroy(e);
Expand Down Expand Up @@ -318,7 +307,7 @@ pub const Engine = struct {
}

/// vocab_gather: every rank's slice of `rows` logits rows, joined on the device into whole rows in rank order.
fn joined(e: *Engine, o: hip.ops.Ops, c: hip.rccl.Comm, slice: hip.ops.Tensor, rows: usize) !hip.ops.Tensor {
fn joined(e: *Engine, o: hip.ops.Ops, c: hip.collective.Comm, slice: hip.ops.Tensor, rows: usize) !hip.ops.Tensor {
const width = e.model().head.n;
const n = rows * width;
const size_of = slice.kind.size();
Expand Down
4 changes: 2 additions & 2 deletions zig/src/families/qwen3_5/backend/hip/engine/hip_lanes.zig
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub const Hip = struct {
matched: std.ArrayList(u32) = .empty,
copied: std.ArrayList([3]u32) = .empty,
/// Tensor parallelism: the other ranks, which get every step before this rank runs it (`worker.follow`).
link: ?*const hip.link.Link = null,
link: ?hip.collective.Link = null,
msg: std.ArrayList(u32) = .empty,
/// This engine's forward and head timings, filled by `measure` (none: the rule drafts the deepest it may).
costs: costs.Costs = .{},
Expand Down Expand Up @@ -104,7 +104,7 @@ pub const Hip = struct {
}

/// Rank 0 of a tensor-parallel group: every step also goes to the ranks behind `link`.
pub fn withLink(h: *Hip, link: *const hip.link.Link) void {
pub fn withLink(h: *Hip, link: hip.collective.Link) void {
h.link = link;
h.prefix.link = link;
}
Expand Down
2 changes: 1 addition & 1 deletion zig/src/families/qwen3_5/backend/hip/engine/hip_prefix.zig
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub const Prefix = struct {
/// Snapshot slots in use.
used: std.ArrayList(bool) = .empty,
/// The other ranks, when this is rank 0 of a group.
link: ?*const hip.link.Link = null,
link: ?hip.collective.Link = null,
msg: std.ArrayList(u32) = .empty,
/// The slot the last restore copied from (reset as a pass begins): the message that begins the pass names it.
restored: u32 = worker.no_snapshot,
Expand Down
6 changes: 3 additions & 3 deletions zig/src/families/qwen3_5/backend/hip/engine/native.zig
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ fn prepare(a: std.mem.Allocator, gpa: std.mem.Allocator, io: std.Io, dev: hip.De
.policy = dev.policy,
.rank = o.rank,
.world = o.world,
.id = if (dev.group) |g| g.id else null,
.group = dev.group,
}) catch |err| return switch (err) {
error.WeightsDoNotFit => refuse(a, problem, "the checkpoint's {d:.1} GiB of weights do not fit the {d:.1} GiB the HIP memory budget grants ({d:.1} GiB free less a {d:.1} GiB reserve{s}); free device memory or adjust TENSORFOLD_MEMORY_RESERVE_GIB / TENSORFOLD_HIP_MEMORY_LIMIT_GB", .{ gibs(pf.weights), gibs(pf.pool.room(pf.held)), gibs(pf.pool.free), gibs(pf.pool.reserve), if (pf.pool.limit != null) ", under TENSORFOLD_HIP_MEMORY_LIMIT_GB" else "" }),
error.BadReserve => refuse(a, problem, "TENSORFOLD_MEMORY_RESERVE_GIB: a number of GiB from 2 to the memory's size", .{}),
Expand Down Expand Up @@ -182,7 +182,7 @@ fn openEngine(a: std.mem.Allocator, gpa: std.mem.Allocator, io: std.Io, dev: hip
if (hip.usage(false).device - before != head) return refuse(a, problem, "the draft head holds {d} device bytes, the plan says {d}", .{ hip.usage(false).device - before, head });
if (p.cache.pages > 0) own.backend.keepPages(p.cache.pages, p.cache.snaps);
// a lone rank times its forwards for the depth rule; the ranks of a group draft without costs
if (dev.group) |g| own.backend.withLink(&g.link) else own.backend.measure();
if (dev.group) |g| own.backend.withLink(g.link()) else own.backend.measure();
return .{
.backend = own.backend.backend(),
.facts = own.backend.facts(),
Expand All @@ -201,5 +201,5 @@ fn followRank(a: std.mem.Allocator, gpa: std.mem.Allocator, io: std.Io, dev: hip
defer gpa.free(p.startup);
var w = try worker.Worker.init(gpa, p.e);
defer w.deinit();
try w.follow(&dev.group.?.link);
try w.follow(dev.group.?.link());
}
2 changes: 1 addition & 1 deletion zig/src/families/qwen3_5/backend/hip/engine/worker.zig
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ pub const Worker = struct {
}

/// Runs rank 0's steps until it says stop.
pub fn follow(w: *Worker, link: *const hip.link.Link) !void {
pub fn follow(w: *Worker, link: hip.collective.Link) !void {
var msg: std.ArrayList(u32) = .empty;
defer msg.deinit(w.gpa);
var ids: [max_windows]u32 = undefined;
Expand Down
8 changes: 4 additions & 4 deletions zig/src/families/qwen3_5/backend/hip/forward/reduce.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ const view = @import("../model/view.zig");
const Ops = hip.ops.Ops;
const Tensor = hip.ops.Tensor;

pub const Error = hip.ops.Error || hip.rccl.Error;
pub const Error = hip.ops.Error || hip.collective.Error;

/// `n` fp32 values summed over the ranks in rank order, so a row's sum does not depend on the rows sharing the call.
pub fn sum(o: Ops, c: hip.rccl.Comm, y: u64, n: usize) Error!u64 {
pub fn sum(o: Ops, c: hip.collective.Comm, y: u64, n: usize) Error!u64 {
const out = try o.arena.of(f32, n);
if (c.world == 2) {
try c.allReduce(y, out, n, .f32, o.stream);
Expand All @@ -32,7 +32,7 @@ pub fn residual(o: Ops, m: *const view.Model, x: Tensor, y: Tensor, n: usize) Er
}

/// The ranks' logits slices (world, rows, width) of the activation dtype, gathered into `out`.
pub fn gather(o: Ops, c: hip.rccl.Comm, slice: Tensor, out: u64, n: usize) Error!void {
const dtype: hip.rccl.Dtype = if (slice.kind == .f16) .f16 else .bf16;
pub fn gather(o: Ops, c: hip.collective.Comm, slice: Tensor, out: u64, n: usize) Error!void {
const dtype: hip.collective.Dtype = if (slice.kind == .f16) .f16 else .bf16;
try c.allGather(slice.ptr, out, n, dtype, o.stream);
}
2 changes: 1 addition & 1 deletion zig/src/families/qwen3_5/backend/hip/model/view.zig
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ pub const Model = struct {
/// What this rank sees: under tp its heads and value heads.
spec: Spec,
/// The tensor-parallel communicator; null on one rank.
tp: ?hip.rccl.Comm = null,
tp: ?hip.collective.Comm = null,
act: Kind,
embed: Projection,
layers: []const Layer,
Expand Down
127 changes: 127 additions & 0 deletions zig/src/hip/collective.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
//! What a tensor-parallel engine asks of its ranks: collectives on its streams, and rank 0's words to the others.

const std = @import("std");
const abi = @import("abi.zig");

pub const Error = error{CollectiveFailed};
pub const LinkError = error{LinkFailed} || std.mem.Allocator.Error;
/// Why a rank could not join its group: no tensor parallelism in this build, no RCCL, or the link between the ranks.
pub const JoinError = error{ NoTensorParallel, NoRccl, NoId, SocketFailed, BindFailed, ConnectFailed, LinkClosed, BadRank, MixedGpus } || std.mem.Allocator.Error;

/// The join of a build without a collectives backend: one rank only.
pub fn noGroup(_: std.mem.Allocator, _: std.Io, _: u32, _: u32, _: []const u8, _: u16, _: @import("caps.zig").Caps, _: *@import("policy.zig").Policy) JoinError!Group {
return error.NoTensorParallel;
}

/// The element types the forward moves, in RCCL's numbering.
pub const Dtype = enum(c_int) { u8 = 1, i32 = 2, i64 = 4, f16 = 6, f32 = 7, bf16 = 9 };

/// One rank's communicator. A collective queues on its stream and waits for every rank's matching call.
pub const Comm = struct {
ptr: *anyopaque,
vtable: *const VTable,
rank: usize,
world: usize,

pub const VTable = struct {
all_reduce: *const fn (ptr: *anyopaque, send: u64, recv: u64, n: usize, dtype: Dtype, stream: abi.Stream) Error!void,
all_gather: *const fn (ptr: *anyopaque, send: u64, recv: u64, n: usize, dtype: Dtype, stream: abi.Stream) Error!void,
broadcast: *const fn (ptr: *anyopaque, send: u64, recv: u64, n: usize, dtype: Dtype, root: usize, stream: abi.Stream) Error!void,
close: *const fn (ptr: *anyopaque) void,
};

/// `recv` = the ranks' `send` summed, `n` values of `dtype`.
pub fn allReduce(c: Comm, send: u64, recv: u64, n: usize, dtype: Dtype, stream: abi.Stream) Error!void {
return c.vtable.all_reduce(c.ptr, send, recv, n, dtype, stream);
}

/// `recv` (world * n values) = every rank's `send` (n values) in rank order.
pub fn allGather(c: Comm, send: u64, recv: u64, n: usize, dtype: Dtype, stream: abi.Stream) Error!void {
return c.vtable.all_gather(c.ptr, send, recv, n, dtype, stream);
}

/// `root`'s `send` into every rank's `recv`, `n` values.
pub fn broadcast(c: Comm, send: u64, recv: u64, n: usize, dtype: Dtype, root: usize, stream: abi.Stream) Error!void {
return c.vtable.broadcast(c.ptr, send, recv, n, dtype, root, stream);
}

pub fn close(c: Comm) void {
c.vtable.close(c.ptr);
}
};

/// Rank 0's channel to the others: it sends each step, a follower takes them in order.
pub const Link = struct {
ptr: *anyopaque,
vtable: *const VTable,

pub const VTable = struct {
send: *const fn (ptr: *anyopaque, words: []const u32) LinkError!void,
recv: *const fn (ptr: *anyopaque, gpa: std.mem.Allocator, out: *std.ArrayList(u32)) LinkError!void,
};

/// Rank 0: `words` to every follower.
pub fn send(l: Link, words: []const u32) LinkError!void {
return l.vtable.send(l.ptr, words);
}

/// A follower: rank 0's next message into `out` (cleared first).
pub fn recv(l: Link, gpa: std.mem.Allocator, out: *std.ArrayList(u32)) LinkError!void {
return l.vtable.recv(l.ptr, gpa, out);
}
};

/// What a rank holds once it joined its group: the link, and its communicator opened when the engine's GPU is current.
pub const Group = struct {
ptr: *anyopaque,
vtable: *const VTable,
rank: usize,
world: usize,

pub const VTable = struct {
link: *const fn (ptr: *anyopaque) Link,
open: *const fn (ptr: *anyopaque) Error!Comm,
close: *const fn (ptr: *anyopaque, gpa: std.mem.Allocator) void,
};

pub fn link(g: Group) Link {
return g.vtable.link(g.ptr);
}

/// This rank's communicator: blocks until every rank has opened its own; the engine's device is current.
pub fn open(g: Group) Error!Comm {
return g.vtable.open(g.ptr);
}

pub fn close(g: Group, gpa: std.mem.Allocator) void {
g.vtable.close(g.ptr, gpa);
}
};

test "a comm forwards each collective to its implementation" {
const Fake = struct {
calls: [3]usize = .{ 0, 0, 0 },
closed: bool = false,
fn reduce(ptr: *anyopaque, _: u64, _: u64, _: usize, _: Dtype, _: abi.Stream) Error!void {
@as(*@This(), @ptrCast(@alignCast(ptr))).calls[0] += 1;
}
fn gather(ptr: *anyopaque, _: u64, _: u64, _: usize, _: Dtype, _: abi.Stream) Error!void {
@as(*@This(), @ptrCast(@alignCast(ptr))).calls[1] += 1;
}
fn cast(ptr: *anyopaque, _: u64, _: u64, _: usize, _: Dtype, _: usize, _: abi.Stream) Error!void {
@as(*@This(), @ptrCast(@alignCast(ptr))).calls[2] += 1;
}
fn shut(ptr: *anyopaque) void {
@as(*@This(), @ptrCast(@alignCast(ptr))).closed = true;
}
};
var f: Fake = .{};
const c: Comm = .{ .ptr = &f, .vtable = &.{ .all_reduce = Fake.reduce, .all_gather = Fake.gather, .broadcast = Fake.cast, .close = Fake.shut }, .rank = 1, .world = 2 };
try c.allReduce(0, 0, 1, .f32, null);
try c.allGather(0, 0, 1, .bf16, null);
try c.allGather(0, 0, 1, .bf16, null);
try c.broadcast(0, 0, 1, .i32, 0, null);
c.close();
try std.testing.expectEqual([3]usize{ 1, 2, 1 }, f.calls);
try std.testing.expect(f.closed);
}
36 changes: 0 additions & 36 deletions zig/src/hip/comm/group.zig

This file was deleted.

Loading