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++

gfx1151: the exact (bitwise) Aurora switches are on by default on gfx1151 only (arch_defaults), the rounding-level ones stay opt-in

Niko12219708b549a454
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 507bd151b..7982c5ed4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -420,7 +420,8 @@ if(STRATA_ENABLE_CUDA OR STRATA_ENABLE_HIP)
add_library(strata_engine STATIC src/core/layer.cpp src/core/session.cpp src/core/expert_source.cpp src/core/remote_experts.cpp
src/core/remote_expert_opt.cu
src/core/expert_cache.cpp src/core/native_head.cpp src/core/native_dense.cpp src/core/verify.cpp src/core/mtp.cpp
- src/core/conversation_snapshot.cpp src/core/conversation_state.cpp src/core/conversation_memory.cpp src/core/peer_experts.cpp)
+ src/core/conversation_snapshot.cpp src/core/conversation_state.cpp src/core/conversation_memory.cpp src/core/peer_experts.cpp
+ src/core/arch_defaults.cpp)
target_include_directories(strata_engine PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_link_libraries(strata_engine PUBLIC strata_core strata_kernels strata_kernels_cpu ${_strata_gpu_runtime_target})
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/tests/core/file_expert_source_test.cpp")
@@ -918,6 +919,9 @@ add_library(strata_spec STATIC src/spec/suffix_drafter.cpp src/spec/controller.c
src/spec/draft_source.cpp)
target_include_directories(strata_spec PUBLIC include)
if(STRATA_BUILD_TESTS)
+ add_executable(arch_defaults_test src/core/arch_defaults_test.cpp src/core/arch_defaults.cpp)
+ target_include_directories(arch_defaults_test PRIVATE include)
+ add_test(NAME arch_defaults_test COMMAND arch_defaults_test)
add_executable(suffix_drafter_test src/spec/suffix_drafter_test.cpp)
target_link_libraries(suffix_drafter_test PRIVATE strata_spec)
add_test(NAME suffix_drafter_test COMMAND suffix_drafter_test)
diff --git a/include/strata/core/arch_defaults.hpp b/include/strata/core/arch_defaults.hpp
new file mode 100644
index 000000000..cd11a0edd
--- /dev/null
+++ b/include/strata/core/arch_defaults.hpp
@@ -0,0 +1,28 @@
+// include/strata/core/arch_defaults.hpp - the per-architecture defaults of switches that are exact everywhere.
+//
+// Every gfx1151 (Strix Halo, RDNA3.5, unified memory) switch in the table was measured on Aurora (experiments/s23 .. s26,
+// the c-best3-v4.2 config) with BYTE-IDENTICAL output against the same engine with the switch off: the same token ids at
+// 4K / 32K / 64K and on four models, and a bitwise harness per kernel. They are therefore on by default on that
+// architecture and nowhere else: a CUDA build and every other HIP architecture run the code they always ran.
+// Switches that change bits (STRATA_PF_GEMM, STRATA_PF_FUSED, STRATA_HC_UPMIX, STRATA_PA_FAST, STRATA_HIP_WMMA,
+// STRATA_SELECT_WMMA, STRATA_HC_Q8: rounding-level, KL-gated) stay opt-in; docs/STRIX_HALO.md lists them.
+//
+// A switch the user set (to anything) is never overridden; STRATA_GFX1151_DEFAULTS=0 turns the whole table off.
+#pragma once
+
+#include <string>
+#include <utility>
+#include <vector>
+
+namespace strata::core {
+
+/// The environment settings that are the defaults of `gcn_arch` (hipDeviceProp_t::gcnArchName; "gfx1151" or
+/// "gfx1151:sramecc-:xnack-"): empty for every other architecture.
+std::vector<std::pair<std::string, std::string>> arch_default_env(const char* gcn_arch);
+
+/// Sets `arch_default_env(gcn_arch)` in this process's environment where the user has not set the variable, prints one
+/// line to stderr when it set anything, and returns the names it set. Call once, before any engine code reads its
+/// switches (they are read lazily, at first use).
+std::vector<std::string> apply_arch_defaults(const char* gcn_arch);
+
+} // namespace strata::core
diff --git a/src/core/arch_defaults.cpp b/src/core/arch_defaults.cpp
new file mode 100644
index 000000000..8cdf3cf92
--- /dev/null
+++ b/src/core/arch_defaults.cpp
@@ -0,0 +1,62 @@
+// src/core/arch_defaults.cpp - see include/strata/core/arch_defaults.hpp.
+#include "strata/core/arch_defaults.hpp"
+
+#include "strata/kernels/gfx_arch.hpp"
+
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+
+namespace strata::core {
+
+std::vector<std::pair<std::string, std::string>> arch_default_env(const char* gcn_arch) {
+ std::vector<std::pair<std::string, std::string>> t;
+ if (!strata::kernels::gfx_arch_is_gfx1151(gcn_arch)) return t;
+ const char* off = std::getenv("STRATA_GFX1151_DEFAULTS");
+ if (off != nullptr && off[0] == '0') return t;
+ // Exact (bitwise) on Aurora, each with its measured gain in aurora_s23.md:
+ t = {
+ // prompt
+ {"STRATA_GDN_HEAD", "1"}, // the GDN recurrence, four lanes a column + the grid-stride norm (S23)
+ {"STRATA_GDN_PP", "2"}, // two columns per lane: 64K prompt +2.9% (stream A, round 2)
+ {"STRATA_GDN_CONVL2", "1"}, // conv + q/k L2 norm in one kernel: 64K -0.3 s (stream A)
+ {"STRATA_GDN_NOY", "1"}, // no dead FP32 store of the norm (stream A)
+ {"STRATA_CVEC_FUSE", "1"}, // a steered layer's write, control vector and next norm in one pass (S23)
+ {"STRATA_HCD_EXACT", "1"}, // the HC down GEMM in hipBLASLt solution 1176's k order: 64K +1.8% (stream S)
+ {"STRATA_PF_PAD", "1"}, // padded GEMM row strides (acts with STRATA_PF_GEMM; inert without it) (S23)
+ // decode
+ {"STRATA_Q8_PACKED", "1"}, // the packed Q8_0 decode layout: +2.3% (S26)
+ {"STRATA_Q6_PACKED", "1"}, // the packed Q6_K heads (S26)
+ {"STRATA_MMVF_ROWS", "1"}, // bf16 multi-row GEMV, 4 rows per block (S25)
+ {"STRATA_ATTN_LANECELL", "1"}, // decode attention scores, one cell per thread (S25)
+ {"STRATA_EXPERT_V2", "1"}, // the grouped decode experts, IQ3_S gate/up + IQ4_NL down (S26)
+ {"STRATA_TSUM", "1"}, // several warp sums as one transposed butterfly (S26)
+ {"STRATA_LFUSE", "1"}, // fewer launches around the shared expert and the KV append (S26)
+ {"STRATA_GDN_SPLIT", "1"}, // the GDN step over 4 blocks per head (S25/S26)
+ {"STRATA_QFUSE", "1"}, // activation q8_1 images written by their producers (S26)
+ {"STRATA_PLE_BATCH", "1"}, // the verify window's PLE key / value projections at once (S25)
+ };
+ return t;
+}
+
+std::vector<std::string> apply_arch_defaults(const char* gcn_arch) {
+ std::vector<std::string> set;
+ for (const auto& kv : arch_default_env(gcn_arch)) {
+ if (std::getenv(kv.first.c_str()) != nullptr) continue; // the user's setting wins, whatever it is
+#if defined(_WIN32)
+ _putenv_s(kv.first.c_str(), kv.second.c_str());
+#else
+ setenv(kv.first.c_str(), kv.second.c_str(), 0);
+#endif
+ set.push_back(kv.first);
+ }
+ if (!set.empty()) {
+ std::fprintf(stderr, "strata: gfx1151 (Strix Halo): %zu exact speed switches on by default (STRATA_GFX1151_DEFAULTS=0 turns "
+ "them off; a switch you set is kept): ", set.size());
+ for (size_t i = 0; i < set.size(); ++i) std::fprintf(stderr, "%s%s", i ? " " : "", set[i].c_str() + 7);
+ std::fprintf(stderr, "\n");
+ }
+ return set;
+}
+
+} // namespace strata::core
diff --git a/src/core/arch_defaults_test.cpp b/src/core/arch_defaults_test.cpp
new file mode 100644
index 000000000..f4ce0098b
--- /dev/null
+++ b/src/core/arch_defaults_test.cpp
@@ -0,0 +1,60 @@
+// src/core/arch_defaults_test.cpp - the per-architecture default table (no GPU needed).
+#include "strata/core/arch_defaults.hpp"
+
+#include <cstdio>
+#include <cstdlib>
+#include <string>
+
+static int fails = 0;
+#define CHECK(c) do { if (!(c)) { std::printf("FAIL line %d: %s\n", __LINE__, #c); ++fails; } } while (0)
+
+static void unset(const char* k) {
+#if defined(_WIN32)
+ _putenv_s(k, "");
+#else
+ unsetenv(k);
+#endif
+}
+static void put(const char* k, const char* v) {
+#if defined(_WIN32)
+ _putenv_s(k, v);
+#else
+ setenv(k, v, 1);
+#endif
+}
+
+int main() {
+ using namespace strata::core;
+ unset("STRATA_GFX1151_DEFAULTS");
+ // other architectures (and CUDA, which passes an empty name): nothing
+ CHECK(arch_default_env("gfx1100").empty());
+ CHECK(arch_default_env("gfx1201:sramecc-:xnack-").empty());
+ CHECK(arch_default_env("gfx1150").empty());
+ CHECK(arch_default_env("gfx11510").empty()); // not a prefix match
+ CHECK(arch_default_env("").empty());
+ CHECK(arch_default_env(nullptr).empty());
+ // gfx1151, plain and with its feature suffix: the table, and no bit-changing switch in it
+ for (const char* a : {"gfx1151", "gfx1151:sramecc-:xnack-"}) {
+ const auto t = arch_default_env(a);
+ CHECK(t.size() >= 10);
+ for (const auto& kv : t) {
+ CHECK(kv.first.rfind("STRATA_", 0) == 0);
+ for (const char* bits : {"STRATA_PF_GEMM", "STRATA_PF_FUSED", "STRATA_HC_UPMIX", "STRATA_PA_FAST", "STRATA_HIP_WMMA",
+ "STRATA_SELECT_WMMA", "STRATA_HC_Q8", "STRATA_PF_HCDOWN", "STRATA_WMMA_GEMM"})
+ CHECK(kv.first != bits);
+ }
+ }
+ // a user's setting wins, whatever it is; the rest are set
+ put("STRATA_TSUM", "0");
+ unset("STRATA_QFUSE");
+ const auto set = apply_arch_defaults("gfx1151");
+ CHECK(std::getenv("STRATA_TSUM") != nullptr && std::string(std::getenv("STRATA_TSUM")) == "0");
+ CHECK(std::getenv("STRATA_QFUSE") != nullptr && std::string(std::getenv("STRATA_QFUSE")) == "1");
+ for (const auto& n : set) CHECK(n != "STRATA_TSUM");
+ // the opt-out
+ put("STRATA_GFX1151_DEFAULTS", "0");
+ CHECK(arch_default_env("gfx1151").empty());
+ CHECK(apply_arch_defaults("gfx1151").empty());
+ std::printf(fails ? "arch_defaults_test: %d FAILED\n" : "arch_defaults_test: OK\n", fails);
+ return fails ? 1 : 0;
+}
diff --git a/src/core/verify.cpp b/src/core/verify.cpp
index 77cc4b4ab..33f0a601e 100644
--- a/src/core/verify.cpp
+++ b/src/core/verify.cpp
@@ -58,12 +58,12 @@ constexpr float EPS = 1e-6f;
using Clock = std::chrono::steady_clock;
double ms_since(Clock::time_point t) { return std::chrono::duration<double, std::milli>(Clock::now() - t).count(); }
const bool g_dbg = std::getenv("STRATA_VERIFY_DEBUG") != nullptr;
-const bool g_lfuse = [] { const char* v = std::getenv("STRATA_LFUSE"); return v != nullptr && v[0] == '1'; }();
-const bool g_lfuse_gate = [] { const char* v = std::getenv("STRATA_LFUSE_GATE"); return v == nullptr || v[0] != '0'; }();
-const bool g_lfuse_pair = [] { const char* v = std::getenv("STRATA_LFUSE_PAIR"); return v == nullptr || v[0] != '0'; }();
-const bool g_qdedup = [] { const char* v = std::getenv("STRATA_VERIFY_QDEDUP"); return v != nullptr && std::atoi(v) != 0; }();
+inline bool g_lfuse() { static const bool on = [] { const char* v = std::getenv("STRATA_LFUSE"); return v != nullptr && v[0] == '1'; }(); return on; }
+inline bool g_lfuse_gate() { static const bool on = [] { const char* v = std::getenv("STRATA_LFUSE_GATE"); return v == nullptr || v[0] != '0'; }(); return on; }
+inline bool g_lfuse_pair() { static const bool on = [] { const char* v = std::getenv("STRATA_LFUSE_PAIR"); return v == nullptr || v[0] != '0'; }(); return on; }
+inline bool g_qdedup() { static const bool on = [] { const char* v = std::getenv("STRATA_VERIFY_QDEDUP"); return v != nullptr && std::atoi(v) != 0; }(); return on; }
// S26 STRATA_QFUSE=1: activation q8_1 images written by their producers (the GDN output norm) - the same bytes
-const bool g_qfuse = [] { const char* v = std::getenv("STRATA_QFUSE"); return v != nullptr && std::atoi(v) != 0; }();
+inline bool g_qfuse() { static const bool on = [] { const char* v = std::getenv("STRATA_QFUSE"); return v != nullptr && std::atoi(v) != 0; }(); return on; }
#define VDBG(...) do { if (g_dbg) { std::fprintf(stderr, "verify dbg: " __VA_ARGS__); std::fflush(stderr); } } while (0)
struct Bump {
@@ -528,7 +528,7 @@ bool Verifier::init(const WeightTable& wt, const ModelGeometry& g, SessionState&
device_plan_ = !all_resident_ && (v != nullptr && std::atoi(v) != 0);
}
// (halo's STRATA_VERIFY_RESIDENT=1 is this window's all_resident_ graph above, which 0.1.39 has on by default)
- if (g_qfuse) { // S26: the HC read's q8_1 group counters, zeroed once (each launch leaves them zero)
+ if (g_qfuse()) { // S26: the HC read's q8_1 group counters, zeroed once (each launch leaves them zero)
if (cudaMalloc((void**) &qcnt_, sizeof(unsigned) * (size_t) (g.n_embd / 32)) != cudaSuccess ||
cudaMemset(qcnt_, 0, sizeof(unsigned) * (size_t) (g.n_embd / 32)) != cudaSuccess) {
cudaGetLastError();
@@ -590,7 +590,7 @@ bool Verifier::record_window(int T, cudaStream_t cs, std::string& err) {
const int tb_[2] = {0, (T + 1) / 2}, te_[2] = {G == 2 ? (T + 1) / 2 : T, T};
// S26 STRATA_LFUSE=1: where the shared expert's gate / scale fusions apply (the paths they replace are the ones taken)
auto lfuse_on = [&](int n) {
- return g_lfuse && ar_on() && native_moe_combine_enabled() && dec_batch && n > 1 && n <= 8 &&
+ return g_lfuse() && ar_on() && native_moe_combine_enabled() && dec_batch && n > 1 && n <= 8 &&
shared_expert_native_bf16_enabled();
};
bool sg_gated_[2] = {false, false}; // per group: the combine applies the shared gate
@@ -805,9 +805,9 @@ bool Verifier::record_window(int T, cudaStream_t cs, std::string& err) {
}
} else
gdn_step_norm_multi(state, hb, (int) C, gate, beta, z_, (const float*) wnm->data, EPS, y_, (int) HK,
- (int) HV, te, nullptr, cs, tb, g_qfuse ? (void*) xq_ : nullptr);
+ (int) HV, te, nullptr, cs, tb, g_qfuse() ? (void*) xq_ : nullptr);
stamp(l, 6, grp);
- if (!g_qfuse) native_quantize_q8_1(y_ + (size_t) tb * ZV, xq_, (int) ZV, n, cs); // STRATA_QFUSE: done above
+ if (!g_qfuse()) native_quantize_q8_1(y_ + (size_t) tb * ZV, xq_, (int) ZV, n, cs); // STRATA_QFUSE: done above
native_mmvq(wout->native_type, wout->native_data, xq_, bo_ + tb * N, (int) ZV, (int) N, n, cs);
} else {
// ======================= QSA =======================
@@ -854,7 +854,7 @@ bool Verifier::record_window(int T, cudaStream_t cs, std::string& err) {
TS, cs);
} else
if (grp == 0) copy_from_mapped(tail_snap_ + (size_t) qi * TS, st.idx_tail, TS, cs);
- const bool kv_multi = g_lfuse && !st.kv_hybrid && !st.kv_q4 && st.kv_int8 && n > 1; // S26 STRATA_LFUSE
+ const bool kv_multi = g_lfuse() && !st.kv_hybrid && !st.kv_q4 && st.kv_int8 && n > 1; // S26 STRATA_LFUSE
if (kv_multi)
kv_append_q8_steps(st.k_q, st.v_q, st.k_scale, st.v_scale, st.page_table, step_ + tb * kStepCount,
(int) kStepCount, kcur_ + tb * NKV * HD, vcur_ + tb * NKV * HD, (int) (NKV * HD), n,
@@ -980,7 +980,7 @@ bool Verifier::record_window(int T, cudaStream_t cs, std::string& err) {
const WeightRef* w_router = v.get("ffn_gate_inp.weight");
// S26 STRATA_LFUSE=1: the shared expert's gate row rides in the router GEMV launch, its sigmoid + row scale
// move into the combine, gate + up share one launch (all bitwise; resident combine path, 2-8 rows only)
- const WeightRef* w_sgi = lfuse_on(n) && g_lfuse_gate ? v.get("ffn_gate_inp_shexp.weight") : nullptr;
+ const WeightRef* w_sgi = lfuse_on(n) && g_lfuse_gate() ? v.get("ffn_gate_inp_shexp.weight") : nullptr;
bool sg_ready = false;
if (dec_batch && n > 1 && w_router != nullptr && native_router_enabled() && NE == 512 && K == 10) {
try {
@@ -1034,6 +1034,7 @@ bool Verifier::record_window(int T, cudaStream_t cs, std::string& err) {
}
}
stamp(l, 17, grp);
+ bool qdedup = false; // STRATA_VERIFY_QDEDUP took effect: the experts' q8_1 image of xm is already made
{
const WeightRef *wgi = need(v, "ffn_gate_inp_shexp.weight", err), *wsg = need(v, "ffn_gate_shexp.weight", err),
*wsu = need(v, "ffn_up_shexp.weight", err), *wsd = need(v, "ffn_down_shexp.weight", err);
@@ -1049,7 +1050,7 @@ bool Verifier::record_window(int T, cudaStream_t cs, std::string& err) {
// STRATA_VERIFY_QDEDUP=1 (not with the forked shared-expert stream, which quantizes into its own buffer): the
// experts' q8_1 image of xm is made first and the shared expert's gate/up read it (quantize_q8_1_rows and
// native_quantize_q8_1 write the same bytes)
- const bool qdedup = g_qdedup && !sh_fork && strata::kernels::cpu::expert_layout().native;
+ qdedup = g_qdedup() && !sh_fork && strata::kernels::cpu::expert_layout().native;
if (qdedup && !q8_ffn) quantize_q8_1_rows(xm, n, N, nat_xq_ + (size_t) tb * (N / 32) * 36, cs);
if (!shared_expert_native_bf16_enabled()) {
if (dec_batch) f32_to_bf16_bulk(mixed_ + tb * N, sh_bf16_ + tb * N, (int64_t) n * N, sh_stream); // contiguous rows
@@ -1059,7 +1060,7 @@ bool Verifier::record_window(int T, cudaStream_t cs, std::string& err) {
shared_expert_multi(n, xm, sh_bf16_ + tb * N, nsw, (const uint16_t*) wgi->data, sh_gate_ + (size_t) tb * g.n_ff,
sh_up_ + (size_t) tb * g.n_ff, sh_g_ + tb, shared_ + tb * N, N, g.n_ff, sh_stream,
qdedup ? (const void*) (nat_xq_ + (size_t) tb * (N / 32) * 36) : nullptr,
- (sg_ready ? 1 : 0) | (lfuse_on(n) && g_lfuse_pair ? 2 : 0));
+ (sg_ready ? 1 : 0) | (lfuse_on(n) && g_lfuse_pair() ? 2 : 0));
sg_gated_[grp] = sg_ready;
} catch (const std::exception& e) {
err = std::string("verify shared expert: ") + e.what();
@@ -1068,7 +1069,7 @@ bool Verifier::record_window(int T, cudaStream_t cs, std::string& err) {
if (sh_fork) cudaEventRecord(ev_join_, sh_cs_);
}
if (strata::kernels::cpu::expert_layout().native) {
- if (!(g_qdedup && strata::kernels::cpu::expert_layout().native))
+ if (!qdedup)
if (!q8_ffn) quantize_q8_1_rows(xm, n, N, nat_xq_ + (size_t) tb * (N / 32) * 36, cs);
} else
quantize_q8_0_scaled(xm, hit_xq_ + (size_t) tb * (N / 32) * 34, hit_xs_ + (size_t) tb * (N / 32), (int64_t) n * N, cs);
diff --git a/src/program/generate.cpp b/src/program/generate.cpp
index 415e29f1c..cd6094347 100644
--- a/src/program/generate.cpp
+++ b/src/program/generate.cpp
@@ -14,6 +14,7 @@
// AND IT IS PHASE 2, so hit rate is `h = 0` and the number it prints is slow on purpose
// (`phase-2-correct-engine.md:5-9`). What it is FOR is the honest tok/s figure and the logit dump.
+#include "strata/core/arch_defaults.hpp"
#include "strata/core/device.hpp"
#include "strata/core/remote_expert_opt.hpp"
#include "strata/core/expert_cache.hpp"
@@ -1617,6 +1618,14 @@ int main(int argc, char** argv) {
}
}
}
+#if defined(STRATA_USE_HIP)
+ { // gfx1151 (Strix Halo): the switches that are exact there are on by default (strata/core/arch_defaults.hpp); before
+ // any engine code reads its switches (they are read at first use), and the user's own settings are kept
+ cudaDeviceProp ad{};
+ if (cudaGetDeviceProperties(&ad, 0) == cudaSuccess) strata::core::apply_arch_defaults(ad.gcnArchName);
+ else (void) cudaGetLastError();
+ }
+#endif
strata::core::set_coupled_draft(o.coupled_draft);
strata::core::set_peer_portable(o.peer_device >= 1); // multi-GPU: the Portable flag on mapped host buffers only with a peer device (before any allocation)
if (o.serve && o.conversation_cache_mib > 0 && (o.prompt_cache == 0 || o.conversation_cache_slots == 0))