kv_plan/qsa_state_bytes/host copy sizing equal layer.cpp's own functions (extracted verbatim) over 480 format x context x ring x --kv-resident cases. StreamMap::resolve models the kernel's three phases sequentially; the miss-list order is the only device nondeterminism and is supplied as input. The literal kv_stream.cu text, run with 1024 emulated threads, reproduces the model state after each of 45 calls with constant eviction. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
64 lines
2.9 KiB
C++
64 lines
2.9 KiB
C++
// Golden fixtures for the KV streaming planner: `kv_plan`, `kv_pool_bytes`, `qsa_state_bytes`, `qsa_shapes`,
|
|
// `align_up16` and `qsa_kv_resident_min` of engine/strata/src/core/layer.cpp, included VERBATIM (extracted by
|
|
// gen_stream_golden.sh with awk, never retyped) and driven over a grid of formats, contexts, rings and
|
|
// --kv-resident values. Host-only: no CUDA symbol is needed.
|
|
#include "strata/core/layout.hpp"
|
|
#include "strata/kernels/kv_q4.hpp"
|
|
#include "strata/kernels/kv_q8.hpp"
|
|
#include "strata/kernels/kv_stream.hpp"
|
|
#include "strata/kernels/qsa.hpp"
|
|
|
|
#include <algorithm>
|
|
#include <cstdint>
|
|
#include <cstdio>
|
|
#include <cstdlib>
|
|
#include <vector>
|
|
|
|
namespace strata::core {
|
|
using strata::kernels::QsaShapes;
|
|
int64_t qsa_kv_resident_min();
|
|
#include "fragment_flags.inc"
|
|
namespace {
|
|
#include "fragment_shapes.inc"
|
|
#include "fragment_streaming.inc"
|
|
} // namespace
|
|
#include "fragment_state_bytes.inc"
|
|
#include "fragment_resident_min.inc"
|
|
|
|
void emit() {
|
|
const ModelGeometry g;
|
|
struct Fmt { const char* name; bool without_key, int8, q4, hybrid; } fmts[] = {
|
|
{"fp16", false, false, false, false}, {"int8", false, true, false, false}, {"q4_0", false, false, true, false},
|
|
{"k8v4", false, false, false, true}, {"int8-keyless", true, true, false, false}};
|
|
std::printf("{\"cases\":[");
|
|
bool first = true;
|
|
for (const Fmt& f : fmts)
|
|
for (int64_t max_cells : {4096ll, 32768ll, 262144ll, 524288ll})
|
|
for (int64_t ring : {0ll, 256ll, -1ll})
|
|
for (int64_t resident : {0ll, 1000ll, 20480ll, 65536ll})
|
|
for (int rope = 0; rope < 2; ++rope) {
|
|
g_without_key = f.without_key;
|
|
g_kv_int8 = f.int8;
|
|
g_kv_q4 = f.q4;
|
|
g_kv_hybrid = f.hybrid;
|
|
g_kv_resident = resident;
|
|
const QsaShapes s = qsa_shapes(g);
|
|
const KvPlan p = kv_plan(s, max_cells, ring);
|
|
const uint64_t bytes = qsa_state_bytes(g, max_cells, rope != 0, ring);
|
|
std::printf("%s\n{\"format\":\"%s\",\"max_cells\":%lld,\"ring\":%lld,\"resident\":%lld,\"rope\":%d,"
|
|
"\"mode\":%d,\"pages\":%lld,\"slots\":%lld,\"pooled_rows\":%lld,\"state_bytes\":%llu}",
|
|
first ? "" : ",", f.name, (long long) max_cells, (long long) ring, (long long) resident, rope,
|
|
p.mode, (long long) p.pages, (long long) p.slots, (long long) p.pooled_rows,
|
|
(unsigned long long) bytes);
|
|
first = false;
|
|
}
|
|
std::printf("],\"resident_min\":%lld,\"map_bytes_5120\":%llu}\n", (long long) qsa_kv_resident_min(),
|
|
(unsigned long long) strata::kernels::kv_stream_map_bytes(5120));
|
|
}
|
|
} // namespace strata::core
|
|
|
|
int main() {
|
|
strata::core::emit();
|
|
return 0;
|
|
}
|