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

qsa scorer (#1943): the exact four-lanes-per-query scorer is the default on gfx12; the test runs there too

Niko1221c298fa559e8e
diff --git a/docs/AMD_HIP.md b/docs/AMD_HIP.md
index ef633086a..ef9264ba8 100644
--- a/docs/AMD_HIP.md
+++ b/docs/AMD_HIP.md
@@ -299,10 +299,13 @@ only when its version matches the installed library; otherwise it prefills on pl
prompt), so keep the table and the library paired. Not worth trying (measured flat): `--kv-resident` changes, a prefill
chunk above 32768, `--spec` above 4.
-## gfx1100: optional exact long-prompt QSA scorer
+## Exact long-prompt QSA scorer (gfx1100 opt-in, gfx12 default)
`STRATA_SCORES_THREAD=1` at engine startup enables a HIP port of #1825's score kernel on gfx1100, for batches of
-at least 64 queries with at least 16,385 live index blocks. The default, short-prompt and decode paths keep the
+at least 64 queries with at least 16,385 live index blocks. On gfx12 (RDNA4) it is on by default for those batches and
+`STRATA_SCORES_THREAD=0` turns it off (0.1.45): on an R9700 `qsa_scores_gfx1100_parity --full` compares 223,664,777 scores and
+11,895,800 ids bitwise equal to the warp scorer, the scorer stage with 256 queries is 3.6x faster at 131K and 4.0x at 240K, and a
+fresh prompt of 131K tokens reads 8.7% faster (4 of 4 pairs) and one of 230K tokens 16.4% faster (3 of 3), with the same answer tokens and byte-identical `exact_pp` residual dumps at 70K and 131K tokens (prompts under 65K cells never reach the bound). The default, short-prompt and decode paths keep the
existing scorer. On one RX 7900 XTX / 7950X3D / ROCm 10.0.0, three paired runs of a tuned 0.1.40.3 engine reduced
fresh one-token request time by 10.45% at 130,978 prompt tokens and 22.64% at 239,906; one same-binary current-main
pair measured 12.85% and 21.71%. Cached follow-ups did not show a repeatable large gain, and a two-task coding pilot
diff --git a/src/kernels/cuda/qsa_select.cu b/src/kernels/cuda/qsa_select.cu
index c27ca108c..5fd67f95b 100644
--- a/src/kernels/cuda/qsa_select.cu
+++ b/src/kernels/cuda/qsa_select.cu
@@ -947,19 +947,24 @@ __global__ void __launch_bounds__(256, 1) block_scores_thread_kernel(const float
}
}
-bool scores_gfx1100_device() {
+// The exact scorer runs on gfx1100 (the PR's own card) when STRATA_SCORES_THREAD=1, and on gfx12 (RDNA4) unless STRATA_SCORES_THREAD=0:
+// there it is bitwise equal to the warp scorer on an R9700 (qsa_scores_gfx1100_parity --full, 35 cases; exact_pp residual dumps at 70K and
+// 131K tokens) and 3.6-4.4x faster in the scorer stage, +8% (131K) to +15% (230K) on a prompt read. Other wave32 parts have no measurement.
+// Returns 0 (not offered), 1 (gfx1100: only on request), 2 (gfx12: the default).
+int scores_thread_arch() {
int device = -1;
- if (cudaGetDevice(&device) != cudaSuccess) { cudaGetLastError(); return false; }
+ if (cudaGetDevice(&device) != cudaSuccess) { cudaGetLastError(); return 0; }
static thread_local int cached_device = -1;
- static thread_local bool supported = false;
+ static thread_local int arch = 0;
if (device != cached_device) {
cudaDeviceProp properties{};
- supported = cudaGetDeviceProperties(&properties, device) == cudaSuccess &&
- gfx_arch_is(properties.gcnArchName, "gfx1100");
+ arch = 0;
+ if (cudaGetDeviceProperties(&properties, device) == cudaSuccess)
+ arch = gfx_arch_is_gfx12(properties.gcnArchName) ? 2 : gfx_arch_is(properties.gcnArchName, "gfx1100") ? 1 : 0;
cached_device = device;
cudaGetLastError();
}
- return supported;
+ return arch;
}
#endif
@@ -1207,16 +1212,18 @@ void qsa_block_scores(const float* pooled, const float* dead, const float* q_idx
}
const int64_t reach = active_blocks > 0 && active_blocks < max_blocks ? active_blocks : max_blocks;
#if defined(__HIPCC__)
- static const bool thread_scores = [] {
+ // STRATA_SCORES_THREAD: 1 = on (gfx1100, gfx12), 0 = off, unset = on for gfx12 only (gfx1100: off, nothing measured here)
+ static const int thread_env = [] {
const char* value = std::getenv("STRATA_SCORES_THREAD");
- return value != nullptr && std::atoi(value) == 1; // experiment: off by default
+ return value == nullptr ? -1 : (std::atoi(value) == 1 ? 1 : 0);
}();
// The bound is the ACTUAL live extent. A reserved 256K context never enables this by itself.
- if (thread_scores && active_blocks >= 16385 && active_blocks <= max_blocks && nq >= 64 &&
- scores_gfx1100_device()) {
+ if (thread_env != 0 && active_blocks >= 16385 && active_blocks <= max_blocks && nq >= 64 &&
+ (scores_thread_arch() == 2 || (thread_env == 1 && scores_thread_arch() == 1))) {
static thread_local bool logged = false;
- if (!logged && std::getenv("STRATA_SCORES_THREAD_TRACE")) {
- std::fprintf(stderr, "qsa exact thread: gfx1100 nq=%lld active_blocks=%lld capacity=%lld\n",
+ if (!logged && (thread_env == -1 || std::getenv("STRATA_SCORES_THREAD_TRACE"))) {
+ std::fprintf(stderr, "qsa exact thread: the prompt's block scorer runs as the four-lanes-per-query kernel (nq=%lld active_blocks=%lld "
+ "capacity=%lld; the same scores bit for bit; STRATA_SCORES_THREAD=0 turns it off)\n",
(long long)nq, (long long)active_blocks, (long long)max_blocks);
logged = true;
}
diff --git a/src/kernels/qsa_scores_gfx1100_parity.cpp b/src/kernels/qsa_scores_gfx1100_parity.cpp
index 63053d937..00832d979 100644
--- a/src/kernels/qsa_scores_gfx1100_parity.cpp
+++ b/src/kernels/qsa_scores_gfx1100_parity.cpp
@@ -161,7 +161,7 @@ int main(int argc, char** argv) {
int devices = 0;
if (cudaGetDeviceCount(&devices) != cudaSuccess || devices == 0) { std::puts("SKIP no GPU"); return 77; }
cudaDeviceProp properties{}; ck(cudaGetDeviceProperties(&properties, 0));
- if (!k::gfx_arch_is(properties.gcnArchName, "gfx1100")) { std::puts("SKIP requires gfx1100"); return 77; }
+ if (!k::gfx_arch_is(properties.gcnArchName, "gfx1100") && !k::gfx_arch_is_gfx12(properties.gcnArchName)) { std::puts("SKIP requires gfx1100 or gfx12"); return 77; }
require(std::getenv("STRATA_SCORES_THREAD") && std::strcmp(std::getenv("STRATA_SCORES_THREAD"), "1") == 0,
"run with STRATA_SCORES_THREAD=1 so the candidate branch is tested");
const bool full = argc > 1 && std::strcmp(argv[1], "--full") == 0;