Skip to content

Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.

C++

SYCL: STRATA_USAGE_DUMP=PATH counts every routed expert in the device plan (an atomic per entry) and writes the counts in --dump-routing format; a measurement of how much residency matters under STRATA_VERIFY_NO_HOST

Niko122150089624995a
diff --git a/sycl/include/strata/kernels/resident_plan_mirror.hpp b/sycl/include/strata/kernels/resident_plan_mirror.hpp
index b28a089a3..b974c1a70 100644
--- a/sycl/include/strata/kernels/resident_plan_mirror.hpp
+++ b/sycl/include/strata/kernels/resident_plan_mirror.hpp
@@ -6,5 +6,5 @@ namespace strata::kernels {
/// that is not in the VRAM cache but has a non-zero entry in `mirror_table` ([n_layers][n_expert] device-readable
/// addresses, 0 = none) as planned: the expert kernels read it from that address, over PCIe. `d_res` is the residency
/// table whose per-layer slices resident_plan receives, so the layer of a call is found from its pointer.
-void resident_plan_set_mirror(const int32_t* d_res, const unsigned long long* mirror_table);
+void resident_plan_set_mirror(const int32_t* d_res, const unsigned long long* mirror_table, int32_t* usage = nullptr);
}
diff --git a/sycl/src/kernels/cuda/verify_kernels.dp.cpp b/sycl/src/kernels/cuda/verify_kernels.dp.cpp
index 52c665ba2..558477f9d 100644
--- a/sycl/src/kernels/cuda/verify_kernels.dp.cpp
+++ b/sycl/src/kernels/cuda/verify_kernels.dp.cpp
@@ -2084,7 +2084,7 @@ resident_plan_kernel(const int32_t *__restrict__ ids, int n, int k,
const unsigned long long *slot_off, long long blob,
int32_t *__restrict__ pl, long long capx, uint32_t *skip,
uint32_t ring, const unsigned long long *__restrict__ mir,
- volatile uint32_t *plan_err) {
+ volatile uint32_t *plan_err, int32_t *usage) {
auto item_ct1 = sycl::ext::oneapi::this_work_item::get_nd_item<3>();
auto &s_ids = *sycl::ext::oneapi::group_local_memory_for_overwrite<
int32_t[kResidentPlanMax]>(
@@ -2109,6 +2109,9 @@ auto &s_ids = *sycl::ext::oneapi::group_local_memory_for_overwrite<
s_ids[tid] = eid;
slot = (eid >= 0 && eid < n_expert) ? res[eid] : -1;
if (slot < 0 && eid >= 0 && eid < n_expert && mir != nullptr) maddr = mir[eid];
+ if (usage != nullptr && eid >= 0 && eid < n_expert) // the adaptive tier's routing counts (device side)
+ sycl::atomic_ref<int32_t, sycl::memory_order::relaxed, sycl::memory_scope::device,
+ sycl::access::address_space::global_space>(usage[eid]).fetch_add(1);
if (slot < 0 && maddr == 0)
dpct::atomic_fetch_or<sycl::access::address_space::generic_space>(
&s_bad, 1);
@@ -2360,8 +2363,10 @@ __dpct_inline__ void copy_or_zero_kernel(sycl::float4 *__restrict__ dst,
namespace {
const int32_t* g_mirror_res = nullptr;
const unsigned long long* g_mirror_table = nullptr;
+int32_t* g_usage = nullptr;
}
-void resident_plan_set_mirror(const int32_t* d_res, const unsigned long long* mirror_table) {
+void resident_plan_set_mirror(const int32_t* d_res, const unsigned long long* mirror_table, int32_t* usage) {
+ g_usage = usage;
g_mirror_res = d_res;
g_mirror_table = mirror_table;
}
@@ -2369,8 +2374,10 @@ void resident_plan(const int32_t* ids, int n_entries, int k, const int32_t* res_
const uint8_t* cache_base, const unsigned long long* slot_off, long long blob, int32_t* plan,
long long capx, uint32_t* skip, uint32_t ring, void* stream, uint32_t* plan_err) {
const unsigned long long* mir = nullptr; // SYCL port: the layer's slice of the host-mirror table, if any
+ int32_t* use = nullptr; // the layer's slice of the device routing counts, if on
if (g_mirror_table != nullptr && g_mirror_res != nullptr && res_layer >= g_mirror_res)
mir = g_mirror_table + (res_layer - g_mirror_res);
+ if (g_usage != nullptr && g_mirror_res != nullptr && res_layer >= g_mirror_res) use = g_usage + (res_layer - g_mirror_res);
{
auto exp_props = sycl::ext::oneapi::experimental::properties{
sycl::ext::oneapi::experimental::use_root_sync};
@@ -2384,7 +2391,7 @@ void resident_plan(const int32_t* ids, int n_entries, int k, const int32_t* res_
[[sycl::reqd_sub_group_size(32)]] {
resident_plan_kernel(
ids, n_entries, k, res_layer, n_expert, cache_base,
- slot_off, blob, plan, capx, skip, ring, mir, plan_err);
+ slot_off, blob, plan, capx, skip, ring, mir, plan_err, use);
});
}
check("resident_plan");
diff --git a/sycl/src/program/generate.cpp b/sycl/src/program/generate.cpp
index f21548dfc..2169c6de9 100644
--- a/sycl/src/program/generate.cpp
+++ b/sycl/src/program/generate.cpp
@@ -12037,7 +12037,13 @@ int main(int argc, char **argv) try {
strata::core::Verifier ver;
strata::core::VerifyHits vh;
vh.d_res = thits.d_res;
- if (mirror_table_d) strata::kernels::resident_plan_set_mirror(thits.d_res, mirror_table_d);
+ int32_t* usage_dev = nullptr; // STRATA_USAGE_DUMP=PATH: the device plan counts every routed expert (measurement)
+ const char* usage_dump = std::getenv("STRATA_USAGE_DUMP");
+ if (mirror_table_d && usage_dump && *usage_dump) {
+ usage_dev = sycl::malloc_device<int32_t>((size_t) (g.n_layers * g.n_expert), dpct::get_in_order_queue());
+ dpct::get_in_order_queue().memset(usage_dev, 0, (size_t) (g.n_layers * g.n_expert) * 4).wait();
+ }
+ if (mirror_table_d) strata::kernels::resident_plan_set_mirror(thits.d_res, mirror_table_d, usage_dev);
vh.h_res = host_res.empty() ? nullptr : host_res.data();
vh.cache_base = thits.cache_base;
vh.blob = thits.blob;
@@ -12484,6 +12490,24 @@ int main(int argc, char **argv) try {
std::printf("%-24s plan %.3f activation quantize %.3f jobs %.3f run %.3f ms/round\n", "dispatch",
drive.d.ms_plan / rounds, drive.d.ms_actq / rounds, drive.d.ms_jobs / rounds,
drive.d.ms_run / rounds);
+ if (usage_dev != nullptr) { // STRATA_USAGE_DUMP: the window's routing as make_profile.py reads it (layer, k=1, id, weight)
+ std::vector<int32_t> uh((size_t) (g.n_layers * g.n_expert));
+ dpct::get_in_order_queue().memcpy(uh.data(), usage_dev, uh.size() * 4).wait();
+ if (FILE* uf = std::fopen(usage_dump, "wb")) {
+ int64_t total = 0;
+ for (int64_t l = 0; l < g.n_layers; ++l)
+ for (int64_t e = 0; e < g.n_expert; ++e)
+ for (int32_t c = 0; c < uh[(size_t) (l * g.n_expert + e)]; ++c, ++total) {
+ const int32_t hdr[3] = {(int32_t) l, 1, (int32_t) e};
+ const float wgt[2] = {0.0f, 0.0f};
+ std::fwrite(hdr, 4, 3, uf);
+ std::fwrite(wgt, 4, 1, uf); // (layer, k) + k ids + k weights: 8 + 8 bytes
+ }
+ std::fclose(uf);
+ std::printf("%-24s %s (%lld routed entries counted on the device)\n", "usage dumped", usage_dump,
+ (long long) total);
+ }
+ }
if (rounds > 0 && !drive.d.usage.empty())
std::printf("%-24s %lld experts swapped into the VRAM tier (every %d rounds, %.3f ms/round)\n", "adaptive tier",
(long long) swaps_total, o.adapt_every, ms_adapt / rounds);