Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Each release's page on GitHub has its notes and measurements. See [the 1.0.0 rel

## Unreleased

- Kernel contract: the GLM Metal contract runs to the end on M1 to M4 Macs again (its KDA and index texts carry the pre-M5 define the loader adds), and gate 5 resolves GLM's routed-expert row launches on every Mac instead of stopping with `UnknownLaunch` (#4397).

- Lanes: #3728's lone-stream copy pricing is taken out again: on an M3 Ultra it made Qwen3.8-27B with the DFlash2 drafter verify drafted rows that did not land, so drafted decode on long prompts is back to 1.2.10's speed, with the same tokens (#4078).

- Docs: the first world-4 Flash Next receipt on HIP, oQ2-MTP at `--tp 4` on four Radeon AI PRO R9700s, with a same-binary world-2 control run that separates the world effect from engine changes (#4210, refs #2401). Thanks to @timmyit.
Expand Down
2 changes: 1 addition & 1 deletion zig/src/core/contract/glm_launch_records.zig
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub const records = [_]M{
.{ .name = "glm launch prompt experts glm_gather_scatter_64", .threads = 128, .tg_memory = 9728, .offline = false },
.{ .name = "glm launch prompt dense glm_mm_grouped", .threads = 128, .tg_memory = 9728, .offline = false },
// a prompt chunk's index scores in 128-row tiles (nax.h: no M1/M2 build ahead of time)
.{ .name = "glm launch index glm_index_scores_nax", .threads = 256, .tg_memory = 17408, .offline = false },
.{ .name = "glm launch index glm_index_scores_nax", .threads = 256, .tg_memory = 18432, .offline = false },
};

test "the GLM launches fit every Apple family" {
Expand Down
28 changes: 21 additions & 7 deletions zig/tests/contract/metal_glm_index.zig
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,31 @@ fn stride(s: c.Shape) usize {

pub const Case = struct {
control: bool,
m3: bool, // no tensor units: the loader's pre-M5 build and launch
new: mtl.Pipeline,
old: mtl.Pipeline,

/// The loader's library as it compiles it (nax.h inlined for this GPU), and main's the same way.
/// The loader's library as it compiles it (pre-M5 define, nax.h inlined for this GPU), and main's the same way.
pub fn text(a: std.mem.Allocator, device: mtl.Device) ![]u8 {
return tf.frags.source(device, a, sources.glm_index_nax);
const raw = try std.mem.concat(a, u8, &.{ m3Def(!device.tensorUnits()), sources.glm_index_nax });
defer a.free(raw);
return tf.frags.source(device, a, raw);
}

pub fn init(s: *bits.Suite, control: bool) !Case {
const loader = try s.production();
const own = try text(s.a, s.device);
defer s.a.free(own);
_ = try loader.require(own);
const body = if (control) try bits.edited(s.a, own, "void glm_index_scores_nax(", "const int tm = 16 * int(sg);", "const int tm = 16 * int(sg / 2);") else try s.a.dupe(u8, own);
const m3 = !s.device.tensorUnits();
const plant: [2][]const u8 = if (m3) .{ "tn = 32 * int(sg % 2);", "tn = 0;" } else .{ "const int tm = 16 * int(sg);", "const int tm = 16 * int(sg / 2);" };
const body = if (control) try bits.edited(s.a, own, "void glm_index_scores_nax(", plant[0], plant[1]) else try s.a.dupe(u8, own);
defer s.a.free(body);
const main_text = try tf.frags.source(s.device, s.a, main_index);
defer s.a.free(main_text);
const new = try bits.pipeline(s.device, body, "glm_index_scores_nax");
errdefer new.deinit();
return .{ .control = control, .new = new, .old = try bits.pipeline(s.device, main_text, "glm_index_scores_nax") };
return .{ .control = control, .m3 = m3, .new = new, .old = try bits.pipeline(s.device, main_text, "glm_index_scores_nax") };
}
pub fn deinit(x: *Case) void {
x.new.deinit();
Expand Down Expand Up @@ -93,8 +98,10 @@ pub const Case = struct {
e.setBuffer(r[2].buf, r[2].off, 2);
e.setBuffer(r[3].buf, r[3].off, 3);
e.setValue(ScoreArgs{ .p0 = @intCast(s.k), .q_stride = QR, .w_stride = HI, .s_stride = @intCast(stride(s)), .rows = @intCast(s.rows) }, 4);
const tile: usize = if (new) tf.glm.prompt.scoreRows(@intCast(most), @intCast(s.rows)) else 64; // selectKeys', main's
e.dispatchGroups(mtl.Size.of((most + 63) / 64, (s.rows + tile - 1) / tile, 1), mtl.Size.of(2 * tile, 1, 1));
// selectKeys' launch (glm/prompt.zig): 32 rows and 128 threads before M5, else scoreRows' tile; main's 64 rows
const tile: usize = if (!new) 64 else if (x.m3) 32 else tf.glm.prompt.scoreRows(@intCast(most), @intCast(s.rows));
const threads: usize = if (new and x.m3) 128 else 2 * tile;
e.dispatchGroups(mtl.Size.of((most + 63) / 64, (s.rows + tile - 1) / tile, 1), mtl.Size.of(threads, 1, 1));
}
};

Expand All @@ -107,5 +114,12 @@ pub fn collect(s: *bits.Suite, only: ?[]const u8) !void {
/// Gate 5's registration `glm launch index <function>`: the loader's index library here, and as a pre-M5 GPU builds it.
pub const prefix = "glm launch index ";
pub fn limitsText(a: std.mem.Allocator, device: mtl.Device, _: []const u8) !bits.Texts {
return .{ .here = try Case.text(a, device), .pre_m5 = try tf.frags.precision.source(a, false, sources.glm_index_nax, sources.nax, false) };
const raw = try std.mem.concat(a, u8, &.{ m3Def(true), sources.glm_index_nax });
defer a.free(raw);
return .{ .here = try Case.text(a, device), .pre_m5 = try tf.frags.precision.source(a, false, raw, sources.nax, false) };
}

/// kernels.zig's pre-M5 dispatch define, put before glm_index_nax.metal on a GPU without tensor units.
fn m3Def(m3_fast: bool) []const u8 {
return if (m3_fast) "#define TF_GLM_M3_FAST 1\n" else "";
}
14 changes: 7 additions & 7 deletions zig/tests/contract/metal_glm_kda.zig
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ const eps: f32 = 1e-5;
/// The window step (all heads, one Mac's 32 heads at TP2), and an Ultra's two groups a head with the norm after.
pub const Form = enum { window, window_tp, parts };

/// kernels.zig's KDA library: kda_rows' source, then the prompt passes, the window step and the parts appended.
pub fn text(a: std.mem.Allocator) ![]u8 {
return std.mem.concat(a, u8, &.{ comptime kernels.generatedSource("kda_rows"), sources.glm_kda_prompt, sources.glm_kda_window, sources.glm_kda_parts });
/// kernels.zig's KDA library: kda_rows, the pre-M5 define (`m3_fast`), the prompt passes, window step and parts.
pub fn text(a: std.mem.Allocator, m3_fast: bool) ![]u8 {
const m3_def = if (m3_fast) "#define TF_GLM_M3_FAST 1\n" else "";
return std.mem.concat(a, u8, &.{ comptime kernels.generatedSource("kda_rows"), m3_def, sources.glm_kda_prompt, sources.glm_kda_window, sources.glm_kda_parts });
}

fn heads(f: Form) usize {
Expand Down Expand Up @@ -48,7 +49,7 @@ pub const Case = struct {

pub fn init(s: *bits.Suite, form: Form, control: bool) !Case {
const loader = try s.production();
const own = try text(s.a);
const own = try text(s.a, !s.device.tensorUnits());
defer s.a.free(own);
_ = try loader.require(own);
const body = if (!control) try s.a.dupe(u8, own) else if (form == .parts) try bits.edited(s.a, own, "void glm_kda_parts(", "const uint dv0 = part * (uint)DV;", "const uint dv0 = 0u * part;") else try bits.edited(s.a, own, "void glm_kda_window(", "P[(size_t)(r0 + (int)tid) * PS + BO + h]", "P[(size_t)r0 * PS + BO + h]");
Expand Down Expand Up @@ -193,7 +194,6 @@ pub fn collect(s: *bits.Suite, only: ?[]const u8) !void {

/// Gate 5's registrations `glm launch kda <function>`: the loader's KDA library.
pub const prefix = "glm launch kda ";
pub fn limitsText(a: std.mem.Allocator, _: mtl.Device, _: []const u8) !bits.Texts {
const t = try text(a);
return .{ .here = t, .pre_m5 = t };
pub fn limitsText(a: std.mem.Allocator, device: mtl.Device, _: []const u8) !bits.Texts {
return .{ .here = try text(a, !device.tensorUnits()), .pre_m5 = try text(a, true) };
}
2 changes: 1 addition & 1 deletion zig/tests/contract/metal_limits.zig
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ fn resolve(a: std.mem.Allocator, device: mtl.Device, d: limits.MetalLaunch, comp
} else if (std.mem.startsWith(u8, d.name, "h3 ")) {
if (!assemble) return undefined;
text = @import("h3_kernels").source;
} else if (std.mem.startsWith(u8, d.name, "glm gather ") or std.mem.startsWith(u8, d.name, "glm rows ")) {
} else if (std.mem.startsWith(u8, d.name, "glm gather ") or std.mem.startsWith(u8, d.name, "glm rows ") or std.mem.startsWith(u8, d.name, "glm moe rows ")) {
if (!assemble) return undefined;
text = tf.glm.wide.gather_source;
} else if (std.mem.startsWith(u8, d.name, "nemotron experts ")) {
Expand Down
Loading