This commit is contained in:
Niko1221 committed 2026-11-22 13:01:28 +01:00
1 parent c6f6427d9d
commit ad4c565e86
13 files changed
+523 -31

No files matched your search

+3 -3
View File
@@ -681,15 +681,15 @@ builds make that identity easy to mistake, see below - so calibrate it on the ca
```sh
cmake --build build-hip --target tune_rocblas
LD_LIBRARY_PATH=/opt/rocm/lib ./build-hip/tune_rocblas --tuning-out table.txt # 14 shapes x 8 token buckets, about 5 min
LD_LIBRARY_PATH=/opt/rocm/lib ./build-hip/tune_rocblas --tuning-out table.txt # 14 shapes x 12 token buckets, about 15 min
```
The tool times rocBLAS's default kernel and every solution the library lists for each shape at T = 256 ... 8192 (`--case
The tool times rocBLAS's default kernel and every solution the library lists for each shape at T = 256 ... 16384 (`--case
T,N,K,ldy` adds a shape, `--tokens` changes the buckets), checks the fastest against the default's output, and writes one row
per shape and bucket: the winning solution where it beats the default by `--min-gain` (1.05), `default` otherwise. The header
names the architecture and version (`STRATA_ROCBLAS_TUNING_V1 gfx1030 5.6.0.8d1ae90e`). Save it as
`tools/hip/<arch>-rocblas-<version>.txt` (trailing dots dropped) for setup, or point `STRATA_ROCBLAS_TUNING` at the file.
`STRATA_ROCBLAS_VERBOSE=1` prints the solution picked per shape and a `tuned_launches=... fallbacks=...` summary at exit. A
`STRATA_ROCBLAS_VERBOSE=1` prints the solution picked per shape (or `default kernel; no row for T=... N=... K=... ldy=...`) and a `tuned_launches=... fallbacks=...` summary at exit; a read at the prompt lengths you use lists every (T, N, K, ldy) the engine calls, which is the way to check that a table covers them (a row matches N, K and ldy exactly; T goes to the nearest bucket). A
solution rocBLAS refuses at run time falls back to the default kernel for that call, and after three refusals for good.
`hip_prefill_rocblas_gemm` (with `STRATA_ROCBLAS_TUNING` set) is the smoke test.
+2 -1
View File
@@ -10,7 +10,7 @@ debugging and are kept in `terminal/data/settings-register.json`.
A number or a word is set like any environment variable, for example `STRATA_KVA=1`. In the Terminal, `strata launch --set NAME=value`
puts it in the model's run configuration.
## Switches you can turn on (271)
## Switches you can turn on (272)
Off unless you set them. The last column says where each one is described.
@@ -90,6 +90,7 @@ Off unless you set them. The last column says where each one is described.
| `STRATA_HOST_CORE` | on / off | NVIDIA and AMD, Intel Arc | [DETAILS.md](DETAILS.md) |
| `STRATA_HY4_TAIL_SKIP` | number | NVIDIA and AMD | - |
| `STRATA_I8_DBG` | number | Intel Arc | [INTEL_INT8_EXPERTS.md](INTEL_INT8_EXPERTS.md) |
| `STRATA_I8_DEFER` | on / off | NVIDIA and AMD | - |
| `STRATA_I8_GRF` | number | Intel Arc | [INTEL_INT8_EXPERTS.md](INTEL_INT8_EXPERTS.md) |
| `STRATA_I8_MT` | number | Intel Arc | [INTEL_INT8_EXPERTS.md](INTEL_INT8_EXPERTS.md) |
| `STRATA_I8_WG` | number | Intel Arc | [INTEL_INT8_EXPERTS.md](INTEL_INT8_EXPERTS.md) |
@@ -111,6 +111,7 @@ void kv_unstage_to_host(const QsaAttnPools& stage, const KvHostPools& host, int
struct KvStreamCounters {
uint64_t misses = 0, lookups = 0, calls = 0;
bool overflow = false;
uint32_t overflow_count = 0;
};
/// Synchronous read of the counters (debug and the end-of-request summary).
KvStreamCounters kv_stream_counters(const KvStreamMap& m);
+181
View File
@@ -5,8 +5,11 @@
#include "conversation_trace.hpp"
#include <cuda_runtime.h>
#include <algorithm>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <cstdio>
#include <cstdlib>
#include <cstring>
@@ -14,6 +17,8 @@
#include <limits>
#include <memory>
#include <mutex>
#include <thread>
#include <vector>
namespace strata::core {
namespace {
@@ -265,6 +270,126 @@ bool transfer(void* dst, const void* src, size_t n, std::string& error) {
error = std::string("conversation snapshot copy: ") + cudaGetErrorString(e);
return false;
}
// STRATA_PARK_HOST_MEMCPY=1 (opt-in, default OFF): for kv_mode != 0 (streamed/draft-ring K/V whose parts 0..3 live
// in pinned host memory st.host.*), use resize_for_overwrite() and multi-threaded host std::memcpy instead of
// zero-filling resize() plus per-segment synchronous CUDA/WDDM copy calls.
bool park_host_memcpy_on() {
static const bool on = [] {
const char* v = std::getenv("STRATA_PARK_HOST_MEMCPY");
return v != nullptr && v[0] != '\0' && v[0] != '0';
}();
return on;
}
int park_copy_threads() {
static const int n = [] {
const char* v = std::getenv("STRATA_PARK_COPY_THREADS");
const int parsed = v != nullptr ? std::atoi(v) : 8;
return std::max(1, std::min(16, parsed > 0 ? parsed : 8));
}();
return n;
}
struct HostCopySpan {
uint8_t* dst;
const uint8_t* src;
size_t n;
};
// Persistent worker pool for parallel host-to-host K/V copies (leaked intentionally on process exit so Windows CRT
// teardown never deadlocks on parked threads; 0% CPU while idle).
class HostCopyPool {
public:
explicit HostCopyPool(int total_threads) : n_workers_(std::max(0, total_threads - 1)) {
workers_.reserve((size_t) n_workers_);
for (int i = 0; i < n_workers_; ++i) {
workers_.emplace_back([this] {
conversation_detail::background_thread_placement();
uint64_t seen = 0;
for (;;) {
const std::vector<HostCopySpan>* tasks = nullptr;
{
std::unique_lock<std::mutex> lk(mu_);
cv_start_.wait(lk, [&] { return gen_ != seen; });
seen = gen_;
tasks = cur_tasks_;
}
if (tasks != nullptr) drain(*tasks);
if (remaining_.fetch_sub(1, std::memory_order_acq_rel) == 1) {
std::lock_guard<std::mutex> lk(mu_);
cv_done_.notify_one();
}
}
});
}
}
void run(const std::vector<HostCopySpan>& tasks) {
if (tasks.empty()) return;
if (n_workers_ <= 0 || tasks.size() <= 1) {
for (const auto& t : tasks) {
std::memcpy(t.dst, t.src, t.n);
core::progress_beat();
}
return;
}
std::lock_guard<std::mutex> run_lk(run_mu_);
{
std::lock_guard<std::mutex> lk(mu_);
cur_tasks_ = &tasks;
next_idx_.store(0, std::memory_order_relaxed);
remaining_.store(n_workers_, std::memory_order_release);
++gen_;
}
cv_start_.notify_all();
drain(tasks);
std::unique_lock<std::mutex> lk(mu_);
cv_done_.wait(lk, [&] { return remaining_.load(std::memory_order_acquire) == 0; });
cur_tasks_ = nullptr;
}
private:
void drain(const std::vector<HostCopySpan>& tasks) {
const size_t total = tasks.size();
for (;;) {
const size_t idx = next_idx_.fetch_add(1, std::memory_order_relaxed);
if (idx >= total) return;
const HostCopySpan& t = tasks[idx];
std::memcpy(t.dst, t.src, t.n);
core::progress_beat();
}
}
int n_workers_ = 0;
std::mutex run_mu_;
std::mutex mu_;
std::condition_variable cv_start_;
std::condition_variable cv_done_;
uint64_t gen_ = 0;
const std::vector<HostCopySpan>* cur_tasks_ = nullptr;
std::atomic<size_t> next_idx_{0};
std::atomic<int> remaining_{0};
std::vector<std::thread> workers_;
};
void parallel_host_memcpy(const std::vector<HostCopySpan>& spans) {
if (spans.empty()) return;
static HostCopyPool* pool = new HostCopyPool(park_copy_threads());
constexpr size_t kChunk = (size_t) 4 << 20; // 4 MiB sub-spans for even thread load balancing
std::vector<HostCopySpan> chunks;
chunks.reserve(spans.size() * 2);
for (const auto& s : spans) {
if (s.n == 0) continue;
size_t off = 0;
while (off < s.n) {
const size_t piece = std::min(kChunk, s.n - off);
chunks.push_back({s.dst + off, s.src + off, piece});
off += piece;
}
}
pool->run(chunks);
}
} // namespace
bool conversation_kv_capture_bytes(const ConversationKv& image, const QsaState& st, const ModelGeometry& g,
@@ -313,12 +438,31 @@ bool conversation_kv_save(ConversationKv& image, const QsaState& st, const Model
const std::array<ConversationBuffer*,5> dst = {&image.k, &image.v, &image.k_scale, &image.v_scale, &image.pooled};
// STRATA_PARK_VRAM_MIB: this layer's parts go into the park's slot under a fresh tag (0: no slot this park)
image.dev_tag = park_async().slot != nullptr ? vram_kv().next_tag++ : 0;
const bool fast_host = park_host_memcpy_on() && st.kv_mode != 0;
std::vector<HostCopySpan> host_spans;
for (size_t i = 0; i < dst.size(); ++i) {
// Recopy the partial page and the indexer's moving spare row. Completed
// pages/rows strictly before the first rewritten token remain identical.
const size_t keep = i == 4 ? (index ? size_t(unchanged_tokens / strata::kernels::qsa_real_shapes().idx_block) * g.idx_key_dim * 4 : 0)
: l.cells ? (sizes[i] / size_t(l.cells)) * size_t(whole_cells) : 0;
if (keep > dst[i]->size()) { error = "conversation snapshot: missing reusable prefix"; return false; }
if (fast_host && i < 4) {
if (sizes[i] > keep && src[i] == nullptr) { error = "conversation snapshot: missing state buffer"; return false; }
const bool trace = park_trace_on();
const auto t1 = trace ? std::chrono::steady_clock::now() : std::chrono::steady_clock::time_point{};
const long rf0 = trace ? conversation_trace::thread_minflt() : 0;
dst[i]->resize_for_overwrite(sizes[i]);
if (trace) {
kv_save_trace().resize += std::chrono::duration<double, std::milli>(std::chrono::steady_clock::now() - t1).count();
kv_save_trace().resize_faults += conversation_trace::thread_minflt() - rf0;
}
if (sizes[i] > keep && !dst[i]->visit(keep, sizes[i] - keep, [&](uint8_t* p, size_t n, size_t at) {
host_spans.push_back({p, static_cast<const uint8_t*>(src[i]) + at, n});
return true;
})) return false;
if (reused_bytes) *reused_bytes += keep;
continue;
}
{ // STRATA_PARK_VRAM_MIB: with a slot, the whole part goes device to device into it (a restore of this image
// reads it from there) and the host buffer gets only the bytes past the kept prefix, read from the slot on
// the background thread; a part the slot cannot take is copied synchronously - never through the stage,
@@ -381,6 +525,13 @@ bool conversation_kv_save(ConversationKv& image, const QsaState& st, const Model
if (!copied) return false;
if (reused_bytes) *reused_bytes += keep;
}
if (!host_spans.empty()) {
const bool trace = park_trace_on();
const auto tc0 = trace ? std::chrono::steady_clock::now() : std::chrono::steady_clock::time_point{};
parallel_host_memcpy(host_spans);
if (trace)
kv_save_trace().copy += std::chrono::duration<double, std::milli>(std::chrono::steady_clock::now() - tc0).count();
}
return true;
}
@@ -526,6 +677,21 @@ bool conversation_kv_restore(const ConversationKv& image, const QsaState& st, co
if (!transfer(dst[i], static_cast<const uint8_t*>(slot->p) + off[i], sizes[i], error)) return false;
return refresh_residency(st, g, upto, error);
}
if (park_host_memcpy_on() && st.kv_mode != 0) {
std::vector<HostCopySpan> host_spans;
for (size_t i = 0; i < 4; ++i) {
if (src[i]->size() > 0 && !dst[i]) { error = "conversation snapshot: missing state buffer"; return false; }
if (!src[i]->visit(0, src[i]->size(), [&](const uint8_t* p, size_t n, size_t at) {
host_spans.push_back({static_cast<uint8_t*>(dst[i]) + at, p, n});
return true;
})) return false;
}
parallel_host_memcpy(host_spans);
if (!src[4]->visit(0, src[4]->size(), [&](const uint8_t* p, size_t n, size_t at) {
return transfer(static_cast<uint8_t*>(dst[4]) + at, p, n, error);
})) return false;
return refresh_residency(st, g, upto, error);
}
for (size_t i = 0; i < src.size(); ++i)
if (!src[i]->visit(0, src[i]->size(), [&](const uint8_t* p, size_t n, size_t at) {
return transfer(static_cast<uint8_t*>(dst[i]) + at, p, n, error);
@@ -557,6 +723,21 @@ bool conversation_kv_restore_prefix(const ConversationKv& image, const QsaState&
if (!transfer(dst[i], static_cast<const uint8_t*>(slot->p) + off[i], sizes[i], error)) return false;
return refresh_residency(st, g, upto, error);
}
if (park_host_memcpy_on() && st.kv_mode != 0) {
std::vector<HostCopySpan> host_spans;
for (size_t i = 0; i < 4; ++i) {
if (sizes[i] > 0 && !dst[i]) { error = "conversation snapshot: missing state buffer"; return false; }
if (!src[i]->visit(0, sizes[i], [&](const uint8_t* p, size_t n, size_t at) {
host_spans.push_back({static_cast<uint8_t*>(dst[i]) + at, p, n});
return true;
})) return false;
}
parallel_host_memcpy(host_spans);
if (!src[4]->visit(0, sizes[4], [&](const uint8_t* p, size_t n, size_t at) {
return transfer(static_cast<uint8_t*>(dst[4]) + at, p, n, error);
})) return false;
return refresh_residency(st, g, upto, error);
}
for (size_t i = 0; i < src.size(); ++i)
if (!src[i]->visit(0, sizes[i], [&](const uint8_t* p, size_t n, size_t at) {
return transfer(static_cast<uint8_t*>(dst[i]) + at, p, n, error);
+12 -3
View File
@@ -620,10 +620,19 @@ bool conversation_snapshot_save(SavedConversation& image, const ConversationView
if (!live_saved) return false;
const auto p3 = now();
const int64_t upto = (int64_t) view.ids.size();
// STRATA_PARK_ASYNC: the K/V bytes these saves copy (the stage they need; an over-estimate by the kept prefix)
// STRATA_PARK_ASYNC / STRATA_PARK_VRAM_MIB: size the VRAM stage by device-resident bytes only.
// Under streamed KV (kv_mode != 0), parts 0..3 live in st.host.* and are never staged in VRAM;
// only part 4 (idx_pooled, or 0 for the draft layer) is device-resident, avoiding ~9x VRAM over-reservation.
size_t kv_need = 0;
for (size_t j = 0; j < layers; ++j) kv_need += conversation_kv_bytes(owned(ss, j), g, upto, true);
if (draft) kv_need += conversation_kv_bytes(*draft, g, upto, false);
auto stage_bytes = [&](const QsaState& q, bool idx) -> size_t {
if (q.kv_mode == 0) return conversation_kv_bytes(q, g, upto, idx);
std::array<uint64_t, 5> parts{};
std::string ignore;
if (conversation_kv_part_sizes(q, g, upto, idx, parts, ignore)) return (size_t) parts[4];
return conversation_kv_bytes(q, g, upto, idx);
};
for (size_t j = 0; j < layers; ++j) kv_need += stage_bytes(owned(ss, j), true);
if (draft) kv_need += stage_bytes(*draft, false);
const bool staged = conversation_park_async_begin(kv_need);
const auto p4 = now();
struct Abandon { bool on; ~Abandon() { if (on) conversation_park_async_abandon(); } } abandon{staged};
+190 -5
View File
@@ -37,6 +37,8 @@
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
#include <chrono> // the STRATA_NUMA_ARENA=1 slice placement's timing (Windows only)
#include "strata/kernels/cpu/expert_layout.hpp" // its per-role slice geometry
#else
#include <fcntl.h>
#include <sys/mman.h>
@@ -142,12 +144,19 @@ uint64_t free_huge_bytes() {
}
#endif
#if defined(_WIN32)
// defined below (the Windows STRATA_NUMA_ARENA=1 slice placement): whether the placement can run on this host and
// pack - reserve() checks it before giving up large pages, so a host or pack it cannot serve keeps them.
bool numa_arena_usable(uint64_t bytes);
#endif
// A 2 MB-aligned reservation. Large pages first, then the largest alignment the OS will give us for free.
// A non-empty shared_file instead maps one file whose first 4 KiB identify the pack and whose remaining bytes
// are the resident arena. This shared-file layout is intended for tmpfs (/dev/shm); hugetlbfs would need
// hugepage-aligned file size and arena offset rather than the 4 KiB header layout used here.
void* reserve(uint64_t bytes, PageBacking& got, std::string& note, const std::string& shared_file,
uint64_t shared_pack_hash, void*& mapping_base, uint64_t& mapping_bytes) {
uint64_t shared_pack_hash, void*& mapping_base, uint64_t& mapping_bytes,
bool numa_placeable) {
mapping_base = nullptr;
mapping_bytes = 0;
@@ -271,7 +280,12 @@ void* reserve(uint64_t bytes, PageBacking& got, std::string& note, const std::st
// fails with ERROR_PRIVILEGE_NOT_HELD. That is the EXPECTED outcome on a desktop, not an error.
SIZE_T large = GetLargePageMinimum();
// A/B switch: STRATA_NO_LARGEPAGES=1 skips the large-page attempt, same run, same boot.
if (large > 0 && std::getenv("STRATA_NO_LARGEPAGES") == nullptr) {
// STRATA_NUMA_ARENA=1 skips it too - but only when the slice placement can actually run (the switch set, a
// native layout it can place, two NUMA nodes): a 2 MB large page cannot split a role across sockets (a
// [gate | up | down] role is ~512-614 KiB), so per-slice placement needs 4 KB pages - the same reason the
// Linux twin asks for MADV_NOHUGEPAGE. A host or pack the placement cannot serve keeps its large pages.
const bool numa_arena = numa_placeable && numa_arena_usable(bytes);
if (large > 0 && std::getenv("STRATA_NO_LARGEPAGES") == nullptr && !numa_arena) {
// MEM_LARGE_PAGES requires the allocation size to be an exact multiple of the large page size -
// anything else is ERROR_INVALID_PARAMETER (87), which reads like a privilege problem but is not.
// Round up: the slack is under 2 MB and the tail stays unused.
@@ -288,6 +302,8 @@ void* reserve(uint64_t bytes, PageBacking& got, std::string& note, const std::st
note = "large pages refused for " + std::to_string((unsigned long long) lbytes) + " B (GetLargePageMinimum=" +
std::to_string((unsigned long long) large) + ", VirtualAlloc error " +
std::to_string((unsigned long long) GetLastError()) + "); using 4 KB pages";
} else if (numa_arena) {
note = "large pages skipped (STRATA_NUMA_ARENA=1); using 4 KB pages";
} else if (std::getenv("STRATA_NO_LARGEPAGES") != nullptr) {
note = "large pages skipped (STRATA_NO_LARGEPAGES); using 4 KB pages";
} else {
@@ -732,6 +748,158 @@ void release_alias_claims(std::vector<void*>& claims) {
claims.clear();
}
#if defined(_WIN32)
// node -> GROUP_AFFINITY for nodes 0 and 1 (the only shape the slice placement serves; a host with more
// nodes gets its note saying only 0 and 1 were placed). GetLogicalProcessorInformationEx(RelationNumaNode) is the documented
// form; this SDK's NUMA_NODE_RELATIONSHIP names the affinity GroupMask (a GroupCount + GroupMask/GroupMasks union)
// and every layout of the struct keeps it at the same offset, so GroupMask reads across SDK generations. The older
// GetNumaNodeProcessorMaskEx is not used: on Win10 19044 it writes a bare GROUP_AFFINITY per node (observed), which
// reads back as garbage through the documented struct. A node spanning several processor groups reports its first
// group only; the touchers still run on that node's cores, which is what first-touch needs.
struct NumaWinTopology {
GROUP_AFFINITY ga[2];
bool two_nodes = false;
int nodes_seen = 0; // RelationNumaNode entries of this host (0 and 1 are the ones placed)
};
NumaWinTopology numa_win_topology() {
NumaWinTopology topo;
DWORD need = 0;
std::vector<char> buf;
bool ok = false;
for (int attempt = 0; attempt < 3 && !ok; ++attempt) {
ok = GetLogicalProcessorInformationEx(RelationNumaNode,
reinterpret_cast<PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX>(
buf.empty() ? nullptr : buf.data()), &need) != 0;
if (!ok) {
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER || need == 0) return topo;
buf.resize(need);
}
}
if (!ok || buf.empty()) return topo;
bool filled[2] = {false, false};
for (DWORD at = 0; at < need; ) {
auto* it = reinterpret_cast<SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX*>(buf.data() + at);
if (it->Size == 0 || at + it->Size > need) break;
if (it->Relationship == RelationNumaNode) {
++topo.nodes_seen;
const DWORD n = it->NumaNode.NodeNumber; // file by NodeNumber: the entry order is not defined
if (n < 2 && it->NumaNode.GroupMask.Mask != 0) {
topo.ga[n] = it->NumaNode.GroupMask;
filled[n] = true;
}
}
at += it->Size;
}
topo.two_nodes = filled[0] && filled[1];
return topo;
}
// STRATA_NUMA_ARENA=1 (the env the Linux slice placement of #6529 uses; the code paths are OS-disjoint): whether
// the placement can run here - the switch set, a native layout it knows how to place, and two NUMA nodes. Every
// cost the switch carries (the large-page skip in reserve(), the 4 KB touch below) checks this, so a host or a
// pack the placement cannot serve keeps its default path, large pages included.
bool numa_arena_usable(uint64_t bytes) {
const char* env = std::getenv("STRATA_NUMA_ARENA");
if (env == nullptr || env[0] != '1' || bytes == 0) return false;
const auto& lay = strata::kernels::cpu::expert_layout();
return lay.native && lay.n_layers > 0 && lay.n_expert > 0 && lay.fmt.size() == (size_t) lay.n_layers &&
lay.total <= bytes && numa_win_topology().two_nodes;
}
// STRATA_NUMA_ARENA=1, the Windows twin of the Linux slice placement (#6529, from the Windows evidence in
// Niko1221/Strata#6023 and mw00/project-maya#56): place Slice 0 and Slice 1 of every expert's [gate | up | down]
// roles on NUMA nodes 0 and 1 BEFORE cudaHostRegister pins the pages. Windows has no madvise/mempolicy; the
// mechanism is the documented first-touch preference (a demand-zero page prefers the node of the CPU that faults
// it, falling back to another node when that one runs out), reached through processor groups: SetThreadAffinityMask
// cannot address a second group (36+36 logical CPUs make two on the measurement host), and the #56-era "first-touch
// does not follow the touching thread" measurement was its pin masks collapsing into group 0 through exactly that
// plus a wrong struct marshal. Measured on 2x E5-2696 v3, Win10 19044 (#6023, 2026-11-22): placement follows the
// touching thread at run granularity >= 128 KB (128 KB / 256 KB / 512 KB alternating blocks and contiguous halves
// all land ~50/50 on a QueryWorkingSetEx scan, preserved through cudaHostRegister Portable|Mapped), below that the
// first 2 MB follow it and the rest collapses onto one node. The per-role halves this function touches are
// ~256-307 KB, inside the working zone; 8 workers a node saturate the fault path (a 56.2 GiB arena places in 15 s).
// Commit shape does not matter (one-shot commit, per-page VirtualAllocExNuma: identical distributions), so
// reserve()'s allocation stays exactly as it is.
//
// Called from the first constructor and the Deferred one, whose arenas use the packed expert layout
// expert_layout().blob_offset. The ByNeed constructor is NOT called: pin-by-need pads every blob to a 4 KiB
// stride (ArenaExpertSource's PadMap, so any set of blobs can register exactly) and moves the destination
// offsets - placing the packed layout there would misplace every blob after the first one.
void place_arena_numa_slices_win(void* base, uint64_t bytes, std::string& note) {
const char* env = std::getenv("STRATA_NUMA_ARENA");
if (env == nullptr || env[0] != '1' || base == nullptr || bytes == 0) return;
const auto& lay = strata::kernels::cpu::expert_layout();
if (!lay.native || lay.n_layers <= 0 || lay.n_expert <= 0 || lay.fmt.size() != (size_t) lay.n_layers ||
lay.total > bytes) {
note += "; STRATA_NUMA_ARENA=1: the pack layout is not one this placement can serve (native expert blobs "
"required), the switch was ignored";
return;
}
const NumaWinTopology topo = numa_win_topology();
if (!topo.two_nodes) {
note += "; STRATA_NUMA_ARENA=1: one NUMA node (or the topology query failed), slice placement not needed";
return;
}
const char* extra_nodes = topo.nodes_seen > 2 ? "; more nodes seen, 0 and 1 placed" : "";
const auto t0 = std::chrono::steady_clock::now();
constexpr int kWorkersPerNode = 8;
constexpr uint64_t kPage = 4096;
std::atomic<int> pin_failures = 0; // touchers that could not be pinned to their node's group
std::vector<std::thread> th;
th.reserve(2 * kWorkersPerNode);
bool spawned_all = true;
for (int k = 0; k < 2 && spawned_all; ++k) {
for (int w = 0; w < kWorkersPerNode && spawned_all; ++w) {
try {
th.emplace_back([base, &lay, k, w, &topo, &pin_failures]() {
if (!SetThreadGroupAffinity(GetCurrentThread(), &topo.ga[(size_t) k], nullptr))
++pin_failures;
// the same page math as the Linux twin: within each role, the page-aligned first half is
// slice 0 (node 0) and the second half is slice 1 (node 1); a role's halves are ~256-307 KB
for (int64_t l = w; l < lay.n_layers; l += kWorkersPerNode) {
const auto& fm = lay.fmt[(size_t) l];
const uint64_t blob = lay.blob_bytes(l);
const uint64_t per[3] = {fm.up_off, fm.down_off - fm.up_off, blob - fm.down_off};
for (int64_t e = 0; e < lay.n_expert; ++e) {
uint64_t start = lay.blob_offset(l, e);
for (int r = 0; r < 3; ++r) {
const uint64_t mid = start + per[r] / 2, end = start + per[r];
const uint64_t lo = k == 0 ? (start & ~(kPage - 1)) : ((mid + kPage - 1) & ~(kPage - 1));
const uint64_t hi = k == 0 ? ((mid + kPage - 1) & ~(kPage - 1)) : (end & ~(kPage - 1));
for (uint64_t at = lo; at < hi; at += kPage)
((volatile uint8_t*) base)[at] = 0;
start = end;
}
}
}
});
} catch (const std::exception&) { // a worker could not start: join what exists and say the placement is partial
spawned_all = false;
}
}
}
for (auto& t : th) t.join();
// Touch the trailing spare blob so the entire arena is faulted before cudaHostRegister (a few pages, touched
// from the calling thread: far below the placement's own measurement noise)
for (uint64_t at = lay.total & ~(kPage - 1); at < bytes; at += kPage)
((volatile uint8_t*) base)[at] = 0;
const double secs = std::chrono::duration<double>(std::chrono::steady_clock::now() - t0).count();
char msg[288];
const int failures = pin_failures.load(std::memory_order_relaxed);
if (!spawned_all || failures != 0)
std::snprintf(msg, sizeof msg,
"; STRATA_NUMA_ARENA=1: WARNING: slice placement partial (%d toucher(s) off-node%s); "
"the pages the missing workers own stay unpinned", failures,
spawned_all ? "" : "; a worker could not start");
else
std::snprintf(msg, sizeof msg,
"; NUMA slice-placed (STRATA_NUMA_ARENA=1: slice 0 -> node 0, slice 1 -> node 1 in %.2f s%s)", secs,
extra_nodes);
note += msg;
}
#endif
// pin_register for the arena's ranges. Windows HIP: a range whose GPU alias covers memory in use is unregistered again and
// reported as refused, so the caller's "the driver refused it" path applies to it (#3431).
#if defined(__linux__)
@@ -786,7 +954,8 @@ PinnedArena::PinnedArena(uint64_t bytes, const std::vector<uint64_t>& bounds,
uint64_t max_pinned_bytes, const std::string& shared_file,
uint64_t shared_pack_hash) : capacity(bytes) {
if (bytes == 0) return;
base = reserve(bytes, backing, note, shared_file, shared_pack_hash, mapping_base, mapping_bytes);
base = reserve(bytes, backing, note, shared_file, shared_pack_hash, mapping_base, mapping_bytes,
/*numa_placeable=*/true);
if (!shared_file.empty() && base != nullptr && mapping_base != nullptr)
shared_state = reinterpret_cast<std::atomic<uint64_t>*>(static_cast<char*>(mapping_base) +
offsetof(SharedArenaHeader, reserved));
@@ -795,6 +964,13 @@ PinnedArena::PinnedArena(uint64_t bytes, const std::vector<uint64_t>& bounds,
mapping_bytes = bytes;
}
#if defined(_WIN32)
// STRATA_NUMA_ARENA=1 places the slices first: the twin touches every page from node-pinned threads, so the
// pages are resident when they register - the cost the comment below warns about, measured at ~90 ms per
// 512 MB in the M1 prototype; a partial tier pays it once at start and buys per-slice node locality for it.
if (base && shared_state == nullptr && backing == PageBacking::NormalPages)
place_arena_numa_slices_win(base, bytes, note);
#endif
// Register with CUDA BEFORE any page is touched: cudaHostRegister pins what is resident now, and a region
// that has already been faulted in page by page is far more expensive to register and may fail outright.
if (base && arena_no_register()) {
@@ -923,7 +1099,8 @@ PinnedArena::PinnedArena(uint64_t bytes, ByNeed, const std::vector<std::pair<uin
uint64_t shared_pack_hash) : capacity(bytes) {
by_need = true;
if (bytes == 0) return;
base = reserve(bytes, backing, note, shared_file, shared_pack_hash, mapping_base, mapping_bytes);
base = reserve(bytes, backing, note, shared_file, shared_pack_hash, mapping_base, mapping_bytes,
/*numa_placeable=*/false);
if (!shared_file.empty() && base != nullptr && mapping_base != nullptr)
shared_state = reinterpret_cast<std::atomic<uint64_t>*>(static_cast<char*>(mapping_base) +
offsetof(SharedArenaHeader, reserved));
@@ -932,6 +1109,7 @@ PinnedArena::PinnedArena(uint64_t bytes, ByNeed, const std::vector<std::pair<uin
mapping_bytes = bytes;
}
if (base == nullptr) return;
// (No slice placement here: the ByNeed arena may be padded per blob - see place_arena_numa_slices_win.)
// Register BEFORE any page is touched (see the first constructor). Same caps as there: the engine's
// `max_pinned_bytes`, else STRATA_ARENA_PIN_GIB=N (> 0); "auto" (-2) is the sliced pin's and does not apply.
const int env_gib = arena_pin_cap_gib();
@@ -1016,11 +1194,18 @@ PinnedArena::PinnedArena(uint64_t bytes, ByNeed, const std::vector<std::pair<uin
PinnedArena::PinnedArena(uint64_t bytes, const std::vector<uint64_t>& bounds, Deferred)
: capacity(bytes), bounds_(bounds) {
if (bytes == 0 || bounds.size() < 2) return;
base = reserve(bytes, backing, note, std::string{}, 0, mapping_base, mapping_bytes);
base = reserve(bytes, backing, note, std::string{}, 0, mapping_base, mapping_bytes,
/*numa_placeable=*/true);
if (base != nullptr && mapping_base == nullptr) {
mapping_base = base;
mapping_bytes = bytes;
}
#if defined(_WIN32)
// Slice placement before the per-layer registration pipeline faults anything (see the first constructor).
// No shared_state check: this constructor takes no shared file, the arena is always process-private.
if (base && backing == PageBacking::NormalPages)
place_arena_numa_slices_win(base, bytes, note);
#endif
slice_bytes = 1; // sliced: one registration per layer
}
+2 -1
View File
@@ -156,7 +156,7 @@ __global__ void __launch_bounds__(RT) resolve_kernel(KvStreamMap m, const int32_
m.ctl[0] = epoch;
m.ctl[1] = hand;
m.ctl[2] = placed;
if (placed < need) m.ctl[3] = 1;
if (placed < need) m.ctl[3] += 1;
unsigned long long* c = reinterpret_cast<unsigned long long*>(m.ctl + 4);
c[0] += (unsigned long long) placed;
c[1] += (unsigned long long) s_lookups;
@@ -280,6 +280,7 @@ KvStreamCounters kv_stream_counters(const KvStreamMap& m) {
r.lookups = u[1];
r.calls = u[2];
r.overflow = c[3] != 0;
r.overflow_count = (uint32_t) c[3];
return r;
}
+7 -7
View File
@@ -172,7 +172,7 @@ __global__ void __launch_bounds__(THREADS) prompt_attn_kernel(const float* __res
if (c >= min(CH, n - c0)) return -1;
const int cell = ids[c0 + c];
const long long page = (long long) p.page_table[cell / page_size];
return (page * n_kv_heads + kvh) * page_size + (cell % page_size);
return page >= 0 ? (page * n_kv_heads + kvh) * page_size + (cell % page_size) : -1;
};
auto fetch = [&](int c0) {
if constexpr (PREFETCH) {
@@ -209,7 +209,7 @@ __global__ void __launch_bounds__(THREADS) prompt_attn_kernel(const float* __res
if (t < nh) {
const int cell = ids[c0 + t];
const long long page = (long long) p.page_table[cell / page_size];
r = (page * n_kv_heads + kvh) * page_size + (cell % page_size);
if (page >= 0) r = (page * n_kv_heads + kvh) * page_size + (cell % page_size);
}
S.row[t] = r;
}
@@ -601,7 +601,7 @@ __global__ void __launch_bounds__(THREADS) prompt_attn_i8_kernel(const float* __
auto row_of = [&](int cell) -> long long {
if (cell < 0) return -1;
const long long page = (long long) __ldg(p.page_table + cell / page_size);
return (page * n_kv_heads + kvh) * page_size + (cell % page_size);
return page >= 0 ? (page * n_kv_heads + kvh) * page_size + (cell % page_size) : -1;
};
#if !STRATA_PA_SM80
// Turing (no cp.async): the warp's next pieces wait in registers and are stored into their stage after this
@@ -864,7 +864,7 @@ __global__ void __launch_bounds__(THREADS) decode_attn_i8_split_kernel(const flo
auto row_of = [&](int cell) -> long long {
if (cell < 0) return -1;
const long long page = (long long) __ldg(p.page_table + cell / page_size);
return (page * n_kv_heads + kvh) * page_size + (cell % page_size);
return page >= 0 ? (page * n_kv_heads + kvh) * page_size + (cell % page_size) : -1;
};
auto issue = [&](long long r, int st, float& ksr, float& vsr) {
#pragma unroll
@@ -1216,7 +1216,7 @@ __global__ void __launch_bounds__(THREADS, 3) prompt_attn_i8v3_kernel(const floa
auto row_of = [&](int cell) -> long long {
if (cell < 0) return -1;
const long long page = (long long) __ldg(p.page_table + cell / page_size);
return (page * n_kv_heads + kvh) * page_size + (cell % page_size);
return page >= 0 ? (page * n_kv_heads + kvh) * page_size + (cell % page_size) : -1;
};
// this warp's 64-dim slice of K (kv = 0) or V (1) of the chunk whose rows the lanes hold, and the cells' scales
auto issue = [&](long long r, int kv) {
@@ -1572,7 +1572,7 @@ __global__ void __launch_bounds__(THREADS) prompt_attn_v70_kernel(const float* _
if (t < min(CH, n)) {
const int cell = ids[t];
const long long page = (long long) p.page_table[cell / page_size];
r = (page * n_kv_heads + kvh) * page_size + (cell % page_size);
if (page >= 0) r = (page * n_kv_heads + kvh) * page_size + (cell % page_size);
}
S.row[0][t] = r;
}
@@ -1819,7 +1819,7 @@ __global__ void __launch_bounds__(THREADS) prompt_attn_v70_kernel(const float* _
if (idx < n) {
const int cell = ids[idx];
const long long page = (long long) p.page_table[cell / page_size];
r = (page * n_kv_heads + kvh) * page_size + (cell % page_size);
if (page >= 0) r = (page * n_kv_heads + kvh) * page_size + (cell % page_size);
}
S.row[rbuf ^ 1][t] = r;
}
+1 -1
View File
@@ -209,7 +209,7 @@ bool run(int fmt) {
std::printf(" %s: %d batches, %llu block lookups, %llu misses (%.1f%% hit), overflow %d, %d failures\n",
name, batches, (unsigned long long) c.lookups, (unsigned long long) c.misses,
c.lookups ? 100.0 * (double) (c.lookups - c.misses) / (double) c.lookups : 0.0, (int) c.overflow, bad);
if (c.overflow || c.calls != (uint64_t) batches || c.misses == 0 || c.misses >= c.lookups) ++bad;
if (c.overflow || c.overflow_count != 0 || c.calls != (uint64_t) batches || c.misses == 0 || c.misses >= c.lookups) ++bad;
// 4. a ring over the same host copy: blocks [b1 - R, b1) restored, read through `b % R`
{
+16 -2
View File
@@ -4927,7 +4927,9 @@ bool Prefill::run_impl(const int64_t* tokens, int64_t n, int64_t pos0, std::stri
});
cudaStreamWaitEvent(m.cs, m.copied[r % (size_t) m.ring], 0);
};
size_t given_upto = 0; // STRATA_I8_DEFER: the last count handed back to the stager
auto give_back = [&](size_t upto) {
given_upto = upto;
if (threaded_issue) a_consumed.store(upto, std::memory_order_release);
else issue_until(upto + (size_t) m.ring);
};
@@ -7523,14 +7525,26 @@ bool Prefill::run_impl(const int64_t* tokens, int64_t n, int64_t pos0, std::stri
// pick only gives its slot back
size_t k = seq_start[(size_t) l];
const size_t kend = seq_start[(size_t) l + 1];
// STRATA_I8_DEFER=1 (opt-in, the int8 expert groups only): a streamed entry the routing did not pick no longer
// launches the open int8 group early. Without it, every such entry while an int8 group holds ring slots runs the
// experts gathered so far as a launch of their own (MMQ's flush only gathers, its GEMM still waits for the full
// group; the int8 flush IS the launch), so a group of 16 experts is cut into fragments of one or a few experts and
// tens of rows - the int8 kernels' least efficient shape. With it, the entry's own slot gets its event at once and
// the hand-back to the stager waits until the group has launched (the flush records the group's slot events; the
// walk's `gg_nslots == 0 -> give_back(consumed)` then hands back everything up to here), so no slot of the open group
// can be refilled before it is read. The stager is held back by those entries meanwhile: when the entries not yet
// handed back plus a full group would come near the ring, the early launch is kept.
static const bool i8_defer = [] { const char* v = std::getenv("STRATA_I8_DEFER"); return v != nullptr && v[0] == '1'; }();
auto release_to = [&](int32_t e_stop) {
while (k < kend && seq[k].e < e_stop) {
if (gg_nslots > 0) flush(0); // the open group's slots get their event first
const bool defer = i8_defer && i8_l && gg_nslots > 0 &&
(k + 1 - given_upto) + (size_t) strata::prefill::i8grp::kGroupMax + 2 < (size_t) m.ring;
if (gg_nslots > 0 && !defer) flush(0); // the open group's slots get their event first
const int sl = (int) (k % (size_t) m.ring);
cudaEventRecord(m.used[sl], m.cs);
m.used_of[sl] = sl;
consumed = ++k;
give_back(consumed);
if (!defer) give_back(consumed);
}
};
for (size_t j = 0; j < order.size(); ++j) {
+28
View File
@@ -14852,6 +14852,34 @@
"retire_after": "",
"retired_in": ""
},
{
"name": "STRATA_I8_DEFER",
"backends": [
"cuda-hip"
],
"reads": [
{
"file": "engine/src/prefill/prefill.cpp",
"line": 7393,
"backend": "cuda-hip",
"fn": "getenv"
}
],
"parse": "flag",
"default_state": "off",
"code_default": null,
"engine_sets": [],
"engine_defaults": [],
"launch_files": [],
"launch_sets": [],
"launch_reads": [],
"doc_mentions": [],
"status": "opt-in",
"owner": "prefill",
"note": "[reviewed] =1: a streamed prompt entry no token routes to no longer launches the open int8 expert group early (groups were cut into fragments of one or a few experts); the hand-back to the stager waits for the group's launch. Bit-identical output.",
"retire_after": "",
"retired_in": ""
},
{
"name": "STRATA_I8_FEWROWS",
"backends": [
@@ -115,3 +115,71 @@ f16o 1 2560 1 1536 -9 # 0.09308 ms -> 0.0197333 ms
f16o 1 2560 1 2048 -9 # 0.120027 ms -> 0.030653 ms
f16o 1 2560 1 4096 -9 # 0.0734267 ms -> 0.04152 ms
f16o 1 2560 1 8192 -9 # 0.200733 ms -> 0.07284 ms
# 2026-11-22, RX 6900 XT, same rocBLAS build: the buckets 10240 ... 16384 (--prefill 16384 reads chunks up to 16384) for every
# shape the prompt path calls (listed with STRATA_ROCBLAS_VERBOSE=1 over 16K-200K reads), and 48 2560 96 at every bucket:
# ssm_alpha / ssm_beta are written interleaved (ldy 96), so the 48 2560 48 rows above never matched them. At T=16384 rocBLAS's
# own pick for the GDN gate (6144 2560) is MT128x256x8, 25.2 ms against 13.9 ms for the row below; 12288 and 20480 pick well.
f16o 1 2560 1 10240 -9 # 0.207613 ms -> 0.114613 ms
f16o 1 2560 1 12288 -9 # 0.349507 ms -> 0.105293 ms
f16o 1 2560 1 14336 -9 # 0.365147 ms -> 0.121014 ms
f16o 1 2560 1 16384 -9 # 0.349933 ms -> 0.136547 ms
f16o 4 10240 4 10240 -1086327834 # 1.49396 ms -> 0.599867 ms
f16o 4 10240 4 12288 -1086327834 # 1.8236 ms -> 0.72692 ms
f16o 4 10240 4 14336 -1086327815 # 1.86948 ms -> 0.859147 ms
f16o 4 10240 4 16384 -1086327924 # 2.08247 ms -> 1.05399 ms
f16o 128 2560 128 10240 -1086327703 # 0.233693 ms -> 0.205947 ms
f16o 128 2560 128 12288 -1086327917 # 0.349013 ms -> 0.289227 ms
f16o 128 2560 128 14336 default # 0.33104 ms
f16o 128 2560 128 16384 default # 0.353147 ms
f16o 320 10240 320 10240 -1086327703 # 2.68515 ms -> 2.54519 ms
f16o 320 10240 320 12288 default # 3.23423 ms
f16o 320 10240 320 14336 default # 3.84793 ms
f16o 320 10240 320 16384 default # 4.32203 ms
f16o 512 2560 512 10240 -1086327687 # 0.92032 ms -> 0.699653 ms
f16o 512 2560 512 12288 default # 0.860773 ms
f16o 512 2560 512 14336 -1086327687 # 1.18659 ms -> 1.026 ms
f16o 512 2560 512 16384 -1086327703 # 1.39956 ms -> 1.18577 ms
f16o 640 2560 640 10240 default # 0.864947 ms
f16o 640 2560 640 12288 default # 1.03372 ms
f16o 640 2560 640 14336 -1086327719 # 1.44249 ms -> 1.19032 ms
f16o 640 2560 640 16384 -1086327719 # 1.57524 ms -> 1.35812 ms
f16o 2560 2560 2560 10240 default # 3.36056 ms
f16o 2560 2560 2560 12288 default # 4.06392 ms
f16o 2560 2560 2560 14336 -1086327687 # 5.02579 ms -> 4.7636 ms
f16o 2560 6144 2560 10240 default # 9.53862 ms
f16o 2560 6144 2560 12288 default # 12.185 ms
f16o 2560 6144 2560 14336 -1086327719 # 14.868 ms -> 14.0712 ms
f16o 2560 640 2560 10240 default # 0.854066 ms
f16o 2560 640 2560 12288 default # 1.02171 ms
f16o 2560 640 2560 14336 -1086327696 # 1.26467 ms -> 1.18292 ms
f16o 6144 2560 6144 10240 default # 8.16578 ms
f16o 6144 2560 6144 12288 default # 9.76927 ms
f16o 6144 2560 6144 14336 default # 11.3925 ms
f16o 10240 2560 10240 10240 default # 14.4933 ms
f16o 10240 320 10240 10240 default # 1.75059 ms
f16o 10240 320 10240 12288 -1086327687 # 2.63521 ms -> 2.05901 ms
f16o 10240 320 10240 14336 -1086327687 # 3.06869 ms -> 2.3976 ms
f16o 10240 320 10240 16384 -1086327680 # 3.4828 ms -> 2.72188 ms
f16o 12288 2560 12288 10240 default # 17.6302 ms
f16o 12288 2560 12288 12288 default # 21.9707 ms
f16o 12288 2560 12288 14336 default # 26.0242 ms
f16o 12288 2560 12288 16384 default # 30.4385 ms
f16o 48 2560 96 256 -1086327840 # 0.0460133 ms -> 0.02236 ms
f16o 48 2560 96 512 -1086327774 # 0.202107 ms -> 0.0323733 ms
f16o 48 2560 96 768 -1086327779 # 0.108547 ms -> 0.0402533 ms
f16o 48 2560 96 1024 -1086327779 # 0.11068 ms -> 0.0404667 ms
f16o 48 2560 96 1536 -1086327776 # 0.115707 ms -> 0.0511733 ms
f16o 48 2560 96 2048 -1086327779 # 0.126027 ms -> 0.0563067 ms
f16o 48 2560 96 4096 -1086327762 # 0.18452 ms -> 0.101733 ms
f16o 48 2560 96 8192 -1086327762 # 0.20408 ms -> 0.152026 ms
f16o 48 2560 96 10240 -1086327925 # 0.209213 ms -> 0.178866 ms
f16o 48 2560 96 12288 -1086327736 # 0.350173 ms -> 0.211587 ms
f16o 48 2560 96 14336 -1086327736 # 0.369587 ms -> 0.25628 ms
f16o 48 2560 96 16384 -1086327748 # 0.354867 ms -> 0.286427 ms
f16o 6144 2560 6144 16384 -1086327687 # 25.2020 ms -> 13.8942 ms
f16o 2560 6144 2560 16384 default # 16.6432 ms (best 16.1626, under --min-gain)
f16o 2560 2560 2560 16384 default
f16o 2560 640 2560 16384 default # 1.4460 ms
f16o 10240 2560 10240 12288 default # 17.6185 ms (best 18.2214)
f16o 10240 2560 10240 14336 default # 21.1415 ms
f16o 10240 2560 10240 16384 default # 24.6485 ms (best 24.9032)
+12 -8
View File
@@ -14,7 +14,7 @@
// cmake --build build-hip --target tune_rocblas
// ./build-hip/tune_rocblas --tuning-out tools/hip/<arch>-rocblas-<version>.txt
//
// Defaults: the engine's 14 FP16 dense shapes at T = 256 ... 8192 (--tokens); --case T,N,K,ldy adds one shape.
// Defaults: the engine's 14 FP16 dense shapes at T = 256 ... 16384 (--tokens); --case T,N,K,ldy adds one shape.
#define ROCBLAS_BETA_FEATURES_API
#include <hip/hip_runtime.h>
#include <hip/hip_fp16.h>
@@ -50,7 +50,7 @@ struct Buffer {
struct Shape { int t, n, k, ldy; };
struct Options {
std::vector<Shape> shapes;
std::vector<int> tokens{256, 512, 768, 1024, 1536, 2048, 4096, 8192};
std::vector<int> tokens{256, 512, 768, 1024, 1536, 2048, 4096, 8192, 10240, 12288, 14336, 16384};
std::string tuning_out;
double min_gain = 1.05;
bool explicit_shapes = false;
@@ -82,7 +82,7 @@ int positive(const std::string& s, const char* label) {
}
void usage(const char* p) {
std::printf("Usage: %s [--case T,N,K,ldy]... [--tokens T1,T2,...] [--min-gain 1.05] [--tuning-out PATH]\n", p);
std::printf("Defaults: the engine's 14 FP16 dense shapes (ldy = N) at T = 256,512,768,1024,1536,2048,4096,8192.\n");
std::printf("Defaults: the engine's 14 FP16 dense shapes (N K ldy as the engine calls them) at T = 256 ... 16384.\n");
}
Options options(int argc, char** argv) {
Options o;
@@ -108,11 +108,15 @@ Options options(int argc, char** argv) {
}
if (!o.explicit_shapes) {
// Qwen3.8-Flash-Next's dense FP16 products, prompt_f16() on (the hc read, GDN and QSA projections, the router
// and the shared expert), ldy = N for every one of them. N K as the engine calls Gemm (ROCBLAS_LAYER=2).
const int nk[][2] = {{10240, 2560}, {12288, 2560}, {6144, 2560}, {2560, 6144}, {2560, 640}, {2560, 2560},
{640, 2560}, {512, 2560}, {128, 2560}, {48, 2560}, {320, 10240}, {10240, 320},
{4, 10240}, {1, 2560}};
for (const auto& p : nk) for (int t : o.tokens) o.shapes.push_back({t, p[0], p[1], p[0]});
// and the shared expert). N K ldy as the engine calls Gemm (STRATA_ROCBLAS_VERBOSE=1 lists every (T,N,K,ldy) it
// meets): ldy = N except ssm_alpha / ssm_beta, which bf16_proj writes interleaved into one buffer (ldy = 2 * 48 =
// 96) - a table row for 48 2560 48 never matches them. The buckets go to 16384, the chunk `--prefill 16384`
// reads (on gfx1030 rocBLAS's own pick for the GDN gate, N=6144 K=2560, is 1.8x off its best at T=16384 only).
const int nkl[][3] = {{10240, 2560, 10240}, {12288, 2560, 12288}, {6144, 2560, 6144}, {2560, 6144, 2560},
{2560, 640, 2560}, {2560, 2560, 2560}, {640, 2560, 640}, {512, 2560, 512},
{128, 2560, 128}, {48, 2560, 96}, {320, 10240, 320}, {10240, 320, 10240},
{4, 10240, 4}, {1, 2560, 1}};
for (const auto& p : nkl) for (int t : o.tokens) o.shapes.push_back({t, p[0], p[1], p[2]});
}
return o;
}