Files
leleka/crates/cuda-driver/oracle/drivers/prefill_ring_trace.cpp
T
Pavlo RatushnyiandClaude Sonnet 5.5 465782405c feat(prefill): Prefill::run scheduling model, extracted-C++ golden traces and the prompt scheduler caller
original_prefill_schedule.rs (pure): ring_slots, chunk loop, the expert-stream plan (sequence builder, issue_until/
give_back, streamed and staged walks), PLE read-ahead double buffer, GR write fusion rule, layer-split hand-off, plus a
ring/event simulator that rejects unsafe schedules. gen_prefill_ring_trace.py extracts the Original's scheduling code
verbatim from prefill.cpp into a host harness; its traces are the committed golden fixture the Rust model must match
line for line.

backend_original_prompt.rs gains PromptRunner + drive (the contract between generate.cpp and Prefill::run), and
executor_original_prompt.rs gets OriginalPromptComposer: one PromptPlan Batched action = one executor.forward + publish
transaction. Unselected source owner; verifier windows / final seed / checkpoints go through explicit hooks.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-14 15:26:05 +02:00

464 lines
25 KiB
C++

// GENERATED by oracle/gen_prefill_ring_trace.py from engine/strata/src/prefill/prefill.cpp
// (sha256 1d18288208debcf1d26021ed8bdfc2633db6dcbd88d899c76d1f628b57838c91). The code between the VERBATIM markers is copied from that file (lines 1170-1228, 1279-1287, 1692-1743, 1806-1853);
// everything else stubs the cuda* calls and records them. Issue is inline (STRATA_PREFILL_ISSUER=0): the threaded issuer
// makes the same copy-stream calls in the same order, gated by the same consumed + ring rule.
#include <algorithm>
#include <atomic>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <memory>
#include <thread>
#include <string>
#include <vector>
using cudaStream_t = int;
using cudaEvent_t = int;
enum { cudaMemcpyHostToDevice = 1, cudaSuccess = 0 };
constexpr int STAGE = 8, RING_MAX = 512, DQ = 2;
static std::vector<std::string> g_ops;
static void op(const std::string& s) { g_ops.push_back(s); }
static const char* sname(cudaStream_t s) { return s == 1 ? "C" : "K"; }
static int slot_of_dev(const void* p) { return (int) (((uintptr_t) p - 0x10000000u) / 0x1000u); }
static std::string src_of_host(const void* p) {
const uintptr_t v = (uintptr_t) p;
if (v >= 0x40000000u) return "stage " + std::to_string((v - 0x40000000u) / 0x1000u);
return "blob " + std::to_string((v - 0x20000000u) / 0x10000u) + " " + std::to_string(((v - 0x20000000u) % 0x10000u) / 0x10u);
}
static int cudaMemcpyAsync(void* dst, const void* src, size_t, int, cudaStream_t s) {
op(std::string(sname(s)) + " h2d " + std::to_string(slot_of_dev(dst)) + " " + src_of_host(src));
return 0;
}
static std::string ev_name(cudaEvent_t e) {
if (e >= 4000) return "ple_copied " + std::to_string(e - 4000);
if (e >= 3000) return "dma " + std::to_string(e - 3000);
return (e >= 2000 ? "used " + std::to_string(e - 2000) : "copied " + std::to_string(e - 1000));
}
static int cudaStreamWaitEvent(cudaStream_t s, cudaEvent_t e, unsigned) { op(std::string(sname(s)) + " wait " + ev_name(e)); return 0; }
static int cudaEventRecord(cudaEvent_t e, cudaStream_t s) { op(std::string(sname(s)) + " record " + ev_name(e)); return 0; }
struct Clock { struct time_point {}; static time_point now() { return {}; } };
static double ms_since(Clock::time_point) { return 0.0; }
struct ExpertLayoutStub { size_t blob_bytes(int64_t) const { return 4096; } };
namespace strata { namespace kernels { namespace cpu {
using ExpertLayout = ExpertLayoutStub;
inline const ExpertLayout& expert_layout() { static ExpertLayout l; return l; }
} } }
struct ModelGeom { int64_t n_expert; int64_t n_layers; };
struct Scenario {
const char* name;
int n_layers, n_expert, lb, le, ring, stager_ring;
int64_t T; // rows of the chunk (stream_all needs T >= 1024)
std::vector<std::vector<int32_t>> orders; // per layer in [lb, le): routed experts, ascending
int resident_mod, resident_rem; // cache-resident when e % mod == rem (mod 0: none)
bool cache_present;
int pinned_mod, transient_mod; // pinned: e % pinned_mod == 0; transient: (e+l) % transient_mod == 0
int chunks;
};
static const Scenario* g_sc = nullptr;
struct Src {
bool pinned(int64_t, int64_t e) const { return g_sc->pinned_mod != 0 && e % g_sc->pinned_mod == 0; }
bool transient(int64_t l, int64_t e) const { return !pinned(l, e) && g_sc->transient_mod != 0 && (e + l) % g_sc->transient_mod == 0; }
const uint8_t* blob(int64_t l, int64_t e) const { return (const uint8_t*) (0x20000000u + (uintptr_t) l * 0x10000u + (uintptr_t) e * 0x10u); }
};
struct Stager {
struct Job { const uint8_t* src; size_t bytes; Src* from = nullptr; int32_t l = 0, e = 0; };
int kRing = 16;
void start(std::vector<Job>&& js) {
if (js.empty()) return; // Stager::start
std::string d = "H stager_start";
for (auto& j : js) d += j.from ? " T" + std::to_string(j.l) + "." + std::to_string(j.e) : " U";
op(d + " n=" + std::to_string(js.size()));
}
const uint8_t* wait(int j) { op("H stager_wait " + std::to_string(j)); return (const uint8_t*) (0x40000000u + (uintptr_t) (j % kRing) * 0x1000u); }
void issued_one(int j, cudaStream_t copy) { cudaEventRecord(3000 + j % kRing, copy); }
void finish() { op("H stager_finish"); }
};
struct Cache { const uint8_t* device_slot(int s) const { return (const uint8_t*) (0x50000000u + (uintptr_t) s * 0x1000u); } };
struct Stats { int64_t experts_dma = 0, experts_streamed = 0, experts_resident = 0; double ms_experts_host = 0, ms_ple = 0; };
constexpr int64_t N = 2560;
struct PT { void mark(int, cudaStream_t) {} };
enum { kPfWaitCopy = 0, kPfDequant = 1 };
inline int64_t stream_all_min() { return 1024; }
// ---- PLE read-ahead stubs
#include <future>
static std::string ple_buf_of(const void* p, uintptr_t base) { return std::to_string(((uintptr_t) p - base) / 0x1000u); }
static int cudaMemcpyAsync(float* dst, const float* src, size_t, int, cudaStream_t) {
(void) dst;
op("K upload ple_emb " + ple_buf_of(src, 0x60000000u));
return 0;
}
static int cudaEventSynchronize(cudaEvent_t e) { op("H sync ple_copied " + std::to_string(e - 4000)); return 0; }
template <class F> static std::future<bool> shim_async(F f) { op("H ple_async"); return std::async(std::launch::deferred, f); }
struct PleTable {
bool gather_batch_device(const uint32_t*, size_t, float*, cudaStream_t, std::string&) { op("K ple_gather_device"); return true; }
};
struct PleState { PleTable* table; };
struct SessionStub { struct { PleTable* table; } ple; };
struct Impl {
Src* src = nullptr; const Cache* cache = nullptr; const int32_t* host_res = nullptr; const ModelGeom* g = nullptr;
int ring = STAGE; cudaStream_t cs = 2, copy = 1;
std::unique_ptr<Stager> stager;
uint8_t* stage_dev[RING_MAX] = {};
cudaEvent_t copied[RING_MAX] = {}, used[RING_MAX] = {};
bool stage_live[RING_MAX] = {};
float* ple_emb = nullptr;
float* ple_emb_host[2] = {};
cudaEvent_t ple_copied[2] = {};
std::vector<uint32_t> ple_rows[2];
int64_t T = 0;
};
static void run_scenario(const Scenario& sc) {
g_sc = &sc;
g_ops.clear();
Impl m;
ModelGeom geom{sc.n_expert, sc.n_layers};
const ModelGeom& g = geom;
Src src_obj; Cache cache_obj;
m.src = &src_obj;
m.g = &geom;
m.ring = sc.ring;
m.stager.reset(new Stager());
m.stager->kRing = sc.stager_ring;
for (int i = 0; i < RING_MAX; ++i) {
m.stage_dev[i] = (uint8_t*) (0x10000000u + (uintptr_t) i * 0x1000u);
m.copied[i] = 1000 + i; m.used[i] = 2000 + i;
}
std::vector<int32_t> host_res_table((size_t) sc.n_layers * sc.n_expert, -1);
if (sc.cache_present) {
int next_slot = 0;
for (int l = 0; l < sc.n_layers; ++l)
for (int e = 0; e < sc.n_expert; ++e)
if (sc.resident_mod != 0 && e % sc.resident_mod == sc.resident_rem) host_res_table[(size_t) l * sc.n_expert + e] = next_slot++;
m.host_res = host_res_table.data();
m.cache = &cache_obj;
}
Stats stats_;
PT pt;
cudaStream_t cs = m.cs;
const int64_t LB = sc.lb, LE = sc.le, T = sc.T;
std::string err;
for (int chunk = 0; chunk < sc.chunks; ++chunk) {
op("H chunk " + std::to_string(chunk));
auto chunk_fn = [&]() -> bool {
// ---- VERBATIM prefill.cpp (sequence, issue_until) ----
const strata::kernels::cpu::ExpertLayout& lay0 = strata::kernels::cpu::expert_layout();
const bool stream_all = m.ring > STAGE && T >= stream_all_min() && m.src != nullptr;
struct StreamEntry { int32_t l, e; const uint8_t* blob; int job; };
std::vector<StreamEntry> seq;
std::vector<size_t> seq_start;
size_t issued = 0, consumed = 0;
if (stream_all) {
seq_start.assign((size_t) g.n_layers + 1, 0);
std::vector<Stager::Job> js;
for (int64_t l = LB; l < LE; ++l) {
seq_start[(size_t) l] = seq.size();
for (int32_t e = 0; e < m.g->n_expert; ++e) {
if (m.host_res && m.cache && m.host_res[(size_t) l * m.g->n_expert + e] >= 0) continue;
int job = -1;
const uint8_t* b = nullptr;
if (m.src->transient(l, e)) { // CS-T: copied by the source into the stager's buffer
job = (int) js.size();
js.push_back({nullptr, (size_t) lay0.blob_bytes(l), m.src, (int32_t) l, e});
} else {
b = m.src->blob(l, e);
if (!b) { err = "prefill: expert source has no blob"; return false; }
if (!m.src->pinned(l, e)) {
job = (int) js.size();
js.push_back({b, (size_t) lay0.blob_bytes(l)});
}
}
seq.push_back({(int32_t) l, e, b, job});
}
}
for (int64_t l = LE; l <= g.n_layers; ++l) seq_start[(size_t) l] = seq.size();
m.stager->start(std::move(js));
}
struct StagerDone {
Stager* st;
~StagerDone() { if (st) st->finish(); }
} chunk_stager_done{stream_all ? m.stager.get() : nullptr};
auto issue_until = [&](size_t limit) {
limit = std::min(limit, seq.size());
while (issued < limit) {
const StreamEntry& en = seq[issued];
const int sl = (int) (issued % (size_t) m.ring);
const auto th = Clock::now();
const size_t bytes = (size_t) lay0.blob_bytes(en.l);
if (m.stage_live[sl]) cudaStreamWaitEvent(m.copy, m.used[sl], 0);
if (en.job < 0) {
cudaMemcpyAsync(m.stage_dev[sl], en.blob, bytes, cudaMemcpyHostToDevice, m.copy);
++stats_.experts_dma;
} else {
const uint8_t* hb = m.stager->wait(en.job);
cudaMemcpyAsync(m.stage_dev[sl], hb, bytes, cudaMemcpyHostToDevice, m.copy);
m.stager->issued_one(en.job, m.copy);
}
cudaEventRecord(m.copied[sl], m.copy);
m.stage_live[sl] = true;
stats_.ms_experts_host += ms_since(th);
++stats_.experts_streamed;
++issued;
}
};
// ---- end VERBATIM ----
const bool threaded_issue = false;
std::atomic<size_t> a_issued{0}, a_consumed{0};
// ---- VERBATIM prefill.cpp (wait_issued, give_back) ----
// the consumer's side: entry k's copy is on the copy stream (the thread issued it), then k is given back
auto wait_issued = [&](size_t k) {
if (!threaded_issue) return;
while (a_issued.load(std::memory_order_acquire) <= k) std::this_thread::yield();
};
auto give_back = [&](size_t upto) {
if (threaded_issue) a_consumed.store(upto, std::memory_order_release);
else issue_until(upto + (size_t) m.ring);
};
// ---- end VERBATIM ----
if (stream_all) issue_until((size_t) m.ring); // prefill.cpp: else if (stream_all) { issue_until((size_t) m.ring); }
for (int64_t l = LB; l < LE; ++l) {
const std::vector<int32_t>& order = sc.orders[(size_t) (l - LB)];
op("H layer " + std::to_string(l));
const strata::kernels::cpu::ExpertLayout& lay = strata::kernels::cpu::expert_layout();
// ---- VERBATIM prefill.cpp (staging setup, stage_one) ----
// Stage ahead: the copy stream moves blobs host -> device while the compute stream works.
int stage_next = 0;
std::vector<int> stage_of(order.size(), -1);
// the unpinned ones are copied to pinned buffers by the stager's threads, in this order
std::vector<int> job_of(order.size(), -1);
if (!stream_all) {
std::vector<Stager::Job> js;
for (size_t j = 0; j < order.size(); ++j) {
const int32_t e = order[j];
if (m.host_res && m.cache && m.host_res[(size_t) l * m.g->n_expert + e] >= 0) continue;
if (m.src->pinned(l, e)) continue;
job_of[j] = (int) js.size();
if (m.src->transient(l, e)) { // CS-T: copied by the source
js.push_back({nullptr, (size_t) lay.blob_bytes(l), m.src, (int32_t) l, e});
continue;
}
const uint8_t* b = m.src->blob(l, e);
if (!b) { err = "prefill: expert source has no blob"; return false; }
js.push_back({b, (size_t) lay.blob_bytes(l)});
}
m.stager->start(std::move(js));
}
StagerDone stager_done{stream_all ? nullptr : m.stager.get()};
auto stage_one = [&](size_t j) -> bool {
const int32_t e = order[j];
const bool resident = m.host_res && m.cache && m.host_res[(size_t) l * m.g->n_expert + e] >= 0;
if (resident) return true;
const int sl = stage_next;
stage_next = (stage_next + 1) % STAGE;
const auto th = Clock::now();
const bool pinned = m.src->pinned(l, e); // pinned: never transient
const uint8_t* b = pinned ? m.src->blob(l, e) : nullptr;
if (pinned && !b) { err = "prefill: expert source has no blob"; return false; }
if (pinned) {
// DMA straight from the page-locked arena: the copy stream only waits for the slot
if (m.stage_live[sl]) cudaStreamWaitEvent(m.copy, m.used[sl], 0);
cudaMemcpyAsync(m.stage_dev[sl], b, (size_t) lay.blob_bytes(l), cudaMemcpyHostToDevice, m.copy);
++stats_.experts_dma;
} else {
// copied to a pinned buffer by the stager (waits only if it is behind), then DMA
const uint8_t* hb = m.stager->wait(job_of[j]);
if (m.stage_live[sl]) cudaStreamWaitEvent(m.copy, m.used[sl], 0);
cudaMemcpyAsync(m.stage_dev[sl], hb, (size_t) lay.blob_bytes(l), cudaMemcpyHostToDevice, m.copy);
m.stager->issued_one(job_of[j], m.copy);
}
cudaEventRecord(m.copied[sl], m.copy);
m.stage_live[sl] = true;
stage_of[j] = sl;
stats_.ms_experts_host += ms_since(th);
++stats_.experts_streamed;
return true;
};
// ---- end VERBATIM ----
auto compute = [&](size_t j, const uint8_t*, int slot) -> bool {
op("K compute " + std::to_string(order[j]) + " " + (slot >= 0 ? std::to_string(slot) : std::string("-")));
if (slot >= 0) cudaEventRecord(m.used[slot], m.cs); // prefill.cpp: after the gather / dequant read of the blob
return true;
};
// ---- VERBATIM prefill.cpp (the walks) ----
if (!stream_all) {
size_t staged = 0;
const size_t lookahead = STAGE - 1;
for (size_t j = 0; j < order.size(); ++j) {
while (staged < order.size() && staged <= j + lookahead) {
if (!stage_one(staged)) return false;
++staged;
}
const int32_t e = order[j];
if (stage_of[j] < 0) {
++stats_.experts_resident;
if (!compute(j, m.cache->device_slot(m.host_res[(size_t) l * m.g->n_expert + e]), -1)) return false;
} else {
pt.mark(kPfWaitCopy, cs);
cudaStreamWaitEvent(m.cs, m.copied[stage_of[j]], 0);
if (!compute(j, m.stage_dev[stage_of[j]], stage_of[j])) return false;
}
}
} else {
// the streamed walk: this layer's entries [k, kend) in id order; an entry the routing did not
// pick only gives its slot back
size_t k = seq_start[(size_t) l];
const size_t kend = seq_start[(size_t) l + 1];
auto release_to = [&](int32_t e_stop) {
while (k < kend && seq[k].e < e_stop) {
cudaEventRecord(m.used[k % (size_t) m.ring], m.cs);
consumed = ++k;
give_back(consumed);
}
};
for (size_t j = 0; j < order.size(); ++j) {
const int32_t e = order[j];
release_to(e);
if (k < kend && seq[k].e == e) {
const int sl = (int) (k % (size_t) m.ring);
pt.mark(kPfWaitCopy, cs);
wait_issued(k);
cudaStreamWaitEvent(m.cs, m.copied[sl], 0);
if (!compute(j, m.stage_dev[sl], sl)) return false;
consumed = ++k;
give_back(consumed);
} else {
++stats_.experts_resident;
if (!compute(j, m.cache->device_slot(m.host_res[(size_t) l * m.g->n_expert + e]), -1)) return false;
}
}
release_to(m.g->n_expert);
}
// ---- end VERBATIM ----
op("K combine");
}
return true;
};
if (!chunk_fn()) { std::fprintf(stderr, "scenario %s failed: %s\n", sc.name, err.c_str()); std::exit(2); }
}
std::printf("{\"name\":\"%s\",\"p\":{\"n_layers\":%d,\"n_expert\":%d,\"lb\":%d,\"le\":%d,\"ring\":%d,\"stager_ring\":%d,\"rows\":%lld,"
"\"resident_mod\":%d,\"resident_rem\":%d,\"cache_present\":%d,\"pinned_mod\":%d,\"transient_mod\":%d,\"chunks\":%d,\"orders\":[",
sc.name, sc.n_layers, sc.n_expert, sc.lb, sc.le, sc.ring, sc.stager_ring, (long long) T, sc.resident_mod, sc.resident_rem,
(int) sc.cache_present, sc.pinned_mod, sc.transient_mod, sc.chunks);
for (size_t li = 0; li < sc.orders.size(); ++li) {
std::printf("%s[", li ? "," : "");
for (size_t k = 0; k < sc.orders[li].size(); ++k) std::printf("%s%d", k ? "," : "", sc.orders[li][k]);
std::printf("]");
}
std::printf("]},\"stats\":[%lld,%lld,%lld],\"ops\":[", (long long) stats_.experts_dma, (long long) stats_.experts_streamed, (long long) stats_.experts_resident);
for (size_t i = 0; i < g_ops.size(); ++i) std::printf("%s\"%s\"", i ? "," : "", g_ops[i].c_str());
std::printf("]}");
}
struct PleScenario { const char* name; int64_t n, T; bool gpu_cache; };
static void run_ple_scenario(const PleScenario& sc) {
g_ops.clear();
Impl m;
m.T = sc.T;
PleTable table;
SessionStub ss;
ss.ple.table = &table;
for (int b = 0; b < 2; ++b) { m.ple_emb_host[b] = (float*) (0x60000000u + (uintptr_t) b * 0x1000u); m.ple_copied[b] = 4000 + b; m.ple_rows[b].assign(4, 0); }
m.ple_emb = (float*) 0x70000000u;
Stats stats_;
std::string err;
const int64_t n = sc.n;
const bool ple_on = true, ple_gpu_cache = sc.gpu_cache;
std::string ple_next_err;
std::future<bool> ple_next;
int ple_buf = 0;
auto ple_gather = [&](int64_t c0, int buf, std::string&) -> bool { op("H ple_gather " + std::to_string(c0) + " " + std::to_string(buf)); return true; };
for (int64_t c0 = 0; c0 < n; c0 += m.T) {
const int64_t T = std::min(m.T, n - c0);
op("H ple_chunk " + std::to_string(c0));
cudaStream_t cs = 2; (void) cs;
auto ple_fn = [&]() -> bool {
// ---- VERBATIM prefill.cpp (the PLE row read-ahead) ----
if (ple_on) {
const auto tp = Clock::now();
if (ple_gpu_cache) {
if (!ple_gather(c0, 0, err) ||
!ss.ple.table->gather_batch_device(m.ple_rows[0].data(), (size_t) T,
m.ple_emb, m.cs, err)) return false;
} else if (!ple_next.valid()) {
if (!ple_gather(c0, ple_buf, err)) return false;
} else if (!ple_next.get()) {
err = ple_next_err;
return false;
}
if (!ple_gpu_cache) {
cudaMemcpyAsync(m.ple_emb, m.ple_emb_host[ple_buf], (size_t) T * N * 4, cudaMemcpyHostToDevice, m.cs);
cudaEventRecord(m.ple_copied[ple_buf], m.cs);
if (c0 + m.T < n) {
cudaEventSynchronize(m.ple_copied[ple_buf ^ 1]); // the other buffer's upload (a chunk ago) is done
ple_next = shim_async( [&ple_gather, &ple_next_err, c1 = c0 + m.T, b = ple_buf ^ 1] {
return ple_gather(c1, b, ple_next_err);
});
}
ple_buf ^= 1;
}
stats_.ms_ple += ms_since(tp);
}
// ---- end VERBATIM ----
return true;
};
if (!ple_fn()) { std::fprintf(stderr, "ple scenario failed\n"); std::exit(2); }
}
std::printf("{\"name\":\"%s\",\"ple\":[%lld,%lld,%d],\"ops\":[", sc.name, (long long) sc.n, (long long) sc.T, (int) sc.gpu_cache);
for (size_t i = 0; i < g_ops.size(); ++i) std::printf("%s\"%s\"", i ? "," : "", g_ops[i].c_str());
std::printf("]}");
}
// ---- the GR write fusion decision of one half
namespace strata { namespace kernels { struct CvecStub { bool cover; bool covers(int64_t) const { return cover; } }; inline CvecStub& cvec() { static CvecStub c; return c; } } }
static bool g_gr_unfused = false;
static bool gr_unfused() { return g_gr_unfused; }
static bool fuse_of(int64_t l, int half, int64_t LE, bool ple_on, bool unfused, bool cvec_covers) {
g_gr_unfused = unfused;
strata::kernels::cvec().cover = cvec_covers;
const int64_t nl = half == 0 ? l : l + 1;
const bool fuse = !gr_unfused() && nl < LE && !(half == 1 && nl == 1 && ple_on) &&
!(half == 1 && strata::kernels::cvec().covers(l));
return fuse;
}
static std::vector<int32_t> iota_vec(int n, int step = 1, int from = 0) {
std::vector<int32_t> v;
for (int i = from; i < n; i += step) v.push_back(i);
return v;
}
int main() {
std::vector<Scenario> sc;
// fields: name, n_layers, n_expert, lb, le, ring, stager_ring, T, orders, resident_mod, resident_rem, cache_present, pinned_mod, transient_mod, chunks
sc.push_back({"stream_basic", 6, 24, 1, 4, 16, 16, 1024,
{iota_vec(24, 2), iota_vec(24, 3, 1), {0, 1, 2, 5, 23}}, 5, 0, true, 3, 4, 2});
sc.push_back({"stream_ring_wrap", 4, 40, 0, 3, 16, 16, 2048,
{iota_vec(40), iota_vec(40), iota_vec(40, 7)}, 0, 0, true, 2, 0, 2});
sc.push_back({"stream_no_cache_all_pinned", 3, 20, 0, 3, 16, 16, 1024,
{iota_vec(20), iota_vec(20, 2), {19}}, 0, 0, false, 1, 0, 1});
sc.push_back({"stream_sparse_release", 5, 40, 1, 4, 16, 4, 4096,
{{39}, {0}, {5, 6, 7, 30}}, 0, 0, true, 5, 3, 2});
sc.push_back({"staged_under_threshold", 4, 32, 0, 3, 384, 16, 512,
{iota_vec(32), iota_vec(32, 3), {2, 4}}, 4, 1, true, 3, 5, 2});
sc.push_back({"staged_ring8", 3, 12, 0, 2, 8, 16, 4096,
{iota_vec(12), iota_vec(12, 2)}, 0, 0, false, 2, 3, 1});
sc.push_back({"staged_few_experts", 3, 10, 0, 2, 16, 16, 100,
{{1, 3, 4}, {9}}, 3, 0, true, 0, 0, 1});
std::printf("{\"ring\":[");
for (size_t i = 0; i < sc.size(); ++i) { if (i) std::printf(",\n"); run_scenario(sc[i]); }
std::printf("],\n");
std::vector<PleScenario> ples = {{"ple_two_chunks_gather", 2000, 1024, false}, {"ple_single_chunk", 100, 256, false},
{"ple_gpu_cache", 3000, 1024, true}, {"ple_four_chunks", 4096, 1024, false},
{"ple_exact_multiple", 2048, 1024, false}};
std::printf("\"ple\":[");
for (size_t i = 0; i < ples.size(); ++i) { if (i) std::printf(",\n"); run_ple_scenario(ples[i]); }
std::printf("],\n\"fuse\":[");
bool first = true;
for (int le : {48, 16}) for (int ple_on = 0; ple_on < 2; ++ple_on) for (int unfused = 0; unfused < 2; ++unfused)
for (int cv = 0; cv < 2; ++cv) for (int l : {0, 1, 2, 14, 15, 46, 47}) for (int half = 0; half < 2; ++half) {
if (l >= le) continue;
std::printf("%s[%d,%d,%d,%d,%d,%d,%d]", first ? "" : ",", le, ple_on, unfused, cv, l, half, (int) fuse_of(l, half, le, ple_on != 0, unfused != 0, cv != 0));
first = false;
}
std::printf("]}\n");
return 0;
}