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

- CUDA kernel contract: on sm_120 and sm_121 the grouped EXL3 baseline controls (`tf_ctl_exl3_grouped_old_*`, main's loop that gate 3 holds the load-ahead kernels to) work out each lane's word indices once, before the k loop, so nvcc 13.3 gives `contract_controls` one form between identical compiles; the served images are unchanged (#5262, refs #5123).

- `tensorfold log` recognises request-log records by the fields each shape must carry instead of by field count, so a record with an extra field no longer splits a request and its reply into two rows (#5492, thanks @devopsfortunato).

- Metal: the DFlash2 drafters' RMS norm rows and Nemotron's group norm come from one kernel body each instead of repeated copies; generated kernels and served output are unchanged (#5313, part of #2251). Thanks to @jschmied.
Expand Down
27 changes: 26 additions & 1 deletion zig/kernels/cuda/exl3_grouped.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ struct GroupedArgs {
// How a warp reads its k tiles: main's loop, or a tile ahead (sm_120 up); SKIP and STALE are the contract's faults.
enum Load : int { PLAIN = 0, AHEAD = 1, SKIP = 2, STALE = 3 };

// This lane's words of the tile at p, at word indices at (ldg_lane_words with its indices computed once a warp).
template <int LW>
__device__ __forceinline__ void ldg_at(const uint32_t* p, const int (&at)[LW], uint32_t (&w)[LW]) {
#pragma unroll
for (int l = 0; l < LW; ++l) w[l] = ldg_stream_u32(p + at[l]);
}

// PLAIN at sm_120 up is the contract's baseline alone (the served kernels read ahead): its indices before the loop.
#if defined(__CUDA_ARCH__) && __CUDA_ARCH__ >= 1200
constexpr bool plain_at_once = true;
#else
constexpr bool plain_at_once = false;
#endif

// One warp's k tiles [kt0, kt0 + nkt) of an expert matrix for MT 16-member tiles: per-lane loads, the shared decode.
template <int CB, int K2, int NT, int LOAD, int MT = 1>
__device__ __forceinline__ void warp_tiles(const uint32_t* T, int ntiles, int kt0, int nkt, int nt0,
Expand All @@ -41,13 +55,24 @@ __device__ __forceinline__ void warp_tiles(const uint32_t* T, int ntiles, int kt
}
const size_t kstride = (size_t)ntiles * TW;
const uint32_t* tb = T + (size_t)kt0 * kstride + (size_t)nt0 * TW;
int at[LW] = {}; // PLAIN at sm_120 up: the lane's word indices in a tile, before the loop
if constexpr (LOAD == PLAIN && plain_at_once) {
int word, offset;
lane_start<K2>(lane, word, offset);
#pragma unroll
for (int l = 0; l < LW; ++l) at[l] = (word + l) % TW;
}
uint32_t nx[NT][LW]; // the next tile's words, in flight while this one decodes
if (LOAD != PLAIN && nkt > 0)
#pragma unroll
for (int j = 0; j < NT; ++j) ldg_lane_words<K2>(tb + j * TW, lane, nx[j]);
for (int i = 0; i < nkt; ++i) {
uint32_t w[NT][LW];
if constexpr (LOAD == PLAIN) {
if constexpr (LOAD == PLAIN && plain_at_once) {
const uint32_t* t0 = T + (size_t)(kt0 + i) * kstride + (size_t)nt0 * TW;
#pragma unroll
for (int j = 0; j < NT; ++j) ldg_at(t0 + j * TW, at, w[j]);
} else if constexpr (LOAD == PLAIN) {
const uint32_t* t0 = T + (size_t)(kt0 + i) * kstride + (size_t)nt0 * TW;
#pragma unroll
for (int j = 0; j < NT; ++j) ldg_lane_words<K2>(t0 + j * TW, lane, w[j]);
Expand Down
6 changes: 3 additions & 3 deletions zig/src/core/contract/exl3_grouped_records.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
const std = @import("std");
const registry = @import("registry.zig");
pub const records = [_]registry.CudaRecord{
.{ .launch = .{ .name = "exl3_grouped tf_ctl_exl3_grouped_old_0", .symbol = "tf_ctl_exl3_grouped_old_0", .image = "contract_controls", .threads = 128 }, .usage = .{ .{ .regs = 128, .static = 32832, .bound = 0 }, .{ .regs = 128, .static = 32832, .bound = 0 }, .{ .regs = 128, .static = 32832, .bound = 0 }, .{ .regs = 127, .static = 32832, .bound = 0 }, .{ .regs = 127, .static = 32832, .bound = 0 } }, .later_pending = true },
.{ .launch = .{ .name = "exl3_grouped tf_ctl_exl3_grouped_old_1", .symbol = "tf_ctl_exl3_grouped_old_1", .image = "contract_controls", .threads = 128 }, .usage = .{ .{ .regs = 128, .static = 32832, .bound = 0 }, .{ .regs = 127, .static = 32832, .bound = 0 }, .{ .regs = 127, .static = 32832, .bound = 0 }, .{ .regs = 128, .static = 32832, .bound = 0 }, .{ .regs = 128, .static = 32832, .bound = 0 } }, .later_pending = true },
.{ .launch = .{ .name = "exl3_grouped tf_ctl_exl3_grouped_old_2", .symbol = "tf_ctl_exl3_grouped_old_2", .image = "contract_controls", .threads = 128 }, .usage = .{ .{ .regs = 128, .static = 32832, .bound = 0 }, .{ .regs = 128, .static = 32832, .bound = 0 }, .{ .regs = 128, .static = 32832, .bound = 0 }, .{ .regs = 128, .static = 32832, .bound = 0 }, .{ .regs = 128, .static = 32832, .bound = 0 } }, .later_pending = true },
.{ .launch = .{ .name = "exl3_grouped tf_ctl_exl3_grouped_old_0", .symbol = "tf_ctl_exl3_grouped_old_0", .image = "contract_controls", .threads = 128 }, .usage = .{ .{ .regs = 128, .static = 32896, .bound = 0 }, .{ .regs = 128, .static = 32896, .bound = 0 }, .{ .regs = 128, .static = 32896, .bound = 0 }, .{ .regs = 128, .static = 32896, .bound = 0 }, .{ .regs = 128, .static = 32896, .bound = 0 } }, .later_pending = true },
.{ .launch = .{ .name = "exl3_grouped tf_ctl_exl3_grouped_old_1", .symbol = "tf_ctl_exl3_grouped_old_1", .image = "contract_controls", .threads = 128 }, .usage = .{ .{ .regs = 128, .static = 32896, .bound = 0 }, .{ .regs = 127, .static = 32896, .bound = 0 }, .{ .regs = 127, .static = 32896, .bound = 0 }, .{ .regs = 127, .static = 32896, .bound = 0 }, .{ .regs = 127, .static = 32896, .bound = 0 } }, .later_pending = true },
.{ .launch = .{ .name = "exl3_grouped tf_ctl_exl3_grouped_old_2", .symbol = "tf_ctl_exl3_grouped_old_2", .image = "contract_controls", .threads = 128 }, .usage = .{ .{ .regs = 128, .static = 32896, .bound = 0 }, .{ .regs = 128, .static = 32896, .bound = 0 }, .{ .regs = 128, .static = 32896, .bound = 0 }, .{ .regs = 126, .static = 32896, .bound = 0 }, .{ .regs = 126, .static = 32896, .bound = 0 } }, .later_pending = true },
};

fn regs(name: []const u8, release: @import("limits.zig").Nvcc) ![5]u32 {
Expand Down
6 changes: 3 additions & 3 deletions zig/src/core/contract/measurements/pending_133.zig
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ pub const records = [_]Override{
.{ .name = "inkling2 dspark tf_ink2_dsp_rnn", .usage = .{ .{ .regs = 32, .static = 5120, .bound = 256 }, .{ .regs = 39, .static = 5120, .bound = 256 }, .{ .regs = 39, .static = 5120, .bound = 256 }, .{ .regs = 39, .static = 5120, .bound = 256 }, .{ .regs = 39, .static = 5120, .bound = 256 } } },
.{ .name = "inkling2 dspark tf_ink2_dsp_vocab", .usage = .{ .{ .regs = 21, .static = 0, .bound = 256 }, .{ .regs = 22, .static = 0, .bound = 256 }, .{ .regs = 22, .static = 0, .bound = 256 }, .{ .regs = 15, .static = 0, .bound = 256 }, .{ .regs = 15, .static = 0, .bound = 256 } } },
.{ .name = "inkling2 dspark tf_ink2_dsp_pick_merge", .usage = .{ .{ .regs = 22, .static = 0, .bound = 0 }, .{ .regs = 22, .static = 0, .bound = 0 }, .{ .regs = 22, .static = 0, .bound = 0 }, .{ .regs = 40, .static = 0, .bound = 0 }, .{ .regs = 40, .static = 0, .bound = 0 } } },
.{ .name = "exl3_grouped tf_ctl_exl3_grouped_old_0", .usage = .{ .{ .regs = 128, .static = 32832, .bound = 0 }, .{ .regs = 128, .static = 32832, .bound = 0 }, .{ .regs = 128, .static = 32832, .bound = 0 }, .{ .regs = 127, .static = 32832, .bound = 0 }, .{ .regs = 127, .static = 32832, .bound = 0 } } },
.{ .name = "exl3_grouped tf_ctl_exl3_grouped_old_1", .usage = .{ .{ .regs = 128, .static = 32832, .bound = 0 }, .{ .regs = 128, .static = 32832, .bound = 0 }, .{ .regs = 128, .static = 32832, .bound = 0 }, .{ .regs = 128, .static = 32832, .bound = 0 }, .{ .regs = 128, .static = 32832, .bound = 0 } } },
.{ .name = "exl3_grouped tf_ctl_exl3_grouped_old_2", .usage = .{ .{ .regs = 128, .static = 32832, .bound = 0 }, .{ .regs = 128, .static = 32832, .bound = 0 }, .{ .regs = 128, .static = 32832, .bound = 0 }, .{ .regs = 128, .static = 32832, .bound = 0 }, .{ .regs = 128, .static = 32832, .bound = 0 } } },
.{ .name = "exl3_grouped tf_ctl_exl3_grouped_old_0", .usage = .{ .{ .regs = 128, .static = 32896, .bound = 0 }, .{ .regs = 128, .static = 32896, .bound = 0 }, .{ .regs = 128, .static = 32896, .bound = 0 }, .{ .regs = 128, .static = 32896, .bound = 0 }, .{ .regs = 128, .static = 32896, .bound = 0 } } },
.{ .name = "exl3_grouped tf_ctl_exl3_grouped_old_1", .usage = .{ .{ .regs = 128, .static = 32896, .bound = 0 }, .{ .regs = 128, .static = 32896, .bound = 0 }, .{ .regs = 128, .static = 32896, .bound = 0 }, .{ .regs = 128, .static = 32896, .bound = 0 }, .{ .regs = 128, .static = 32896, .bound = 0 } } },
.{ .name = "exl3_grouped tf_ctl_exl3_grouped_old_2", .usage = .{ .{ .regs = 128, .static = 32896, .bound = 0 }, .{ .regs = 128, .static = 32896, .bound = 0 }, .{ .regs = 128, .static = 32896, .bound = 0 }, .{ .regs = 128, .static = 32896, .bound = 0 }, .{ .regs = 128, .static = 32896, .bound = 0 } } },
.{ .name = "GLM BF16 tf_ctl_glm_old_hc_finish", .usage = .{ .{ .regs = 64, .static = 48, .bound = 256 }, .{ .regs = 64, .static = 48, .bound = 256 }, .{ .regs = 64, .static = 48, .bound = 256 }, .{ .regs = 64, .static = 48, .bound = 256 }, .{ .regs = 64, .static = 48, .bound = 256 } } },
.{ .name = "GLM BF16 tf_ctl_glm_old_rmsnorm_1536", .usage = .{ .{ .regs = 40, .static = 16, .bound = 128 }, .{ .regs = 40, .static = 16, .bound = 128 }, .{ .regs = 40, .static = 16, .bound = 128 }, .{ .regs = 38, .static = 16, .bound = 128 }, .{ .regs = 38, .static = 16, .bound = 128 } } },
.{ .name = "GLM BF16 tf_ctl_glm_old_rmsnorm_4096", .usage = .{ .{ .regs = 40, .static = 32, .bound = 256 }, .{ .regs = 40, .static = 32, .bound = 256 }, .{ .regs = 40, .static = 32, .bound = 256 }, .{ .regs = 40, .static = 32, .bound = 256 }, .{ .regs = 40, .static = 32, .bound = 256 } } },
Expand Down
Loading