Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
881ccca
cuda: a process-wide cap on DeviceBuffer and pinned HostBuffer bytes
plotarmordev Oct 16, 2026
b00dd4e
drama: the temporal codebook tower
plotarmordev Oct 16, 2026
c8af505
drama: the speech codec, with codec.pth read without Python
plotarmordev Oct 16, 2026
e192c0f
engine_api: speech requests, speech info and a submit_speech hook
plotarmordev Oct 16, 2026
ab45904
native: Drama 3 (fish_omni) on CUDA
plotarmordev Oct 16, 2026
7553d00
server: POST /v1/audio/speech
plotarmordev Oct 16, 2026
8ba4307
tests: Drama 3 backbone and tower oracles, replays and stage traces
plotarmordev Oct 16, 2026
20249e9
drama: incremental codec decode, bit-identical to the whole decode
plotarmordev Oct 16, 2026
93fcaab
tests: Drama 3 codec oracle, replays and stage trace
plotarmordev Oct 16, 2026
d84284d
engine_api: audio events, so a speech engine can publish PCM while it…
plotarmordev Oct 16, 2026
71c31a9
build: Drama 3 backbone and tower kernels, the drama module, the nati…
plotarmordev Oct 16, 2026
588f1f1
server: stream: true on /v1/audio/speech sends raw PCM chunks as they…
plotarmordev Oct 16, 2026
d8c6a47
drama: the backbone's one-row GEMM stages its weights through shared …
plotarmordev Oct 16, 2026
10796d4
build: the Drama 3 codec kernels and the codec tool steps
plotarmordev Oct 16, 2026
8bc6814
tests: tf-drama-codec-stream-oracle, whole against chunked codec decodes
plotarmordev Oct 16, 2026
40c7c87
core: a direct read the file system refuses goes through the page cache
plotarmordev Oct 16, 2026
23a7fcc
cuda: Module.holds, whether a loaded image defines a device global
plotarmordev Oct 16, 2026
6f85731
drama: the Drama 3 text backbone on CUDA
plotarmordev Oct 16, 2026
05a715f
drama: one-row backbone GEMVs stream weights through a swizzled cp.as…
plotarmordev Oct 16, 2026
9dc8202
drama: add-norm fused with the routed experts' FP8 activation quantiz…
plotarmordev Oct 16, 2026
705541c
drama: one SwiGLU launch for the routed and shared experts
plotarmordev Oct 16, 2026
08291b5
drama: MoE combine on 8-wide vectors
plotarmordev Oct 16, 2026
641b18b
drama: decode attention keeps the next keys' loads in flight
plotarmordev Oct 16, 2026
01b7f3b
drama: the tower's one decode row attends as a thread-block cluster
plotarmordev Oct 16, 2026
b89dc67
drama: checkpoint weights stream onto the GPU with direct I/O in file…
plotarmordev Oct 16, 2026
0f9345e
speech: a Drama 3 reply that reaches max_frames returns its clipped a…
plotarmordev Oct 16, 2026
9b3934c
drama: one-row attention runs its Q/K norm and RoPE prologue in the s…
plotarmordev Oct 16, 2026
ea06b8b
drama: the tower samples with a stable radix sort
plotarmordev Oct 16, 2026
68aeb3e
drama: the codec builds its weights on its own thread while the backb…
plotarmordev Oct 16, 2026
2757724
drama: the tower's one-row projections on drama_tower_gemv, in cuBLAS…
plotarmordev Oct 16, 2026
bef432b
drama: the backbone chain launches with programmatic dependent launch
plotarmordev Oct 16, 2026
fdee05c
Merge upstream main (6ee828c2) into feat/drama3-cuda
plotarmordev Oct 17, 2026
0f81a2b
Merge align/920-merge-main (upstream main 6ee828c2) into feat/drama3-…
plotarmordev Oct 17, 2026
15bceca
Merge align/921-merge-main (upstream main 6ee828c2) into fix/drama3-c…
plotarmordev Oct 17, 2026
64e8ff8
Merge align/922-merge-main (upstream main 6ee828c2) into perf/drama3-…
plotarmordev Oct 17, 2026
2d9232a
Merge align/923-merge-main (upstream main 6ee828c2) into perf/drama3-…
plotarmordev Oct 17, 2026
42c548c
Merge align/924-merge-main (upstream main 6ee828c2) into perf/drama3-…
plotarmordev Oct 17, 2026
96f2b38
Merge align/925-merge-main (upstream main 6ee828c2) into perf/drama3-…
plotarmordev Oct 17, 2026
7c9fd59
Merge align/926-merge-main (upstream main 6ee828c2) into perf/drama3-pdl
plotarmordev Oct 17, 2026
b56fc8c
drama: below sm_90 the tower's decode row runs drama_attention, and i…
plotarmordev Oct 17, 2026
996637c
Merge align/924-merge-main into perf/drama3-load: the tower's sm_90 c…
plotarmordev Oct 17, 2026
bc31ec2
Merge align/926-merge-main into perf/drama3-pdl: the tower's sm_90 cl…
plotarmordev Oct 17, 2026
4d3c4f5
Merge align/925-merge-main into perf/drama3-tower-gemv: the tower's s…
plotarmordev Oct 17, 2026
2d62476
CHANGELOG: the tower's cluster decode attention runs from sm_90 on, t…
plotarmordev Oct 17, 2026
65cd256
engine_api and native/cuda.zig back under 600 lines: speech and visio…
plotarmordev Oct 17, 2026
f5aa7a5
Merge align/920-merge-main into feat/drama3-streaming: speech and vis…
plotarmordev Oct 17, 2026
fd87532
Merge align/921-merge-main into fix/drama3-clipped-replies: speech an…
plotarmordev Oct 17, 2026
572afe3
Merge align/922-merge-main into perf/drama3-backbone-one-row: speech …
plotarmordev Oct 17, 2026
1ecf53b
Merge align/923-merge-main into perf/drama3-tower-decode: speech and …
plotarmordev Oct 17, 2026
bd11ba4
Merge align/924-merge-main into perf/drama3-load: speech and vision t…
plotarmordev Oct 17, 2026
f495030
Merge align/925-merge-main into perf/drama3-tower-gemv: speech and vi…
plotarmordev Oct 17, 2026
f64f02d
Merge align/926-merge-main into perf/drama3-pdl: speech and vision ty…
plotarmordev Oct 17, 2026
118086a
core: lane tests ignore the speech audio event
plotarmordev Oct 17, 2026
4d41f5a
Merge align/921-merge-main into fix/drama3-clipped-replies: lane test…
plotarmordev Oct 17, 2026
2b27b19
Merge align/922-merge-main into perf/drama3-backbone-one-row: lane te…
plotarmordev Oct 17, 2026
e45d71b
Merge align/923-merge-main into perf/drama3-tower-decode: lane tests …
plotarmordev Oct 17, 2026
809e103
Merge align/924-merge-main into perf/drama3-load: lane tests ignore t…
plotarmordev Oct 17, 2026
0ed8946
Merge align/925-merge-main into perf/drama3-tower-gemv: lane tests ig…
plotarmordev Oct 17, 2026
d986914
Merge align/926-merge-main into perf/drama3-pdl: lane tests ignore th…
plotarmordev Oct 17, 2026
9d6a54c
drama: backbone attention runs the reference's 64-key softmax tiles
plotarmordev Oct 17, 2026
d2734fd
Merge align/927-merge-main into align/attention-tiles: lane tests ign…
plotarmordev Oct 17, 2026
391c64c
changelog: drop the attention tiles' speed sentence, no change measur…
plotarmordev Oct 17, 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
native: Drama 3 (fish_omni) on CUDA
The native CUDA backend opens fish_omni checkpoints with the Drama 3 host: one synthesis at a time on a worker
thread that owns the context, stream, backbone, tower and codec, admitted against the same memory pool the text
families use. The pool reading moves to cuda_memory.readPool so both paths share it, and the host caps its own
allocations at what it was admitted for. Options the host cannot honor are refused at open.
  • Loading branch information
plotarmordev committed Oct 16, 2026
commit ab45904fa294b3f20bfee1b274d955a1bf938678
69 changes: 39 additions & 30 deletions zig/src/native/cuda.zig
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const Allocator = std.mem.Allocator;
const budget = @import("cuda_memory.zig");
const lane_backend = @import("cuda_bound.zig");
const nemotron_slide = @import("nemotron_slide.zig");
const drama_host = @import("drama_host.zig");

/// CUDA families provide metadata, open their lane backend and explain their refusals.
const registry = .{nemotron.native};
Expand All @@ -22,8 +23,9 @@ const nemotron_snaps: api.prompt_cache.Snapshots.VTable = .{

pub const backends: []const []const u8 = &.{"cuda"};
pub const families: []const api.Family = blk: {
var out: [registry.len]api.Family = undefined;
var out: [registry.len + 1]api.Family = undefined;
for (registry, 0..) |F, i| out[i] = .{ .model_type = F.model_type, .formats = F.formats };
out[registry.len] = .{ .model_type = "fish_omni", .formats = &.{"fp8-block128"} };
const final = out;
break :blk &final;
};
Expand Down Expand Up @@ -98,28 +100,6 @@ fn weightBytes(io: std.Io, dir: []const u8) u64 {
return total;
}

/// The pool now, read on the thread whose context is current; `problem` names a bad variable.
fn pool(a: Allocator, io: std.Io, ctx: *const cuda.Context, problem: *[]const u8) !?budget.Pool {
const unified = (try ctx.attribute(.integrated)) != 0;
const card = try ctx.memInfo();
const text = if (unified) budget.procText(a, io, "/proc/meminfo") else null;
const available = budget.counts(unified, .{ .total = card.total, .available = card.free }, text) catch {
problem.* = "cannot read or parse /proc/meminfo's MemTotal and MemAvailable; refusing CUDA unified-memory admission";
return null;
};
const free = available.available;
const total = available.total;
const reserve = budget.reserveBytes(getenv("TENSORFOLD_MEMORY_RESERVE_GIB"), total, unified) catch {
problem.* = try std.fmt.allocPrint(a, "TENSORFOLD_MEMORY_RESERVE_GIB={s}: a number of GiB from {d} to the memory's size", .{ getenv("TENSORFOLD_MEMORY_RESERVE_GIB").?, budget.floor(unified).least });
return null;
};
const limit = budget.limitBytes(getenv("TENSORFOLD_CUDA_MEMORY_LIMIT_GB")) catch {
problem.* = try std.fmt.allocPrint(a, "TENSORFOLD_CUDA_MEMORY_LIMIT_GB={s}: a positive number of GiB whose byte count fits in a 64-bit size", .{getenv("TENSORFOLD_CUDA_MEMORY_LIMIT_GB").?});
return null;
};
return .{ .free = free, .total = total, .reserve = reserve, .limit = limit, .unified = unified };
}

fn readMemory(_: ?*anyopaque, reset_peak: bool) ?api.Memory {
const u = cuda.usage(reset_peak);
return .{ .active = u.device, .cache = 0, .peak = u.peak, .pinned = u.host };
Expand Down Expand Up @@ -247,13 +227,47 @@ pub fn open(a: Allocator, gpa: Allocator, io: std.Io, o: api.Open, problem: *[]c
problem.* = why;
return null;
}
if (std.mem.eql(u8, o.model_type, "fish_omni")) return openDrama(a, gpa, io, o, problem);
inline for (registry) |F| {
if (std.mem.eql(u8, o.model_type, F.model_type)) return openWith(F, a, gpa, io, o, problem);
}
problem.* = try std.fmt.allocPrint(a, "the native CUDA engine has no backend for {s} checkpoints yet", .{o.model_type});
return null;
}

fn openDrama(a: Allocator, gpa: Allocator, io: std.Io, o: api.Open, problem: *[]const u8) !?api.Opened {
if (o.tp != 1 or o.rank != 0 or (o.lanes_fixed and o.lanes != 1)) {
problem.* = "Drama 3 serves one synthesis on one CUDA device: use --parallel 1 and no tensor parallelism";
return null;
}
const window = o.context orelse 8192;
if (window < 1025 or window > 8192) {
problem.* = "Drama 3 supports --context 1025 through 8192";
return null;
}
if (o.slide or o.drafter != null or o.mtp_drafts != null or o.mtp_confidence != null or
(o.prompt_cache_gib != null and o.prompt_cache_gib.? != 0) or
(o.keep != null and o.keep.? != 0) or o.policy.len != 0)
{
problem.* = "Drama 3 does not support learned weights, speculative drafts, retained prompt caches, or text-engine policies";
return null;
}
const device = try setting(a, o.device, "TF_CUDA_DEVICE", 0, problem) orelse return null;
const segments = try setting(a, o.segments, "TF_CUDA_SEGMENTS", 1, problem) orelse return null;
if (segments != 1) {
problem.* = "Drama 3 uses one prompt segment at a time: use --segments 1";
return null;
}
if (getenv("TENSORFOLD_CUDA_KERNELS")) |path| if (path.len > 0 and !std.mem.eql(u8, path, "native")) {
problem.* = "Drama 3 uses embedded native kernels, not captured kernel sets: unset TENSORFOLD_CUDA_KERNELS or set it to native";
return null;
};
return drama_host.open(gpa, io, o.dir, "", .{ .context = @intCast(window), .device = device }) catch |e| {
problem.* = try std.fmt.allocPrint(a, "the native Drama 3 CUDA engine could not load the checkpoint ({s})", .{@errorName(e)});
return null;
};
}

fn openWith(comptime F: type, a: Allocator, gpa: Allocator, io: std.Io, o: api.Open, problem: *[]const u8) !?api.Opened {
if (refusals.family(F, o)) |why| {
problem.* = why;
Expand Down Expand Up @@ -321,7 +335,7 @@ fn openWith(comptime F: type, a: Allocator, gpa: Allocator, io: std.Io, o: api.O
return null;
},
};
const before = try pool(a, io, &g.ctx, problem) orelse return null;
const before = try budget.readPool(a, io, &g.ctx, problem) orelse return null;
const weights = weightBytes(io, o.dir);
const held0 = cuda.usage(false).device;
if (weights > before.room(held0)) {
Expand All @@ -334,7 +348,7 @@ fn openWith(comptime F: type, a: Allocator, gpa: Allocator, io: std.Io, o: api.O
};
defer if (!opened) loaded.deinit(loaded.ctx);
const model = cuda.usage(false).device - held0;
const after = try pool(a, io, &g.ctx, problem) orelse return null;
const after = try budget.readPool(a, io, &g.ctx, problem) orelse return null;
const room = after.room(model) -| loaded.learn_bytes;
const free = loaded.free_streams;
const streams = budget.admit(room, loaded.stream_bytes, free, o.lanes, o.lanes_fixed) catch |e| {
Expand Down Expand Up @@ -414,11 +428,6 @@ test "chip classes name the compute capability as gate entries do" {
try std.testing.expectEqualStrings("nvidia-sm121", name);
}

test "every registered family is listed for capabilities" {
try std.testing.expectEqual(@as(usize, registry.len), families.len);
try std.testing.expectEqualStrings("nemotron_h", families[0].model_type);
}

test "variables: unset or empty means the default, anything but a whole number is refused" {
try std.testing.expectEqual(@as(?u32, null), try envNumber(null));
try std.testing.expectEqual(@as(?u32, null), try envNumber(""));
Expand Down
24 changes: 24 additions & 0 deletions zig/src/native/cuda_memory.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! CUDA memory admission arithmetic, and the host pool read from /proc/meminfo and validated, without a device.
const std = @import("std");
const cuda = @import("cuda");
const gib: f64 = 1 << 30;

/// What /proc/meminfo says: MemTotal and MemAvailable in bytes (the page cache counts as available).
Expand Down Expand Up @@ -108,6 +109,29 @@ pub fn counts(unified: bool, card: MemInfo, text: ?[]const u8) error{HostMemoryU
return card;
}

/// Shared native-engine admission; the context must be current. Invalid environment settings fail closed.
pub fn readPool(a: std.mem.Allocator, io: std.Io, ctx: *const cuda.Context, problem: *[]const u8) !?Pool {
const unified = (try ctx.attribute(.integrated)) != 0;
const card = try ctx.memInfo();
const text = if (unified) procText(a, io, "/proc/meminfo") else null;
defer if (text) |bytes| a.free(bytes);
const available = counts(unified, .{ .total = card.total, .available = card.free }, text) catch {
problem.* = "cannot read or parse /proc/meminfo's MemTotal and MemAvailable; refusing CUDA unified-memory admission";
return null;
};
const reserve_text = if (std.c.getenv("TENSORFOLD_MEMORY_RESERVE_GIB")) |p| std.mem.span(p) else null;
const limit_text = if (std.c.getenv("TENSORFOLD_CUDA_MEMORY_LIMIT_GB")) |p| std.mem.span(p) else null;
const reserve = reserveBytes(reserve_text, available.total, unified) catch {
problem.* = try std.fmt.allocPrint(a, "TENSORFOLD_MEMORY_RESERVE_GIB={s}: a number of GiB from {d} to the memory's size", .{ reserve_text orelse "", floor(unified).least });
return null;
};
const limit = limitBytes(limit_text) catch {
problem.* = try std.fmt.allocPrint(a, "TENSORFOLD_CUDA_MEMORY_LIMIT_GB={s}: a positive number of GiB whose byte count fits in a 64-bit size", .{limit_text orelse ""});
return null;
};
return .{ .free = available.available, .total = available.total, .reserve = reserve, .limit = limit, .unified = unified };
}

test "the memory plan: reserve, cap, and admission that fails closed" {
const g: u64 = 1 << 30;
try std.testing.expectEqual(4 * g, try reserveBytes(null, 24 * g, true)); // unified: at least 4 GiB
Expand Down
Loading