Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
48 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
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
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
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
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
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
core: a direct read the file system refuses goes through the page cache
Some file systems accept an O_DIRECT open and then fail the aligned read with EINVAL. The reader now clears
O_DIRECT on that descriptor and reads again through the page cache instead of failing the load; a test injects
the refusal.
  • Loading branch information
plotarmordev committed Oct 16, 2026
commit 40c7c871f09b3412f0165494ca2f4df8a8452ecb
59 changes: 56 additions & 3 deletions zig/src/core/direct_io.zig
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,23 @@ fn readAt(f: File, buf: Buffer, offset: u64, len: usize, ctx: *anyopaque, pread:
const want: usize = @intCast(offset + len - lo);
const whole = span(offset, len);
if (whole > buf.len) return error.BufferTooSmall;
var aligned = f.direct;
var got: usize = 0;
while (got < want) {
// A short O_DIRECT read is retried from the last 4 KiB boundary so the next pread stays aligned.
const at: usize = if (f.direct) std.mem.alignBackward(usize, got, alignment) else got;
const at: usize = if (aligned) std.mem.alignBackward(usize, got, alignment) else got;
const ask = whole - at;
const n = pread(ctx, f.fd, buf.ptr + at, ask, lo + @as(u64, @intCast(at)));
if (n < 0) {
if (std.c.errno(n) == .INTR) continue;
std.log.err("read of {d} bytes at {d} failed: {t}", .{ ask, lo + at, std.c.errno(n) });
const e = std.c.errno(n);
if (e == .INTR) continue;
// a file system that took the O_DIRECT open can still refuse its reads: the file goes through the cache
if (e == .INVAL and aligned) {
try buffered(f.fd);
aligned = false;
continue;
}
std.log.err("read of {d} bytes at {d} failed: {t}", .{ ask, lo + at, e });
return error.ReadFailed;
}
if (n == 0) return error.EndOfFile;
Expand All @@ -75,6 +83,13 @@ fn readAt(f: File, buf: Buffer, offset: u64, len: usize, ctx: *anyopaque, pread:
return buf[@intCast(offset - lo)..][0..len];
}

/// Clears O_DIRECT on `fd`, so this read and every later one through it use the page cache.
fn buffered(fd: std.c.fd_t) !void {
const direct_flag: c_int = @bitCast(@as(u32, @bitCast(std.c.O{ .DIRECT = true })));
const flags = std.c.fcntl(fd, std.c.F.GETFL);
if (flags < 0 or std.c.fcntl(fd, std.c.F.SETFL, flags & ~direct_flag) < 0) return error.ReadFailed;
}

test "span and fits" {
try std.testing.expectEqual(@as(usize, 4096), span(0, 1));
try std.testing.expectEqual(@as(usize, 8192), span(4095, 2));
Expand Down Expand Up @@ -104,6 +119,44 @@ test "direct reads return the same bytes as buffered reads" {
try std.testing.expectError(error.BufferTooSmall, f.read(buf, 1, 1 << 20));
}

/// Refuses its first read with EINVAL, as a file system that accepts an O_DIRECT open but not the read does.
const Refuse = struct {
refused: bool = false,

fn pread(ctx: *anyopaque, fd: std.c.fd_t, buf: [*]u8, len: usize, offset: u64) isize {
const r: *Refuse = @ptrCast(@alignCast(ctx));
if (!r.refused) {
r.refused = true;
std.c._errno().* = @backingInt(std.c.E.INVAL);
return -1;
}
return std.c.pread(fd, buf, len, @intCast(offset));
}
};

test "a direct read the file system refuses is read again through the page cache" {
if (builtin.os.tag != .linux) return error.SkipZigTest;
const gpa = std.testing.allocator;
var f = try File.open("/proc/self/exe");
defer f.close();
if (!f.direct) return error.SkipZigTest;
var plain: File = .{ .fd = std.c.open("/proc/self/exe", .{ .ACCMODE = .RDONLY, .CLOEXEC = true }), .direct = false };
try std.testing.expect(plain.fd >= 0);
defer plain.close();
const buf = try gpa.alignedAlloc(u8, .fromByteUnits(alignment), 1 << 20);
defer gpa.free(buf);
const want = try gpa.alloc(u8, 100000);
defer gpa.free(want);
try std.testing.expectEqual(@as(isize, @intCast(want.len)), std.c.pread(plain.fd, want.ptr, want.len, 12345));
var refuse: Refuse = .{};
try std.testing.expectEqualSlices(u8, want, try readAt(f, buf, 12345, want.len, &refuse, Refuse.pread));
try std.testing.expect(refuse.refused);
const direct_flag: c_int = @bitCast(@as(u32, @bitCast(std.c.O{ .DIRECT = true })));
try std.testing.expectEqual(@as(c_int, 0), std.c.fcntl(f.fd, std.c.F.GETFL) & direct_flag);
// later reads through the descriptor, now buffered, still return the file's bytes
try std.testing.expectEqualSlices(u8, want[1..][0..4095], try f.read(buf, 12346, 4095));
}

const Script = struct {
plan: []const usize,
offs: [8]u64 = undefined,
Expand Down