Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 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
13961db
feat(hip): tensor parallelism over RCCL, behind hip/collective.zig
BlivionIaG Oct 11, 2026
ba0bc3c
feat(hip): the graph cache by shape in the hip module, for every HIP …
BlivionIaG Oct 12, 2026
905d9e9
feat(hip): a step recorded as graphs cut at its collectives, the coll…
BlivionIaG Oct 12, 2026
5480055
feat(hip): the graph cache over any replayable step, a caller's own k…
BlivionIaG Oct 12, 2026
ebe69eb
feat(qwen3_5): HIP rounds record split graphs: the collectives run be…
BlivionIaG Oct 12, 2026
10926cf
feat(qwen3_5): HIP rounds replay split graphs at any world size, RCCL…
BlivionIaG Oct 12, 2026
66d8a19
fix(qwen3_5): every rank sizes its streams for rank 0's window, so a …
BlivionIaG Oct 12, 2026
d47b0f8
perf(qwen3_5): the HIP loader drops each part's mapped pages once it …
BlivionIaG Oct 13, 2026
a9bab75
Merge 1.0.9 (c36b536d) into hip-kernels-affine
BlivionIaG Oct 13, 2026
fa4d769
Merge branch 'qwen35-structured' into fn-base3
BlivionIaG Oct 13, 2026
f76877c
Merge branch 'hip-kernels-affine' (1.0.9) into fn-base3
BlivionIaG Oct 13, 2026
996c098
fix(core): MLX affine dequant reads any code width from 2 to 8 bits, …
BlivionIaG Oct 12, 2026
3fa8861
refactor(core): a MoE layer's stacked experts and router rows in core…
BlivionIaG Oct 11, 2026
1ae1078
style(hip): the ops headers end without a blank line, as git diff --c…
BlivionIaG Oct 14, 2026
fbc626d
Merge branch 'hip-kernels-ops' into hip-kernels-affine (ops headers e…
BlivionIaG Oct 14, 2026
47612d0
Merge branch 'hip-kernels-ops' into qwen35-family (ops headers end wi…
BlivionIaG Oct 14, 2026
3850523
Merge branch 'qwen35-family' into qwen35-rccl (ops headers end withou…
BlivionIaG Oct 14, 2026
deec0a9
Merge branch 'qwen35-family' into qwen35-structured (ops headers end …
BlivionIaG Oct 14, 2026
3f4cc24
Merge the ops headers' whitespace fix (#617, through #621, #697 and #…
BlivionIaG Oct 14, 2026
5537d6a
fix(hip): the paged prefill tile calls expf, as the flat tile does
BlivionIaG Oct 14, 2026
bbf83cd
Merge branch 'hip-kernels-ops' into hip-kernels-affine (the paged pre…
BlivionIaG Oct 14, 2026
9178585
Merge branch 'hip-kernels-ops' into qwen35-family (the paged prefill …
BlivionIaG Oct 14, 2026
f5281d5
Merge branch 'qwen35-family' into qwen35-rccl (the paged prefill tile…
BlivionIaG Oct 14, 2026
28c3160
Merge branch 'qwen35-family' into qwen35-structured (the paged prefil…
BlivionIaG Oct 14, 2026
4a91921
Merge the paged prefill tile's expf (#617, through #621, #697 and #655)
BlivionIaG Oct 14, 2026
d91b074
fix(hip): one fp32 DeltaNet recurrence at every length; the chunked p…
BlivionIaG Oct 14, 2026
da96b90
Merge branch 'hip-kernels-ops' into hip-kernels-affine (one fp32 Delt…
BlivionIaG Oct 14, 2026
1da7042
Merge branch 'hip-kernels-ops' into qwen35-family (one fp32 DeltaNet …
BlivionIaG Oct 14, 2026
205b800
Merge branch 'qwen35-family' into qwen35-rccl (one fp32 DeltaNet recu…
BlivionIaG Oct 14, 2026
81d6529
Merge branch 'qwen35-family' into qwen35-structured (one fp32 DeltaNe…
BlivionIaG Oct 14, 2026
1bdd859
refactor(hip): the policy's gdn switch goes with the chunked recurren…
BlivionIaG Oct 14, 2026
edc5b3f
refactor(hip): the policy's gdn switch goes with the chunked recurren…
BlivionIaG Oct 14, 2026
02c3ff0
Merge the one fp32 DeltaNet recurrence (#617, through #655)
BlivionIaG Oct 14, 2026
4d5f7a9
Merge the one fp32 DeltaNet recurrence (through #697)
BlivionIaG Oct 14, 2026
060c30e
Merge the one fp32 DeltaNet recurrence (through #621)
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
2 changes: 1 addition & 1 deletion build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ pub fn build(b: *std.Build) void {
const api_mod = b.createModule(.{ .root_source_file = b.path("zig/src/core/engine_api.zig"), .target = target, .optimize = optimize, .link_libc = true, .imports = &.{.{ .name = "lanes", .module = lanes_mod }} });
test_step.dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = api_mod })).step);
}
hip_build.steps(b, target, test_step);
hip_build.steps(b, target, optimize, build_options, test_step);
exlr8_build.hostTests(b, target, test_step);
const lanes_cpu = b.createModule(.{ .root_source_file = b.path("zig/src/core/lanes/lanes.zig"), .target = b.graph.host, .optimize = .debug, .link_libc = true });
const disk_cpu = b.addTest(.{ .root_module = b.createModule(.{
Expand Down
152 changes: 151 additions & 1 deletion zig/build/hip.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

const std = @import("std");
const caps = @import("../src/hip/caps.zig");
const exlr8_build = @import("exlr8.zig");

/// hip-host-test (part of `test`), hip-gpu-build and hip-gpu-test, hip-affine-build and hip-affine-test.
pub fn steps(b: *std.Build, target: std.Build.ResolvedTarget, test_step: *std.Build.Step) void {
pub fn steps(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, build_options: *std.Build.Step.Options, test_step: *std.Build.Step) void {
const hip_fixtures = b.addOptions();
for ([_][]const u8{ "success", "failed", "missing" }) |kind| {
const fixture_module = b.createModule(.{ .target = b.graph.host, .link_libc = true });
Expand All @@ -21,10 +22,21 @@ pub fn steps(b: *std.Build, target: std.Build.ResolvedTarget, test_step: *std.Bu
.link_libc = true,
});
hip_test_module.addOptions("hip_fixtures", hip_fixtures);
hip_test_module.addImport("hip_kernels", b.createModule(.{ .root_source_file = b.addWriteFiles().add("kernels.zig", stub) }));
hip_test_module.addImport("core", coreModule(b, b.graph.host));
const hip_tests = b.addTest(.{ .root_module = hip_test_module });
const run_hip_tests = b.addRunArtifact(hip_tests);
test_step.dependOn(&run_hip_tests.step);
b.step("hip-host-test", "HIP admission tests without GPU work").dependOn(&run_hip_tests.step);
const loader = b.addRunArtifact(b.addTest(.{ .root_module = b.createModule(.{
.root_source_file = b.path("zig/src/families/qwen3_5/loader.zig"),
.target = b.graph.host,
.link_libc = true,
.imports = &.{.{ .name = "core", .module = coreModule(b, b.graph.host) }},
}) }));
loader.has_side_effects = true; // TF_QWEN_DIR is not a cached input
test_step.dependOn(&loader.step);
b.step("test-qwen35", "Qwen3.5 / 3.6 checkpoint loader tests; TF_QWEN_DIR indexes a real checkpoint").dependOn(&loader.step);
const hipcc = b.option([]const u8, "hipcc", "HIP compiler for model-free tests") orelse "hipcc";
const hipcc_resolved = b.findProgram(.{ .names = &.{hipcc} }) orelse hipcc;
const hip_include = b.option([]const u8, "hip-include", "HIP header directory") orelse
Expand Down Expand Up @@ -63,4 +75,142 @@ pub fn steps(b: *std.Build, target: std.Build.ResolvedTarget, test_step: *std.Bu
const affine_test = b.addTest(.{ .root_module = affine_module });
b.step("hip-affine-build", "Compile affine golden GPU test without executing").dependOn(&affine_test.step);
b.step("hip-affine-test", "Run exact affine golden GPU regression").dependOn(&b.addRunArtifact(affine_test).step);
const device_lib = b.option([]const u8, "hip-device-lib", "ROCm device bitcode directory (default <rocm>/lib/llvm/amdgcn/bitcode; Arch: <rocm>/amdgcn/bitcode)");
const objects = kernelObjects(b, hipcc, hipcc_resolved, device_lib, hip_arch);
const kernel_module = b.createModule(.{ .root_source_file = b.path("zig/src/hip/kernel_tests.zig"), .target = target, .link_libc = true });
kernel_module.addIncludePath(.{ .cwd_relative = hip_include });
kernel_module.addCSourceFile(.{ .file = b.path("zig/src/hip/device_arch.c"), .flags = &.{"-D__HIP_PLATFORM_AMD__"} });
kernel_module.addImport("hip_kernels", objects);
kernel_module.addImport("core", coreModule(b, target));
const kernel_test = b.addTest(.{ .root_module = kernel_module });
b.step("hip-kernel-build", "Compile the model-free kernels and their GPU tests without running them").dependOn(&kernel_test.step);
b.step("hip-kernel-test", "Every model-free kernel against its host reference on the GPU").dependOn(&b.addRunArtifact(kernel_test).step);
const stub_kernels = b.createModule(.{ .root_source_file = b.addWriteFiles().add("kernels.zig", stub) });
const host = engineModules(b, b.graph.host, .Debug, stub_kernels, null);
test_step.dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = host.hip })).step);
test_step.dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = host.family })).step);
test_step.dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = host.native })).step);
// the GPU programs compile on any host against stub kernels, so `test` catches what only they reach
test_step.dependOn(&checksExe(b, b.graph.host, .Debug, host).step);
test_step.dependOn(&server(b, b.graph.host, host, build_options).step);
const gpu = engineModules(b, target, optimize, objects, hip_include);
b.step("tf-qwen35-test", "Qwen3.5 / 3.6 model checks on the GPU (-Dhip-arch)").dependOn(&b.addInstallArtifact(checksExe(b, target, optimize, gpu), .{}).step);
const native = server(b, target, gpu, build_options);
b.step("native-hip", "tensorfold-native with the HIP engines into zig-out/native-hip/bin (-Dhip-arch)").dependOn(&b.addInstallArtifact(native, .{ .dest_dir = .{ .override = .{ .custom = "native-hip/bin" } } }).step);
}

/// `tf-qwen35-test`: the model checks on a real checkpoint and GPU.
fn checksExe(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, e: Engine) *std.Build.Step.Compile {
return b.addExecutable(.{ .name = "tf-qwen35-test", .root_module = b.createModule(.{
.root_source_file = b.path("zig/tests/qwen35/main.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
.imports = &.{ .{ .name = "hip", .module = e.hip }, .{ .name = "qwen3_5", .module = e.family }, .{ .name = "lanes", .module = e.lanes }, .{ .name = "npy", .module = b.createModule(.{ .root_source_file = b.path("zig/src/core/npy.zig"), .target = target, .optimize = optimize }) } },
}) });
}

const Engine = struct { hip: *std.Build.Module, lanes: *std.Build.Module, api: *std.Build.Module, family: *std.Build.Module, native: *std.Build.Module };

/// The HIP backend, the Qwen3.5 family over it and the native engines, on `kernels` (a stub on the host).
fn engineModules(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, kernels: *std.Build.Module, hip_include: ?[]const u8) Engine {
const core = coreModule(b, target);
const hip = b.createModule(.{ .root_source_file = b.path("zig/src/hip/root.zig"), .target = target, .optimize = optimize, .link_libc = true });
hip.addImport("core", core);
hip.addImport("hip_kernels", kernels);
hip.addImport("cuda_memory", b.createModule(.{ .root_source_file = b.path("zig/src/native/cuda_memory.zig"), .target = target, .optimize = optimize }));
if (hip_include) |dir| {
hip.addIncludePath(.{ .cwd_relative = dir });
hip.addCSourceFile(.{ .file = b.path("zig/src/hip/device_arch.c"), .flags = &.{"-D__HIP_PLATFORM_AMD__"} });
}
const lanes = b.createModule(.{ .root_source_file = b.path("zig/src/core/lanes/lanes.zig"), .target = target, .optimize = optimize, .link_libc = true });
const api = b.createModule(.{ .root_source_file = b.path("zig/src/core/engine_api.zig"), .target = target, .optimize = optimize, .link_libc = true, .imports = &.{.{ .name = "lanes", .module = lanes }} });
const family = b.createModule(.{
.root_source_file = b.path("zig/src/families/qwen3_5/hip.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
.imports = &.{ .{ .name = "hip", .module = hip }, .{ .name = "core", .module = core }, .{ .name = "lanes", .module = lanes }, .{ .name = "engine_api", .module = api } },
});
const native = b.createModule(.{
.root_source_file = b.path("zig/src/native/hip.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
.imports = &.{ .{ .name = "hip", .module = hip }, .{ .name = "engine_api", .module = api }, .{ .name = "lanes", .module = lanes }, .{ .name = "qwen3_5", .module = family } },
});
return .{ .hip = hip, .lanes = lanes, .api = api, .family = family, .native = native };
}

/// The server over the HIP engines, as the CUDA build makes it: the HTTP side keeps its safety checks.
fn server(b: *std.Build, target: std.Build.ResolvedTarget, e: Engine, build_options: *std.Build.Step.Options) *std.Build.Step.Compile {
const api = e.api;
const engines = e.native;
const tokenizer = e.hip.import_table.get("core").?.import_table.get("tokenizer").?;
const template = b.createModule(.{ .root_source_file = b.path("zig/src/core/template/template.zig"), .target = target, .optimize = .ReleaseSafe, .link_libc = true });
const exe = b.addExecutable(.{ .name = "tensorfold-native", .root_module = b.createModule(.{
.root_source_file = b.path("zig/src/server/main.zig"),
.target = target,
.optimize = .ReleaseSafe,
.link_libc = true,
.imports = &.{ .{ .name = "engine_api", .module = api }, .{ .name = "tokenizer", .module = tokenizer }, .{ .name = "template", .module = template }, .{ .name = "native_engines", .module = engines }, .{ .name = "checkpoint_cli", .module = b.createModule(.{ .root_source_file = b.path("zig/src/cli/cli.zig"), .target = target, .optimize = .ReleaseSafe, .link_libc = true, .imports = &.{ .{ .name = "native_engines", .module = engines }, exlr8_build.cliImport(b, target, .ReleaseSafe, e.hip.import_table.get("core").?) } }) } },
}) });
exe.root_module.addOptions("build_options", build_options);
return exe;
}

/// The model-free kernels' source groups, in zig/src/hip/kernels.zig's Group order.
const groups = [_][]const u8{ "ops/ops.hip", "ops/act.hip", "attention/attention.hip", "recurrence/gated_delta.hip", "attention/prefill.hip", "decode/decode.hip", "decode/plan.hip", "tiles/dot2_tiles.hip", "tiles/dot2.hip" };

/// What the group sources include, so an edit to one rebuilds them.
const headers = [_][]const u8{
"attention/attention_fa.hip", "decode/pages.hpp", "decode/plan.hpp", "ops/attention.hpp", "ops/common.hpp",
"ops/draw.hpp", "ops/tp.hpp", "ops/elementwise.hpp", "ops/linear.hpp", "ops/moe.hpp",
"ops/norms.hpp", "ops/rope.hpp", "common/arch.hpp", "common/dot2.hpp", "common/vec.hpp",
"common/wmma.hpp", "quant/act.hpp", "quant/mlx.hpp", "quant/mlx_decoder.hpp", "quant/mlx_pieces.hpp",
"quant/mlx_tiles.hpp", "tiles/dot2.hpp", "tiles/epilogue.hpp", "tiles/gemm.hpp", "tiles/gemm_kp.hpp",
"tiles/matrix_gemm.hpp", "tiles/plan.hpp", "tiles/stream.hpp",
};

/// The flags of the kernels' first build: no contraction, wave32 on RDNA, C++20.
const flags = [_][]const u8{ "-D__HIP_PLATFORM_AMD__=1", "-DUSE_ROCM=1", "-DHIPBLAS_V2", "-fPIC", "-DCUDA_HAS_FP16=1", "-DHIP_ENABLE_WARP_SYNC_BUILTINS=1", "-std=c++20", "-fno-gpu-rdc", "-mno-wavefrontsize64", "-ffp-contract=off" };

const stub = "pub const arch = \"\";\npub const images: [9][]align(8) const u8 = @splat(&.{});\n";

/// One code object a group for `arch`, built with the caps table's instruction switches, as the `hip_kernels` module.
fn kernelObjects(b: *std.Build, hipcc: []const u8, hipcc_resolved: []const u8, device_lib: ?[]const u8, arch: []const u8) *std.Build.Module {
const c = caps.Caps.of(arch).?;
const root = std.fs.path.dirname(std.fs.path.dirname(hipcc_resolved) orelse ".") orelse ".";
const files = b.addWriteFiles();
var decls: []const u8 = "";
var refs: []const u8 = "";
for (groups, 0..) |source, i| {
const run = b.addSystemCommand(&.{ hipcc, "--genco" });
run.addArgs(&flags);
run.addArg(b.fmt("-DTF_WAVE={d}", .{c.wave}));
run.addArg(b.fmt("-DTF_DOT2_F16={d}", .{@intFromBool(c.dot2_f16)}));
run.addArg(b.fmt("-DTF_DOT2_BF16={d}", .{@intFromBool(c.dot2_bf16)}));
run.addArg(b.fmt("-DTF_SDOT4={d}", .{@intFromBool(c.sdot4)}));
run.addArg(b.fmt("-DTF_SDOT8={d}", .{@intFromBool(c.sdot8)}));
run.addArg(b.fmt("-DTF_MATRIX={d}", .{@intFromBool(c.matrix != .none)}));
run.addArg(b.fmt("--rocm-path={s}", .{root}));
run.addArg(b.fmt("--rocm-device-lib-path={s}", .{device_lib orelse b.fmt("{s}/lib/llvm/amdgcn/bitcode", .{root})}));
run.addArg(b.fmt("--offload-arch={s}", .{arch}));
run.addPrefixedDirectoryArg("-I", b.path("zig/kernels/hip"));
for (headers) |h| run.addFileInput(b.path(b.fmt("zig/kernels/hip/{s}", .{h})));
run.addArg("-o");
const object = run.addOutputFileArg(b.fmt("group{d}.hsaco", .{i}));
run.addFileArg(b.path(b.fmt("zig/kernels/hip/{s}", .{source})));
_ = files.addCopyFile(object, b.fmt("group{d}.hsaco", .{i}));
decls = b.fmt("{s}const g{d} align(8) = @embedFile(\"group{d}.hsaco\").*;\n", .{ decls, i, i });
refs = b.fmt("{s}&g{d}, ", .{ refs, i });
}
return b.createModule(.{ .root_source_file = files.add("kernels.zig", b.fmt("pub const arch = \"{s}\";\n{s}pub const images = [_][]align(8) const u8{{ {s}}};\n", .{ arch, decls, refs })) });
}

/// The backend-neutral core (checkpoint formats, the kernel registry), as the other backends import it.
fn coreModule(b: *std.Build, target: std.Build.ResolvedTarget) *std.Build.Module {
const core = b.createModule(.{ .root_source_file = b.path("zig/src/core/root.zig"), .target = target, .link_libc = true });
core.addImport("tokenizer", b.createModule(.{ .root_source_file = b.path("zig/src/core/tokenizer/tokenizer.zig"), .target = target, .link_libc = true }));
return core;
}
Loading
Loading