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

sm_75 series: the bitwise Turing kernels (#2069-#2072 #2081 #2093 #2220-#2222) are opt-in with STRATA_SM75_PERF=1

Niko12217f1964a6cbb3
diff --git a/include/strata/core/sm75_series.hpp b/include/strata/core/sm75_series.hpp
new file mode 100644
index 000000000..5e6097fa4
--- /dev/null
+++ b/include/strata/core/sm75_series.hpp
@@ -0,0 +1,46 @@
+// strata/core/sm75_series.hpp - the Turing (RTX 20, compute capability 7.5) kernel series: one opt-in switch.
+//
+// The Turing kernels of PRs #2069-#2072, #2081, #2091-#2093, #2145-#2146, #2220-#2223, #1821 were measured on one RTX
+// 2080 Ti (and a CMP 50HX) and are bitwise equal to the kernels they replace. We have no sm_75 card to confirm them, so
+// they are ON ONLY WHEN ASKED FOR:
+//
+// STRATA_SM75_PERF=1 turns on every bitwise Turing kernel of the series on a compute capability 7.5 card.
+//
+// Each kernel keeps the author's own switch, which wins over STRATA_SM75_PERF in both directions (=0 off, =1 on, on any
+// card where the PR said so for tests). Nothing here changes a card that is not a 7.5: the check is the card's compute
+// capability (STRATA_EMULATE_CC=75 counts, so a 75-virtual build on an sm_86 card runs the series for tests).
+//
+// The numerics-changing Turing options are NOT part of this switch and keep their own explicit opt-ins:
+// STRATA_SELECT_SIMT=1|2 (FP32 tiled block scorer), STRATA_PA_V2T=1 (v2 prompt attention), STRATA_PF_FUSED_SM75=1
+// (fused int8 prompt experts), STRATA_BF16_TC=1 (FP16 tensor-core projections).
+#pragma once
+
+#include "strata/core/emulate.hpp"
+
+#include <cstdlib>
+
+namespace strata {
+
+/// STRATA_SM75_PERF=1 (read once)
+inline bool sm75_series() {
+ static const bool on = [] {
+ const char* e = std::getenv("STRATA_SM75_PERF");
+ return e != nullptr && std::atoi(e) != 0;
+ }();
+ return on;
+}
+
+/// the device (raw cudaDevAttrComputeCapabilityMajor / Minor) is a Turing card, or emulates one (STRATA_EMULATE_CC=75)
+inline bool is_sm75(int major, int minor) { return cc_major_of(major) == 7 && cc_minor_of(minor) == 5; }
+
+/// the default of a bitwise Turing kernel switch: on for a Turing card when STRATA_SM75_PERF=1
+inline bool sm75_default(int major, int minor) { return is_sm75(major, minor) && sm75_series(); }
+
+/// a Turing switch with its own variable: `name` set means 0 off / anything else on (Turing only); unset follows the series
+inline bool sm75_switch(const char* name, int major, int minor) {
+ if (!is_sm75(major, minor)) return false;
+ const char* v = std::getenv(name);
+ return v != nullptr ? std::atoi(v) != 0 : sm75_series();
+}
+
+} // namespace strata
diff --git a/include/strata/core/tc_sm75.hpp b/include/strata/core/tc_sm75.hpp
index 5b7276073..30160d9a4 100644
--- a/include/strata/core/tc_sm75.hpp
+++ b/include/strata/core/tc_sm75.hpp
@@ -7,22 +7,19 @@
//
// **ONLY sm_75 IS EVER AFFECTED.** The predicate below answers true for compute capability 7.5 and for nothing
// else: cc 7.0/7.2 (Volta) keeps its own behaviour, and every cc >= 8 keeps the paths the engine was written
-// with. `STRATA_TC_SM75` can only turn the Turing paths OFF (for an A/B or a bisect); it cannot turn them on
-// somewhere else, so a machine that is not a 2080 Ti cannot be moved onto them by an environment variable.
+// with. A machine that is not a 2080 Ti cannot be moved onto them by an environment variable.
// The kernels themselves are gated a second time, at compile time, by `__CUDA_ARCH__ == 750`.
+//
+// 0.1.45: the Turing paths are opt-in (nobody here has an sm_75 card to confirm them): STRATA_SM75_PERF=1
+// (sm75_series.hpp) turns them on, STRATA_TC_SM75=0 / 1 forces this one off / on (still only on a 7.5 card).
#pragma once
-#include <cstdlib>
+#include "strata/core/sm75_series.hpp"
namespace strata::core {
-/// The Turing paths are for compute capability 7.5 exactly. `auto` (the default): on. "0": off (the
-/// pre-patch behaviour). Any other value, and any other device, is off.
inline bool tc_sm75_enabled(int cc_major, int cc_minor) {
- if (cc_major != 7 || cc_minor != 5) return false; // 7.5 and only 7.5 - never another SM model
- const char* e = std::getenv("STRATA_TC_SM75");
- if (e != nullptr && e[0] == '0') return false;
- return true;
+ return strata::sm75_switch("STRATA_TC_SM75", cc_major, cc_minor); // 7.5 and only 7.5 - never another SM model
}
} // namespace strata::core
diff --git a/src/core/verify.cpp b/src/core/verify.cpp
index 8b1b4b750..3c3d54834 100644
--- a/src/core/verify.cpp
+++ b/src/core/verify.cpp
@@ -1,5 +1,6 @@
// src/core/verify.cpp - see include/strata/core/verify.hpp.
#include "strata/core/batch_rows.hpp"
+#include "strata/core/sm75_series.hpp"
#include "strata/kernels/gfx_arch.hpp"
#include "strata/core/verify.hpp"
#if !defined(STRATA_USE_HIP) && !defined(STRATA_HIP_GFX906)
@@ -249,7 +250,7 @@ bool head_mix_multi_enabled() {
// copy_rows_from_mapped_after): same reads, same values, one kernel node fewer each. A dependent kernel costs ~2.4 us in a
// gfx1201 graph whatever it does; measured on gfx12 only, so it is on there by default. STRATA_FUSE_WAIT=0 / 1 forces it
// off / on (HIP builds; a CUDA build never fuses).
-// sm_75 (Turing) defaults of the CUDA build's switches below, read per device
+// the Turing series (STRATA_SM75_PERF=1, sm75_series.hpp) defaults of the CUDA build's switches below, read per device
bool device_is_sm75() {
#if defined(STRATA_USE_HIP)
return false;
@@ -262,7 +263,7 @@ bool device_is_sm75() {
const bool ok = cudaDeviceGetAttribute(&maj, cudaDevAttrComputeCapabilityMajor, dev) == cudaSuccess &&
cudaDeviceGetAttribute(&mnr, cudaDevAttrComputeCapabilityMinor, dev) == cudaSuccess;
if (!ok) cudaGetLastError();
- per_dev[dev] = ok && maj == 7 && mnr == 5 ? 2 : 1;
+ per_dev[dev] = ok && strata::sm75_default(maj, mnr) ? 2 : 1; // a Turing card with STRATA_SM75_PERF=1
}
return per_dev[dev] == 2;
#endif
diff --git a/src/kernels/cuda/fused_gr.cu b/src/kernels/cuda/fused_gr.cu
index 6c97fc625..ce2a395e2 100644
--- a/src/kernels/cuda/fused_gr.cu
+++ b/src/kernels/cuda/fused_gr.cu
@@ -1,5 +1,6 @@
// src/kernels/cuda/fused_gr.cu - see include/strata/kernels/fused_gr.hpp.
#include "strata/core/emulate.hpp"
+#include "strata/core/sm75_series.hpp"
#include "strata/kernels/q8_1_finite.hpp" // #606: q8_1_ds
#include "strata/core/geometry.hpp"
#include "strata/kernels/fused_gr.hpp"
@@ -1143,7 +1144,7 @@ bool up75_on() {
int major = 0, minor = 0;
cudaDeviceGetAttribute(&major, cudaDevAttrComputeCapabilityMajor, dev);
cudaDeviceGetAttribute(&minor, cudaDevAttrComputeCapabilityMinor, dev);
- per_dev[dev] = major == 7 && minor == 5 ? 2 : 1;
+ per_dev[dev] = strata::sm75_default(major, minor) ? 2 : 1; // Turing, STRATA_SM75_PERF=1
}
return per_dev[dev] == 2;
#endif
@@ -1167,7 +1168,7 @@ int down_tg(int ct) {
int major = 0, minor = 0;
cudaDeviceGetAttribute(&major, cudaDevAttrComputeCapabilityMajor, dev);
cudaDeviceGetAttribute(&minor, cudaDevAttrComputeCapabilityMinor, dev);
- per_dev[dev] = major == 7 && minor == 5 ? 2 : 1;
+ per_dev[dev] = strata::sm75_default(major, minor) ? 2 : 1; // Turing, STRATA_SM75_PERF=1
}
return per_dev[dev] == 2 && (ct == 4 || ct == 6) ? 2 : 0;
#endif
diff --git a/src/kernels/cuda/iq_kernels.cu b/src/kernels/cuda/iq_kernels.cu
index 6df62e4d1..6ee414d4b 100644
--- a/src/kernels/cuda/iq_kernels.cu
+++ b/src/kernels/cuda/iq_kernels.cu
@@ -5,6 +5,7 @@
// MIT license, third_party/ggml/LICENSE). The block structs and codebook grids come from its ggml-common.h,
// included unchanged.
#include "strata/kernels/iq_kernels.hpp"
+#include "strata/core/sm75_series.hpp"
#include "strata/kernels/gfx_arch.hpp"
#include "strata/kernels/dp4a.hpp"
#include "strata/kernels/q8_1_finite.hpp"
@@ -3618,8 +3619,8 @@ int exp_mode() {
// Turing (sm_75): mode 4 (native_expert_bench, real Q2_0 rows of Flash-Next, bitwise equal to mode 0 on an RTX
// 2080 Ti: 10 experts x 1 entry 47.3 -> 41.4 us, 30 x 1 120.2 -> 100.2 us); the down projection keeps the CUDA
// layout in windows of 4+ tokens (sm75_down_em below). STRATA_SM75_EXP=0 keeps the CUDA layout.
- const char* sm75 = std::getenv("STRATA_SM75_EXP");
- const bool turing = major == 7 && minor == 5 && (sm75 == nullptr || std::atoi(sm75) != 0);
+ // (off unless STRATA_SM75_PERF=1; STRATA_SM75_EXP=0 / 1 forces it off / on)
+ const bool turing = strata::sm75_switch("STRATA_SM75_EXP", major, minor);
per_dev[dev] = 1 + ((major == 7 && minor == 0 && sm70 != nullptr && std::atoi(sm70) != 0) || p100 || p40 ? 8 : turing ? 4 : kExpModeDefault);
}
return per_dev[dev] - 1;
@@ -3636,7 +3637,7 @@ int sm75_down_em(int em0, int64_t cap_groups) {
if (cudaGetDevice(&dev) != cudaSuccess) return em0;
cudaDeviceGetAttribute(&major, cudaDevAttrComputeCapabilityMajor, dev);
cudaDeviceGetAttribute(&minor, cudaDevAttrComputeCapabilityMinor, dev);
- return major == 7 && minor == 5 ? 0 : em0;
+ return strata::is_sm75(major, minor) ? 0 : em0;
}
#else
int sm75_down_em(int em0, int64_t) { return em0; }
diff --git a/src/kernels/cuda/native_mmvq.cu b/src/kernels/cuda/native_mmvq.cu
index 20f4aa505..df56525f7 100644
--- a/src/kernels/cuda/native_mmvq.cu
+++ b/src/kernels/cuda/native_mmvq.cu
@@ -28,6 +28,7 @@
#include "strata/kernels/q8_1_finite.hpp"
#include "strata/kernels/iq_kernels.hpp"
#include "strata/kernels/gfx_arch.hpp"
+#include "strata/core/sm75_series.hpp"
#include "s26_tsum.cuh"
#if !defined(__HIPCC__)
#include "q8_1_il.cuh"
@@ -2315,7 +2316,7 @@ bool q2_0_warp_rows_on() {
const bool ok = cudaDeviceGetAttribute(&maj, cudaDevAttrComputeCapabilityMajor, dev) == cudaSuccess &&
cudaDeviceGetAttribute(&mnr, cudaDevAttrComputeCapabilityMinor, dev) == cudaSuccess;
if (!ok) cudaGetLastError();
- on[dev] = ok && maj == 7 && mnr == 5 ? 1 : -1; // measured on Turing only
+ on[dev] = ok && strata::sm75_default(maj, mnr) ? 1 : -1; // Turing only, with STRATA_SM75_PERF=1
}
return on[dev] > 0;
}
@@ -2886,13 +2887,13 @@ void native_mmvq_il_tune(int rows) { g_tune_rows = rows; }
namespace {
// sm_80 and newer (measured on sm_86 and sm_120), Volta (sm_70) and Pascal (sm_60, sm_61), each with its own table
-// above; Turing keeps native_mmvq's kernels unchanged
+// above; Turing keeps native_mmvq's kernels unless STRATA_SM75_PERF=1 (kIlRows_75)
// Volta (PR 1401): opt-in with STRATA_SM70_TABLE=1 until the author confirms on a V100 with the final code
bool sm70_opt_in() { const char* v = std::getenv("STRATA_SM70_TABLE"); return v != nullptr && std::atoi(v) != 0; }
// Pascal (sm_60, GP100): the same interleaved kernels (bitwise equal to native_mmvq's, mmvq_il_parity), its own table
// kIlRows_60. STRATA_SM60_TABLE=0 keeps native_mmvq's kernels on a P100; any other value (or unset) uses the table.
-// Turing (sm_75): its own table kIlRows_75 (bitwise equal); STRATA_SM75_IL=0 keeps the plain kernels
-bool sm75_il_on() { const char* v = std::getenv("STRATA_SM75_IL"); return v == nullptr || std::atoi(v) != 0; }
+// STRATA_SM75_IL=0 / 1 forces the table off / on; unset it follows STRATA_SM75_PERF=1 (Turing only)
+bool sm75_il_on(int major, int minor) { return strata::sm75_switch("STRATA_SM75_IL", major, minor); }
bool sm60_table_on() { const char* v = std::getenv("STRATA_SM60_TABLE"); return v == nullptr || std::atoi(v) != 0; }
// Pascal (sm_61: Tesla P40 / P4, GTX 10 series; native dp4a): the same interleaved kernels (bitwise equal to
// native_mmvq's, mmvq_il_parity), its own table kIlRows_61. STRATA_SM61_TABLE=0 keeps native_mmvq's kernels.
@@ -2906,7 +2907,7 @@ bool il_arch_ok() {
int minor = 0;
cudaDeviceGetAttribute(&minor, cudaDevAttrComputeCapabilityMinor, dev);
ok[dev] = (cudaDeviceGetAttribute(&major, cudaDevAttrComputeCapabilityMajor, dev) == cudaSuccess &&
- (major >= 8 || (major == 7 && minor == 0 && sm70_opt_in()) || (major == 7 && minor == 5 && sm75_il_on()) ||
+ (major >= 8 || (major == 7 && minor == 0 && sm70_opt_in()) || (major == 7 && minor == 5 && sm75_il_on(major, minor)) ||
(major == 6 && minor == 0 && sm60_table_on()) || (major == 6 && minor == 1 && sm61_table_on()))) ? 1 : -1;
}
return ok[dev] > 0;
diff --git a/src/kernels/cuda/qsa_decode_attn.cu b/src/kernels/cuda/qsa_decode_attn.cu
index 41d25b9de..71b5bc358 100644
--- a/src/kernels/cuda/qsa_decode_attn.cu
+++ b/src/kernels/cuda/qsa_decode_attn.cu
@@ -1,5 +1,6 @@
// src/kernels/cuda/qsa_decode_attn.cu - see include/strata/kernels/qsa_decode_attn.hpp.
#include "strata/kernels/qsa_decode_attn.hpp"
+#include "strata/core/sm75_series.hpp"
#include "strata/core/geometry.hpp"
#include "strata/kernels/kv_q8.hpp"
#include "strata/kernels/kv_q4.hpp"
@@ -400,7 +401,7 @@ bool attn_v3_on() {
const bool ok = cudaDeviceGetAttribute(&maj, cudaDevAttrComputeCapabilityMajor, dev) == cudaSuccess &&
cudaDeviceGetAttribute(&mnr, cudaDevAttrComputeCapabilityMinor, dev) == cudaSuccess;
if (!ok) cudaGetLastError();
- on[dev] = ok && maj == 7 && mnr == 5 ? 1 : -1; // measured on Turing only
+ on[dev] = ok && strata::sm75_default(maj, mnr) ? 1 : -1; // Turing only, with STRATA_SM75_PERF=1
}
return on[dev] > 0;
}
diff --git a/src/kernels/cuda/qsa_select.cu b/src/kernels/cuda/qsa_select.cu
index 4550c4a51..5e7a223b2 100644
--- a/src/kernels/cuda/qsa_select.cu
+++ b/src/kernels/cuda/qsa_select.cu
@@ -1,5 +1,6 @@
// src/kernels/cuda/qsa_select.cu - see include/strata/kernels/qsa_select.hpp.
#include "strata/core/emulate.hpp"
+#include "strata/core/sm75_series.hpp"
#include "strata/core/geometry.hpp"
#include <cstdlib>
#include <cstring>
@@ -1384,7 +1385,7 @@ bool scores_halve_on() {
int major = 0, minor = 0;
cudaDeviceGetAttribute(&major, cudaDevAttrComputeCapabilityMajor, dev);
cudaDeviceGetAttribute(&minor, cudaDevAttrComputeCapabilityMinor, dev);
- ok[dev] = major == 7 && minor == 5 ? 1 : 2;
+ ok[dev] = strata::sm75_default(major, minor) ? 1 : 2; // Turing, STRATA_SM75_PERF=1
}
return ok[dev] == 1;
}
@@ -1868,7 +1869,7 @@ bool topk_split_device() {
int major = 0, minor = 0;
cudaDeviceGetAttribute(&major, cudaDevAttrComputeCapabilityMajor, dev);
cudaDeviceGetAttribute(&minor, cudaDevAttrComputeCapabilityMinor, dev);
- ok[dev] = (env == 1 || (major == 7 && minor == 5)) ? 1 : 2;
+ ok[dev] = (env == 1 || strata::sm75_default(major, minor)) ? 1 : 2; // Turing, STRATA_SM75_PERF=1
}
return ok[dev] == 1;
}
@@ -2088,9 +2089,22 @@ __global__ void __launch_bounds__(TK_T) block_topk_sample_kernel(const float* __
}
}
+// The prompt path's one-read top-k: STRATA_TOPK_SAMPLE=0 / 1 forces it off / on for any card; unset it is a Turing kernel
+// of the series (STRATA_SM75_PERF=1). (As submitted in #2093 it was on for every CUDA card; same ids, but only measured
+// on an RTX 2080 Ti, so the other cards keep the wide kernel.)
bool topk_sample_on() {
static const int env = [] { const char* v = std::getenv("STRATA_TOPK_SAMPLE"); return v ? (std::atoi(v) != 0 ? 1 : 0) : -1; }();
- return env != 0;
+ if (env >= 0) return env != 0;
+ static int ok[64] = {}; // 0 unknown, 1 yes, 2 no
+ int dev = 0;
+ if (cudaGetDevice(&dev) != cudaSuccess || dev < 0 || dev >= 64) { cudaGetLastError(); return false; }
+ if (ok[dev] == 0) {
+ int major = 0, minor = 0;
+ cudaDeviceGetAttribute(&major, cudaDevAttrComputeCapabilityMajor, dev);
+ cudaDeviceGetAttribute(&minor, cudaDevAttrComputeCapabilityMinor, dev);
+ ok[dev] = strata::sm75_default(major, minor) ? 1 : 2;
+ }
+ return ok[dev] == 1;
}
#endif