Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
f9fc1a7
glm: group-limited top-k routing (Ling's 8 groups, keep 4) and a per-…
jschmied Oct 15, 2026
a655957
ling: Ling-3.1-flash's config loader and weight map, its routing and …
jschmied Oct 15, 2026
d46e372
ling: weights in the checkpoint's own format (bf16, FP8 blocks, Model…
jschmied Oct 15, 2026
faf7af1
docs: Ling-3.1-flash recipe: what exists, what is missing, testing wi…
jschmied Oct 15, 2026
7d184cb
glm: MLA kernels take Ling-3.1's shape: 64 roped key columns, 128-wid…
jschmied Oct 15, 2026
ef8f12f
glm: KDA serves Ling-3.1 as is (real layer 0 vs fla and float64); an …
jschmied Oct 15, 2026
6f583ba
ling: the TP=1 layer graph in any loaded format: KDA and MLA mixers, …
jschmied Oct 15, 2026
bfb44dd
ling: SwiGLU clamp in Ling's order, min(silu(g), L) * clip(u, -L, L)
jschmied Oct 15, 2026
2a5e1b6
tests: zig fmt ling_mla_real.zig
jschmied Oct 15, 2026
a3f14d3
ling: served through the lane core at TP=1: engine, lane backend, ser…
jschmied Oct 15, 2026
577436b
ling: the MTP layer (model.layers.72) drafts: enorm | hnorm through e…
jschmied Oct 15, 2026
7bd7a40
tests: ling-pack times one MoE layer's expert load (read, pack, cold)…
jschmied Oct 15, 2026
bbe360f
ling: routed experts staged in batches through pinned memory and pack…
jschmied Oct 15, 2026
412f66f
tests: ling-layer-speed times one real layer whole and op by op per p…
jschmied Oct 15, 2026
99652ba
ling: row copies 16 bytes a thread on aligned rows (prompt KDA and ML…
jschmied Oct 15, 2026
b3faea6
ling: a single decode row's projections write their columns in place,…
jschmied Oct 15, 2026
5b00637
ling: FP8 prompt chunks under 16 routed pairs an expert run the decod…
jschmied Oct 15, 2026
e78d23b
glm: group-limited select without divisions where groups are whole la…
jschmied Oct 15, 2026
0ffce4f
tests: ling-layer-speed takes a rows list, times prompt ops from an i…
jschmied Oct 15, 2026
bd7c23e
tests: ling-layer-speed starts each rep after a random spin (tf_probe…
jschmied Oct 15, 2026
32055e9
glm: swiglu keeps GLM's limit as given; only Ling's swigluWith maps 0…
jschmied Oct 15, 2026
991383f
glm: swigluWith's doc comment within 120 columns
jschmied Oct 15, 2026
03171bf
glm: drop the opt-in 16-row chunked KDA prompt path; GLM's cuda_kda.z…
jschmied Oct 15, 2026
66579cb
ling: config refuses every geometry the kernels don't take, at load, …
jschmied Oct 16, 2026
92afed6
ling: routing groups of one and a single pick refused at load; one gr…
jschmied Oct 16, 2026
674163f
ling: Store.alloc owns a buffer only once it is in both lists; a fake…
jschmied Oct 16, 2026
0ba510a
ling: a new stream's slot is chosen before its map entry exists (lane…
jschmied Oct 16, 2026
82b3817
ling: rows past a sequence's capacity are refused before any layer ru…
jschmied Oct 16, 2026
0ba2adf
ling: Engine.init frees its sequences when binding slot 0 or the last…
jschmied Oct 16, 2026
5649c63
ling: every tensor of the full checkpoint checked against the loader'…
jschmied Oct 16, 2026
e4c9bcc
oracle: the Ling oracles check their HF source against inclusionAI/Li…
jschmied Oct 16, 2026
5e931c3
ling: a segment the scratch cannot hold is refused before any layer r…
jschmied Oct 16, 2026
1395e26
ling: staging and loaded weights freed only after the stream drains; …
jschmied Oct 16, 2026
e99e650
docs/recipes/ling-3.1: file names for hashes the rebase changed, curr…
jschmied 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
tests: ling-layer-speed times one real layer whole and op by op per p…
…hase; ling-layer-bytes writes every path's bytes for cmp
  • Loading branch information
jschmied committed Oct 16, 2026
commit 412f66fc69c192f2d04e7355ada3c8dd72d23def
119 changes: 119 additions & 0 deletions zig/tests/cuda/ling_layer_bytes.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
//! `ling-layer-bytes DIR FIXTURE OUT`: one real Ling-3.1 layer's outputs and states on every path, written for cmp.
const std = @import("std");
const cuda = @import("cuda");
const check = @import("check.zig");
const ling = @import("ling_cuda");
const rig = @import("ling_forward_rig.zig");

const F = rig.F;
const Rig = rig.Rig;
const Opened = @typeInfo(@typeInfo(@TypeOf(rig.W.open)).@"fn".return_type.?).error_union.payload;

/// The loaded layer, its graph, a prompt and a decode Buffers, the fixture's rows tiled to `rows`.
pub const Kit = struct {
o: Opened,
m: F.Modules,
w: rig.W.Weights,
g: F.Graph,
r: Rig,
pb: F.Buffers,
db: F.Buffers,
x: []u16,
D: usize,
L: u32,
cap: usize,

/// Loads FIXTURE's layer from DIR; prompt buffers for `rows` rows, states of `cap` positions.
pub fn init(k: *Kit, gpu: check.Gpu, a: std.mem.Allocator, s: cuda.Stream, dir: []const u8, path: []const u8, rows: usize, cap: usize) !void {
const bytes = try std.Io.Dir.cwd().readFileAlloc(gpu.io, path, a, .limited(1 << 30));
if (bytes.len < 24 or !std.mem.eql(u8, bytes[0..8], "TFLINGL1")) return error.BadFixture;
const dims = std.mem.bytesAsSlice(u32, bytes[8..24]);
k.L = dims[0];
const T: usize = dims[1];
k.D = dims[2];
k.x = try a.alloc(u16, rows * k.D);
for (0..rows) |t| @memcpy(std.mem.sliceAsBytes(k.x[t * k.D ..][0..k.D]), bytes[24 + (t % T) * k.D * 2 ..][0 .. k.D * 2]);
var why: ling.config.Why = .{};
k.o = rig.W.open(gpu.gpa, gpu.io, dir, &why) catch |e| {
std.debug.print("{s}: {s}\n", .{ dir, why.text() });
return e;
};
k.m = try F.Modules.load(gpu.d, gpu.ctx);
var pack = try cuda.modelopt.Packer.load(gpu.d);
defer pack.unload();
k.w = try rig.W.load(gpu.gpa, gpu.d, s, &pack, &k.o.ck, k.o.c, &.{k.L}, .{ .globals = false });
k.g = try F.Graph.init(gpu.gpa, gpu.d, &k.m, s, &k.w);
k.r = .{ .gpu = gpu, .a = a, .s = s, .m = &k.m, .g = &k.g };
k.cap = cap;
k.pb = try F.Buffers.init(gpu.d, &k.m, &k.w, rows, true, cap);
k.db = try F.Buffers.init(gpu.d, &k.m, &k.w, F.window_rows, false, cap);
}

pub fn deinit(k: *Kit) void {
k.pb.deinit();
k.db.deinit();
k.r.deinit();
k.g.deinit();
k.w.deinit();
k.m.deinit();
k.o.ck.close();
}

/// Rows lo .. hi through the layer on `st`, committing `keep` of them (0: all); the output rows' bytes.
pub fn pass(k: *Kit, b: *const F.Buffers, st: *F.State, lo: usize, hi: usize, keep: usize) ![]u8 {
const d = k.r.gpu.d;
const n = hi - lo;
try d.check(d.api.cuMemcpyHtoDAsync_v2(b.x, k.x[lo * k.D ..].ptr, n * k.D * 2, k.r.s.handle), "cuMemcpyHtoDAsync");
const f = k.r.fwd(b, null);
try f.stack(&.{.{ .st = st, .row0 = 0, .rows = n }});
const out = try k.r.back(b.x, n * k.D * 2);
try f.commit(st, if (keep == 0) n else keep);
return out;
}
};

fn put(list: *std.ArrayList(u8), a: std.mem.Allocator, bytes: []const u8) !void {
try list.appendSlice(a, bytes);
}

/// Every path's bytes: prompts of 512 and 2048 rows, 16 decode rows, windows of 2..16 with partial commits, states.
pub fn run(gpu: check.Gpu, dir: []const u8, path: []const u8, out: []const u8) !void {
var arena = std.heap.ArenaAllocator.init(gpu.gpa);
defer arena.deinit();
const a = arena.allocator();
var s = try cuda.Stream.init(gpu.d, false);
defer s.deinit();
var k: Kit = undefined;
try k.init(gpu, a, s, dir, path, 2048, 2600);
defer k.deinit();
var all: std.ArrayList(u8) = .empty;
const P = 400;
for ([_]usize{ 512, 2048 }) |T| {
const st = try k.r.state(k.cap);
defer st.deinit();
try put(&all, a, try k.pass(&k.pb, st, 0, T, 0));
try put(&all, a, try k.r.back(st.arena.buf.ptr, st.arena.buf.len));
}
for ([_]bool{ true, false }) |wide| {
k.r.kda_wide = wide;
const st = try k.r.state(k.cap);
defer st.deinit();
_ = try k.pass(&k.pb, st, 0, P, 0);
for (0..F.window_rows) |i| try put(&all, a, try k.pass(&k.db, st, P + i, P + i + 1, 0));
try put(&all, a, try k.r.back(st.arena.buf.ptr, st.arena.buf.len));
for ([_]usize{ 2, 3, 4, 8, 16 }) |w| {
const sw = try k.r.state(k.cap);
defer sw.deinit();
_ = try k.pass(&k.pb, sw, 0, P, 0);
const keep = (w + 1) / 2;
try put(&all, a, try k.pass(&k.db, sw, P, P + w, keep));
try put(&all, a, try k.pass(&k.db, sw, P + keep, P + keep + w, 0));
try put(&all, a, try k.r.back(sw.arena.buf.ptr, sw.arena.buf.len));
}
}
k.r.kda_wide = true;
var h = std.hash.Wyhash.init(0);
h.update(all.items);
try std.Io.Dir.cwd().writeFile(gpu.io, .{ .sub_path = out, .data = all.items });
check.pass("ling-layer-bytes layer {d}: {d} bytes into {s}, wyhash {x:0>16}", .{ k.L, all.items.len, out, h.final() });
}
275 changes: 275 additions & 0 deletions zig/tests/cuda/ling_layer_speed.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,275 @@
//! `ling-layer-speed DIR FIXTURE [REPS]`: one real Ling-3.1 layer timed by CUDA events, whole and op by op, per phase.
const std = @import("std");
const cuda = @import("cuda");
const check = @import("check.zig");
const ling = @import("ling_cuda");
const rig = @import("ling_forward_rig.zig");
const bytes = @import("ling_layer_bytes.zig");

const F = rig.F;
const G = ling.graph;
const W = rig.W;
const kda = G.kda;
const latent = G.latent;
const glue = G.glue;

/// Events between op groups; each group's milliseconds by name, medians over reps.
const Timer = struct {
ev: [48]cuda.Event,
names: [48][]const u8 = undefined,
n: usize = 0,
s: cuda.Stream,
on: bool,

fn mark(t: *Timer, name: []const u8) !void {
if (!t.on) return;
try t.ev[t.n].record(t.s);
t.names[t.n] = name;
t.n += 1;
}
};

const Seg = F.Seg;

fn kdaBlock(o: G.Ops, b: *const F.Buffers, a: W.Kda, c: *const ling.config.Config, li: usize, sg: Seg, rows: usize, t: *Timer) !void {
const D: usize = c.hidden;
const H: usize = c.kda_heads;
const n = H * kda.dk;
const st = sg.st;
const ps = st.stride;
const sv = st.saves(li);
const p = if (b.prompt) b.kp else sv.p;
for ([_]W.Proj{ a.q, a.k, a.v, a.b }, [_]usize{ 0, n, 2 * n, 3 * n }, [_][]const u8{ "proj q", "proj k", "proj v", "proj b (bf16)" }) |w, col0, name| {
try o.mm(w, b.normed, D, rows, b.tmp);
try t.mark(name);
const w_n = w.outputs();
try o.copy(b.tmp, w_n * 2, p + col0 * 2, ps * 2, rows, w_n * 2);
try t.mark("copies into p");
}
try o.mm(a.f, b.normed, D, rows, b.ka);
try t.mark("proj f");
try o.mm(a.g, b.normed, D, rows, b.kg);
try t.mark("proj g");
const cur = st.cur[li];
const ch: kda.Chain = .{ .p = p, .p_stride = ps, .b_off = 3 * n, .a = b.ka, .a_stride = n, .g = b.kg, .g_stride = n, .conv_state = st.convAt(li), .conv_w = a.conv, .state_in = st.recAt(cur, li), .a_log = a.a_log, .dt_bias = a.dt_bias, .norm_w = a.o_norm, .eps = c.eps, .lower = c.lower_bound, .heads = H };
const k = if (b.prompt) b.saves.k else sv.k;
const v = if (b.prompt) b.saves.v else sv.v;
const g = if (b.prompt) b.saves.g else sv.g;
const bb = if (b.prompt) b.saves.b else sv.b;
const s: kda.Saves = .{ .out = b.saves.out, .state_out = st.recAt(1 - cur, li), .k = k, .v = v, .g = g, .b = bb };
const wide: ?kda.Wide = if (if (b.prompt) rows >= kda.wide_rows else o.kda_wide) .{ .q = b.wide.q, .y = b.wide.y } else null;
try kda.chain(&o.m.kda, o.s, ch, rows, s, wide);
try t.mark("KDA chain");
if (b.prompt) {
try glue.convShift(o.set(), o.s, st.convAt(li), p, rows, rows * ps, ps, 1, 3 * n);
try t.mark("conv shift");
}
try o.mm(a.o, b.saves.out, n, rows, b.y);
try t.mark("proj o");
}

fn mlaBlock(o: G.Ops, b: *const F.Buffers, a: W.Mla, ab: G.Absorb, g: *const F.Graph, sg: Seg, rows: usize, t: *Timer) !void {
const c = &g.w.config;
const D: usize = c.hidden;
const H: usize = c.mla_heads;
const qk: usize = c.qkDim();
const nope: usize = c.nope;
const kw = F.cache_width;
const lw = 512;
const ql: usize = c.q_lora;
try o.mm(a.q_a.?, b.normed, D, rows, b.qa_in);
try t.mark("proj q_a");
try glue.rmsnorm(o.set(), o.s, b.qa_in, ql, a.q_a_norm, b.qr, ql, null, c.eps, rows, ql);
try t.mark("norms q_a, kv");
try o.mm(a.q_b.?, b.qr, ql, rows, b.q);
try t.mark("proj q_b");
try o.mm(a.kv_a, b.normed, D, rows, b.kv);
try t.mark("proj kv_a");
try glue.rmsnorm(o.set(), o.s, b.kv, kw, a.kv_a_norm, b.lat, kw, null, c.eps, rows, lw);
try t.mark("norms q_a, kv");
try o.mm(a.gate.?, b.normed, D, rows, b.g);
try t.mark("proj gate (bf16)");
try latent.absorbQStrided(o.set(), o.s, b.q, qk, ab.wk, b.qa, kw, rows, H, nope, lw);
try t.mark("absorb q");
const st = sg.st;
try latent.rope(o.set(), o.s, .{ .x = b.q + nope * 2, .x_row = H * qk, .x_head = qk, .out = b.qa + lw * 2, .o_row = H * kw, .o_head = kw }, rows, H, st.pos_dev, g.freq);
try latent.rope(o.set(), o.s, .{ .x = b.kv + lw * 2, .x_row = kw, .x_head = 0, .out = b.lat + lw * 2, .o_row = kw, .o_head = 0 }, rows, 1, st.pos_dev, g.freq);
try latent.latentWrite(o.set(), o.s, b.lat, kw, st.cacheAt(0), st.pos_dev, rows, kw);
try t.mark("rope, cache write");
var r0: usize = 0;
while (r0 < rows) : (r0 += ling.state.att_rows) {
const m = @min(ling.state.att_rows, rows - r0);
var at = st.pos_dev;
if (r0 > 0) {
try o.addI32(st.pos_dev, r0, b.at);
at = b.at;
}
const nch = latent.chunksFor(st.pos + r0 + m);
try latent.attentionRoped(o.set(), o.s, b.qa + r0 * H * kw * 2, st.cacheAt(0), at, b.partials, b.ol + r0 * H * lw * 2, b.dummy, m, H, lw, nch, c.smScale());
}
try t.mark("latent attention");
try latent.expandV(o.set(), o.s, b.ol, ab.wv, b.vn, rows, H, c.v_dim, lw);
try t.mark("expand v");
try o.gate(b.vn, b.g, H, rows, H, c.v_dim);
try t.mark("head gate");
try o.mm(a.o, b.vn, H * c.v_dim, rows, b.y);
try t.mark("proj o");
}

fn mlp(o: G.Ops, b: *const F.Buffers, m: W.Mlp, rows: usize, limit: f32, out: u64, t: *Timer, comptime tag: []const u8) !void {
const D = m.gate.inputs();
const w = m.gate.outputs();
for ([_]W.Proj{ m.gate, m.up }, [_]usize{ 0, w }) |p, col0| {
try o.mm(p, b.normed, D, rows, b.tmp);
try t.mark(tag ++ " gate, up");
try o.copy(b.tmp, w * 2, b.gu + col0 * 2, 4 * w, rows, w * 2);
try t.mark(tag ++ " copies");
}
try glue.swigluWith(o.m.swiglu, o.s, b.gu, b.act, b.xs, limit, rows, w);
try t.mark(tag ++ " swiglu");
try o.mm(m.down, b.act, w, rows, out);
try t.mark(tag ++ " down");
}

fn moe(o: G.Ops, b: *const F.Buffers, e: W.Moe, g: *const F.Graph, rows: usize, t: *Timer) !void {
const c = &g.w.config;
const D: usize = c.hidden;
const E: usize = c.experts;
const top: usize = c.topk;
const slots = top + 1;
try glue.router(o.set(), o.s, b.normed, D, e.router, b.mlog, b.rpart, rows, D, E);
try t.mark("router");
try glue.select(o.set(), o.s, b.mlog, if (e.bias != 0) e.bias else g.zero_bias, b.pick, b.wts, rows, top, E, c.routed_scale, c.norm_topk, ling.groups(c));
try t.mark("select");
const l = e.routed.grouped;
const tile: usize = if (o.prompt) cuda.experts.promptTile(l.format) else 16;
try o.m.router.route(o.s, b.pick, rows * slots, E + 1, tile, b.plan);
try t.mark("expert plan");
const items = cuda.grouped.maxItems(rows * slots, E + 1, tile);
const gr = o.m.grouped();
const up: cuda.experts.Rows = .{ .x = b.normed, .stride = l.dims, .slots = slots };
const down: cuda.experts.Rows = .{ .x = b.eact, .stride = l.width };
const skip: i32 = @intCast(E);
if (o.prompt) try gr.prompt(o.s, .up, up, l, b.plan, b.eact, items, skip) else try gr.decode(o.s, .up, up, l, b.plan, b.eact, items, skip);
try t.mark("experts gate-up");
if (o.prompt) try gr.prompt(o.s, .down_bf16, down, l, b.plan, b.ey, items, skip) else try gr.decode(o.s, .down_bf16, down, l, b.plan, b.ey, items, skip);
try t.mark("experts down");
if (o.prompt) { // the decode kernels on 16-pair items over the same rows, for comparison
try o.m.router.route(o.s, b.pick, rows * slots, E + 1, 16, b.plan);
try t.mark("alt plan 16");
const it16 = cuda.grouped.maxItems(rows * slots, E + 1, 16);
try gr.decode(o.s, .up, up, l, b.plan, b.eact, it16, skip);
try t.mark("alt gate-up decode kernel");
try gr.decode(o.s, .down_bf16, down, l, b.plan, b.ey, it16, skip);
try t.mark("alt down decode kernel");
}
try mlp(o, b, e.shared.?, rows, e.shared_limit, b.sh, t, "shared");
var a: cuda.Args = .{};
inline for (.{ b.ey, b.pick, b.wts, b.sh, b.y, @as(i64, @intCast(rows)), @as(i64, @intCast(D)), @as(c_int, @intCast(slots)), @as(c_int, @intCast(top)), @as(c_int, 0) }) |v| a.add(v);
try cuda.launch.launch(o.m.combine, .{ .grid = .{ .x = @intCast(rows), .y = @intCast((D + 255) / 256) }, .block = .{ .x = 256 } }, o.s, &a);
try t.mark("combine");
}

/// The layer as forward.layer runs it, op groups marked.
fn layerOps(f: *const F.Forward, sg: Seg, rows: usize, t: *Timer) !void {
const o = f.ops();
const b = f.b;
const g = f.g;
const c = &g.w.config;
const D: usize = c.hidden;
const l = g.w.layers[0];
try t.mark("start");
try glue.rmsnorm(o.set(), o.s, b.x, D, l.attn_norm, b.normed, D, null, c.eps, rows, D);
try t.mark("norms + residual adds");
switch (l.mixer) {
.kda => |a| try kdaBlock(o, b, a, c, 0, sg, rows, t),
.mla => |a| try mlaBlock(o, b, a, g.absorb[0], g, sg, rows, t),
}
try o.add(b.x, b.y, b.x, rows * D);
try glue.rmsnorm(o.set(), o.s, b.x, D, l.mlp_norm, b.normed, D, null, c.eps, rows, D);
try t.mark("norms + residual adds");
switch (l.ffn) {
.dense => |m| try mlp(o, b, m, rows, 0, b.y, t, "dense"),
.moe => |e| try moe(o, b, e, g, rows, t),
}
try o.add(b.x, b.y, b.x, rows * D);
try t.mark("norms + residual adds");
}

const Row = struct { name: []const u8, ms: [32]f64 = undefined, n: usize = 0 };

fn median(xs: []f64) f64 {
std.mem.sort(f64, xs, {}, std.sort.asc(f64));
return xs[xs.len / 2];
}

/// `ling-layer-speed DIR FIXTURE [REPS]`: decode at position 2048, windows 2..16, prompts of 512 and 2048 rows.
pub fn run(gpu: check.Gpu, dir: []const u8, path: []const u8, reps_arg: ?[]const u8) !void {
const reps: usize = if (reps_arg) |x| try std.fmt.parseInt(usize, x, 10) else 15;
var arena = std.heap.ArenaAllocator.init(gpu.gpa);
defer arena.deinit();
const a = arena.allocator();
var s = try cuda.Stream.init(gpu.d, false);
defer s.deinit();
var k: bytes.Kit = undefined;
try k.init(gpu, a, s, dir, path, 2048, 4200);
defer k.deinit();
var t: Timer = .{ .ev = undefined, .s = s, .on = true };
for (&t.ev) |*e| e.* = try cuda.Event.init(gpu.d, true);
defer for (&t.ev) |*e| e.deinit();
const st = try k.r.state(k.cap);
defer st.deinit();
const c = &k.w.config;
std.debug.print("RESULT ling-layer-speed layer {d} ({t}, {s}, {t}), {d} reps, median and least us (other GPU contexts' time slices land in the medians)\n", .{ k.L, c.kind(k.L), if (c.isMoe(k.L)) "MoE" else "dense", c.quant, reps });
for ([_]usize{ 1, 2, 4, 8, 16, 512, 2048 }) |rows| {
const b = if (rows > F.window_rows) &k.pb else &k.db;
const pos: usize = if (rows > F.window_rows) 0 else 2048;
try st.setPos(s, pos);
const d = gpu.d;
try d.check(d.api.cuMemcpyHtoDAsync_v2(b.x, k.x.ptr, rows * k.D * 2, s.handle), "cuMemcpyHtoDAsync");
const f = k.r.fwd(b, null);
const sg: Seg = .{ .st = st, .row0 = 0, .rows = rows };
var whole: [64]f64 = undefined;
var table: [32]Row = undefined;
var nt: usize = 0;
for (0..reps + 2) |i| {
// whole layer through forward.layer, then the same launches op by op
try t.ev[46].record(s);
try f.layer(&.{sg}, 0, rows, null);
try t.ev[47].record(s);
try s.synchronize();
if (i >= 2) whole[i - 2] = try t.ev[46].elapsedMs(t.ev[47]);
t.n = 0;
try layerOps(&f, sg, rows, &t);
try s.synchronize();
if (i < 2) continue;
var acc: [32]f64 = @splat(0);
for (1..t.n) |j| {
const name = t.names[j];
var at: usize = 0;
while (at < nt and !std.mem.eql(u8, table[at].name, name)) at += 1;
if (at == nt) {
table[nt] = .{ .name = name };
nt += 1;
}
acc[at] += try t.ev[j - 1].elapsedMs(t.ev[j]);
}
for (table[0..nt], acc[0..nt]) |*r, v| {
r.ms[r.n] = v;
r.n += 1;
}
}
var sum: f64 = 0;
var low: f64 = 0;
std.debug.print("RESULT rows {d:>4}: layer {d:.1} {d:.1}", .{ rows, median(whole[0..reps]) * 1000, std.mem.min(f64, whole[0..reps]) * 1000 });
for (table[0..nt]) |*r| {
const lo = std.mem.min(f64, r.ms[0..r.n]) * 1000;
const m = median(r.ms[0..r.n]) * 1000;
sum += m;
low += lo;
std.debug.print(" | {s} {d:.1} {d:.1}", .{ r.name, m, lo });
}
std.debug.print(" | sum of ops {d:.1} {d:.1}\n", .{ sum, low });
}
check.pass("ling-layer-speed layer {d}: timed", .{k.L});
}
Loading