Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
42 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
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
1ae1078
style(hip): the ops headers end without a blank line, as git diff --c…
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
5537d6a
fix(hip): the paged prefill tile calls expf, as the flat tile does
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
d91b074
fix(hip): one fp32 DeltaNet recurrence at every length; the chunked p…
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
1bdd859
refactor(hip): the policy's gdn switch goes with the chunked recurren…
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
Prev Previous commit
Next Next commit
feat(hip): the kernels a tensor-parallel rank and the MTP head add
ops/tp.hpp in the ops group, device code only: an activation plus an fp32 rank sum rounded once, a rank's local
expert ids and the masks of the experts another rank answers, and a token's softmax probability (MTP's
confidence). Zig launches in launches/tp.zig, `Ops.addWide`, `moeLocalize`, `moeForeignItems`,
`moeZeroForeign` and `tokenProb`. hip-kernel-test checks each against a host reference.
  • Loading branch information
BlivionIaG committed Oct 12, 2026
commit 211ea815f3fe009d469d2fa12c999d64e094ef11
12 changes: 6 additions & 6 deletions zig/build/hip.zig
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ const groups = [_][]const u8{ "ops/ops.hip", "ops/act.hip", "attention/attention

/// 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/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",
"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.
Expand Down
1 change: 1 addition & 0 deletions zig/kernels/hip/ops/ops.hip
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
#include "norms.hpp"
#include "moe.hpp"
#include "draw.hpp"
#include "tp.hpp"
84 changes: 84 additions & 0 deletions zig/kernels/hip/ops/tp.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#pragma once

#include "common.hpp"
#include "draw.hpp"

// Tensor-parallel forward ops: residual add of an fp32 sum, expert-share remap and masks; MTP token probability.

namespace {

__device__ __forceinline__ long long tp_gid() { return static_cast<long long>(blockIdx.x) * blockDim.x + threadIdx.x; }

constexpr int kProbThreads = 256;

} // namespace

// out = round(float(x) + y): the residual of a rank-summed fp32 share.
extern "C" __global__ void tf_add_wide(const void* x, const float* y, void* out, int kind, long long n) {
long long i = tp_gid();
if (i >= n) return;
if (kind == 1) {
float v = __half2float(static_cast<const __half*>(x)[i]) + y[i];
static_cast<__half*>(out)[i] = __float2half_rn(v);
} else {
float v = bf16_to_float(static_cast<const uint16_t*>(x)[i]) + y[i];
static_cast<uint16_t*>(out)[i] = float_to_bf16(v);
}
}

// out[i] = the rank's local id of expert pick[i], or `skip` (an id past the rank's experts) when another rank holds it.
extern "C" __global__ void tf_moe_localize(const int* pick, const int* remap, int* out, int n, int skip) {
int i = static_cast<int>(tp_gid());
if (i >= n) return;
int local = remap[pick[i]];
out[i] = local >= 0 ? local : skip;
}

// An item of the skip expert does no work.
extern "C" __global__ void tf_moe_foreign_items(int* items, int count, int skip) {
int i = static_cast<int>(tp_gid());
if (i < count && items[i * 3] == skip) items[i * 3 + 2] = 0;
}

// A pair another rank's expert answers has zero rows (selected, not multiplied: the buffer holds anything).
extern "C" __global__ void tf_moe_zero_foreign(float* y, const int* picks, int skip, long long pairs, int d) {
long long i = tp_gid();
if (i >= pairs * d) return;
if (picks[i / d] == skip) y[i] = 0.f;
}

// out[r] = softmax(row r)[id[r]], or of the row's largest value when `id` is null; one block a row, a NaN in gives NaN.
extern "C" __global__ void tf_token_prob(const uint16_t* logits, int kind, int n, const int* id, float* out) {
const uint16_t* row = logits + static_cast<long long>(blockIdx.x) * n;
__shared__ float shared[kProbThreads];
float top = -INFINITY;
bool nan = false;
for (int i = threadIdx.x; i < n; i += kProbThreads) {
float v = widen(row[i], kind);
nan |= v != v;
top = fmaxf(top, v);
}
shared[threadIdx.x] = nan ? NAN : top;
__syncthreads();
for (int stride = kProbThreads / 2; stride > 0; stride >>= 1) {
if (threadIdx.x < stride) {
float a = shared[threadIdx.x], b = shared[threadIdx.x + stride];
shared[threadIdx.x] = (a != a || b != b) ? NAN : fmaxf(a, b);
}
__syncthreads();
}
const float peak = shared[0];
__syncthreads();
float total = 0.f;
for (int i = threadIdx.x; i < n; i += kProbThreads) total += expf(widen(row[i], kind) - peak);
shared[threadIdx.x] = total;
__syncthreads();
for (int stride = kProbThreads / 2; stride > 0; stride >>= 1) {
if (threadIdx.x < stride) shared[threadIdx.x] += shared[threadIdx.x + stride];
__syncthreads();
}
if (threadIdx.x == 0) {
const float chosen = id ? expf(widen(row[id[blockIdx.x]], kind) - peak) : 1.f;
out[blockIdx.x] = chosen / shared[0];
}
}
1 change: 1 addition & 0 deletions zig/src/hip/kernel_tests.zig
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ test {
_ = @import("kernel_tests/chain.zig");
_ = @import("kernel_tests/attention.zig");
_ = @import("kernel_tests/ops.zig");
_ = @import("kernel_tests/tp.zig");
_ = @import("kernel_tests/affine/affine.zig");
_ = @import("kernel_tests/affine/rows.zig");
}
128 changes: 128 additions & 0 deletions zig/src/hip/kernel_tests/tp.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
//! A tensor-parallel rank's kernels and MTP's token probability against host references.
const std = @import("std");
const rig = @import("rig.zig");
const Rig = rig.Rig;
const gpa = rig.gpa;
const at = rig.at;
const ops = @import("../ops/ops.zig");
const Kind = ops.Kind;

fn act(t: *const Rig) Kind {
return if (t.bf16) .bf16 else .f16;
}

/// The activation's round-to-nearest-even of an fp32 value, as torch rounds.
fn round(t: *const Rig, f: f32) u16 {
if (!t.bf16) return rig.f16Bits(f);
const u: u32 = @bitCast(f);
if (std.math.isNan(f)) return 0x7fc0;
return @intCast((u + 0x7fff + ((u >> 16) & 1)) >> 16);
}

test "a residual plus an fp32 sum rounds once to the activation, and the expert-share remap and masks are exact" {
const t = try Rig.open(1 << 20);
defer t.close();
const o = t.ops(&t.on);
var rng: rig.Rng = .{ .state = 0x7B };
const n = 3000;
const hx = try gpa.alloc(u16, n);
defer gpa.free(hx);
const hy = try gpa.alloc(f32, n);
defer gpa.free(hy);
for (hx, hy) |*x, *y| {
x.* = t.bits(rng.unit() * 6.0 - 3.0);
y.* = rng.unit() * 0.01 - 0.005;
}
var x = try t.upload(hx);
defer x.free();
var y = try t.upload(hy);
defer y.free();
var out = try t.alloc(n * 2);
defer out.free();
try o.addWide(.{ .ptr = at(x), .kind = act(t) }, at(y), .{ .ptr = at(out), .kind = act(t) }, n);
const experts = 16;
const skip = 8;
var remap: [experts]i32 = undefined;
for (&remap, 0..) |*r, e| r.* = if (e % 2 == 0) @intCast(e / 2) else -1;
var picks: [64]i32 = undefined;
for (&picks) |*p| p.* = @intCast(rng.next() % experts);
var dev_remap = try t.upload(&remap);
defer dev_remap.free();
var dev_picks = try t.upload(&picks);
defer dev_picks.free();
var local = try t.alloc(picks.len * 4);
defer local.free();
try o.moeLocalize(at(dev_picks), at(dev_remap), at(local), picks.len, skip);
var items = [_]i32{ 0, 0, 5, skip, 5, 7, 3, 12, 2, skip, 17, 1 };
var dev_items = try t.upload(&items);
defer dev_items.free();
try o.moeForeignItems(at(dev_items), items.len / 3, skip);
const d = 33;
const ys = try gpa.alloc(f32, picks.len * d);
defer gpa.free(ys);
for (ys) |*v| v.* = rng.unit() + 1.0;
var dev_ys = try t.upload(ys);
defer dev_ys.free();
var local_picks: [picks.len]i32 = undefined;
for (&local_picks, picks) |*l, p| l.* = if (remap[@intCast(p)] >= 0) remap[@intCast(p)] else skip;
var dev_local = try t.upload(&local_picks);
defer dev_local.free();
try o.moeZeroForeign(at(dev_ys), at(dev_local), skip, picks.len, d);
try t.stream.synchronize();
const got = try rig.download(u16, out);
defer gpa.free(got);
for (got, hx, hy) |g, xb, yv| try std.testing.expectEqual(round(t, @as(f32, @floatCast(t.value(xb))) + yv), g);
const gl = try rig.download(i32, local);
defer gpa.free(gl);
try std.testing.expectEqualSlices(i32, &local_picks, gl);
const gi = try rig.download(i32, dev_items);
defer gpa.free(gi);
for (0..items.len / 3) |k| {
const want: i32 = if (items[3 * k] == skip) 0 else items[3 * k + 2];
try std.testing.expectEqual(items[3 * k], gi[3 * k]);
try std.testing.expectEqual(want, gi[3 * k + 2]);
}
const gy = try rig.download(f32, dev_ys);
defer gpa.free(gy);
for (gy, ys, 0..) |g, v, k| try std.testing.expectEqual(if (local_picks[k / d] == skip) 0 else v, g);
}

test "a token's probability is its softmax share of the row, or the largest one's with no ids, within 1e-6 of float64" {
const t = try Rig.open(1 << 20);
defer t.close();
const o = t.ops(&t.on);
var rng: rig.Rng = .{ .state = 0x9E1 };
const rows = 6;
const n = 4099;
const hl = try gpa.alloc(u16, rows * n);
defer gpa.free(hl);
for (hl) |*x| x.* = t.bits(rng.unit() * 16.0 - 8.0);
var ids: [rows]i32 = undefined;
for (&ids) |*id| id.* = @intCast(rng.next() % n);
var logits = try t.upload(hl);
defer logits.free();
var dev_ids = try t.upload(&ids);
defer dev_ids.free();
var with_ids = try t.alloc(rows * 4);
defer with_ids.free();
var largest = try t.alloc(rows * 4);
defer largest.free();
const l: ops.Tensor = .{ .ptr = at(logits), .kind = act(t) };
try o.tokenProb(l, rows, n, at(dev_ids), at(with_ids));
try o.tokenProb(l, rows, n, 0, at(largest));
try t.stream.synchronize();
const gw = try rig.download(f32, with_ids);
defer gpa.free(gw);
const gm = try rig.download(f32, largest);
defer gpa.free(gm);
for (0..rows) |r| {
const row = hl[r * n ..][0..n];
var peak: f64 = -std.math.inf(f64);
for (row) |x| peak = @max(peak, t.value(x));
var total: f64 = 0;
for (row) |x| total += @exp(t.value(x) - peak);
const want = @exp(t.value(row[@intCast(ids[r])]) - peak) / total;
try std.testing.expectApproxEqAbs(want, gw[r], 1e-6);
try std.testing.expectApproxEqAbs(1.0 / total, gm[r], 1e-6);
}
}
16 changes: 16 additions & 0 deletions zig/src/hip/launches.zig
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const recurrence = @import("launches/recurrence.zig");
const plan = @import("launches/plan.zig");
const elementwise = @import("launches/elementwise.zig");
const draw = @import("launches/draw.zig");
const tp = @import("launches/tp.zig");

pub const ConvArgs = conv.ConvArgs;
pub const PlanArgs = plan.PlanArgs;
Expand Down Expand Up @@ -127,6 +128,11 @@ pub const Launcher = struct {
router_small: [2]Function,
rms_rows: Function,
qk_rope: Function,
add_wide: Function,
moe_localize: Function,
moe_foreign_items: Function,
moe_zero_foreign: Function,
token_prob: Function,
};

/// Which kernels a run takes where two give the same bits; every one defaults on.
Expand Down Expand Up @@ -191,6 +197,11 @@ pub const Launcher = struct {
.router_small = .{ try ops.function("tf_router_small_f16"), try ops.function("tf_router_small_bf16") },
.rms_rows = try ops.function("tf_rms_rows"),
.qk_rope = try ops.function("tf_qk_rope"),
.add_wide = try ops.function("tf_add_wide"),
.moe_localize = try ops.function("tf_moe_localize"),
.moe_foreign_items = try ops.function("tf_moe_foreign_items"),
.moe_zero_foreign = try ops.function("tf_moe_zero_foreign"),
.token_prob = try ops.function("tf_token_prob"),
};
const ns = "_ZN2tf4rocm";
l.rms = .{
Expand Down Expand Up @@ -286,6 +297,11 @@ pub const Launcher = struct {
pub const tf_kv_write_at = attention.tf_kv_write_at;
pub const tf_argmax_rows = draw.tf_argmax_rows;
pub const tf_topk_rows = draw.tf_topk_rows;
pub const tf_add_wide = tp.tf_add_wide;
pub const tf_moe_localize = tp.tf_moe_localize;
pub const tf_moe_foreign_items = tp.tf_moe_foreign_items;
pub const tf_moe_zero_foreign = tp.tf_moe_zero_foreign;
pub const tf_token_prob = tp.tf_token_prob;
pub const pagedCausal = attention.pagedCausal;
pub const tf_gdn_gate = recurrence.tf_gdn_gate;
pub const tf_gated_delta = recurrence.tf_gated_delta;
Expand Down
77 changes: 77 additions & 0 deletions zig/src/hip/launches/tp.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
//! A tensor-parallel rank's launches (the fp32 sum into a residual, the local expert ids) and MTP's token probability.

const Launcher = @import("../launches.zig").Launcher;
const util = @import("util.zig");
const S = util.S;
const C = util.C;
const P = util.P;
const I = util.I;
const CI = util.CI;
const F = util.F;
const CF = util.CF;
const Args = util.Args;
const Error = util.Error;
const ad = util.ad;
const dim = util.dim;

fn blocks(n: i64, threads: i64) c_int {
return @intCast(@divFloor(n + threads - 1, threads));
}

/// out = round(x + y) of `n` values, x and out of `kind` (1 fp16, 2 bf16), y fp32.
pub fn tf_add_wide(l: *const Launcher, x: C, y: CF, out: P, kind: c_int, n: c_longlong, s: S) Error!void {
if (n == 0) return;
var a: Args = .{};
try a.add(ad(x));
try a.add(ad(y));
try a.add(ad(out));
try a.add(kind);
try a.add(n);
try l.go(l.op.add_wide, dim(blocks(n, 256), 1, 1), dim(256, 1, 1), 0, s, &a);
}

/// out[i] = remap[pick[i]], or `skip` where it is negative.
pub fn tf_moe_localize(l: *const Launcher, pick: CI, remap: CI, out: I, n: c_int, skip: c_int, s: S) Error!void {
if (n == 0) return;
var a: Args = .{};
try a.add(ad(pick));
try a.add(ad(remap));
try a.add(ad(out));
try a.add(n);
try a.add(skip);
try l.go(l.op.moe_localize, dim(blocks(n, 256), 1, 1), dim(256, 1, 1), 0, s, &a);
}

/// Zeroes the pair count of every plan item of the `skip` expert.
pub fn tf_moe_foreign_items(l: *const Launcher, items: I, count: c_int, skip: c_int, s: S) Error!void {
if (count == 0) return;
var a: Args = .{};
try a.add(ad(items));
try a.add(count);
try a.add(skip);
try l.go(l.op.moe_foreign_items, dim(blocks(count, 256), 1, 1), dim(256, 1, 1), 0, s, &a);
}

/// Zeroes the rows of `y` (pairs, d) fp32 whose pick is `skip`.
pub fn tf_moe_zero_foreign(l: *const Launcher, y: F, picks: CI, skip: c_int, pairs: c_longlong, d: c_int, s: S) Error!void {
if (pairs == 0) return;
var a: Args = .{};
try a.add(ad(y));
try a.add(ad(picks));
try a.add(skip);
try a.add(pairs);
try a.add(d);
try l.go(l.op.moe_zero_foreign, dim(blocks(pairs * d, 256), 1, 1), dim(256, 1, 1), 0, s, &a);
}

/// out[r] = softmax(row r)[id[r]] of (rows, n) logits of `kind`, or of the row's largest value when `id` is null.
pub fn tf_token_prob(l: *const Launcher, logits: C, kind: c_int, rows: c_int, n: c_int, id: CI, out: F, s: S) Error!void {
if (rows == 0) return;
var a: Args = .{};
try a.add(ad(logits));
try a.add(kind);
try a.add(n);
try a.add(ad(id));
try a.add(ad(out));
try l.go(l.op.token_prob, dim(rows, 1, 1), dim(256, 1, 1), 0, s, &a);
}
6 changes: 6 additions & 0 deletions zig/src/hip/ops/draw.zig
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ pub fn argmaxRows(o: Ops, logits: Tensor, rows: usize, n: usize, out: u64) Error
try o.l.tf_argmax_rows(p(logits.ptr), @backingInt(logits.kind), int(rows), int(n), i(out), o.stream);
}

/// softmax(row r)[ids[r]] of `rows` logits rows (fp16 or bf16) into fp32 `out`; of the row's largest when `ids` is 0.
pub fn tokenProb(o: Ops, logits: Tensor, rows: usize, n: usize, ids: u64, out: u64) Error!void {
if (logits.kind == .f32) return error.BadShape;
try o.l.tf_token_prob(p(logits.ptr), @backingInt(logits.kind), int(rows), int(n), if (ids == 0) null else @ptrFromInt(ids), f(out), o.stream);
}

/// Each row's `ks[r]` largest by (value desc, id asc): ids (i32) and the values' 16-bit patterns, `stride` apart.
pub fn topkRows(o: Ops, logits: Tensor, rows: usize, n: usize, ks: u64, stride: usize, ids: u64, values: u64) Error!void {
if (logits.kind == .f32) return error.BadShape;
Expand Down
Loading