Merge perf-PR group sm75 (f-145-pp-sm75)

This commit is contained in:
Niko1221 committed 2026-10-16 10:59:08 +02:00
commit df6262f270
27 files changed
+2244 -137

No files matched your search

+57 -8
View File
@@ -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)
@@ -271,6 +272,25 @@ 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).
// 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;
#else
static int per_dev[64]; // 0 unknown, 1 no, 2 yes
int dev = 0;
if (cudaGetDevice(&dev) != cudaSuccess || dev < 0 || dev >= 64) return false;
if (!per_dev[dev]) {
int maj = 0, mnr = 0;
const bool ok = cudaDeviceGetAttribute(&maj, cudaDevAttrComputeCapabilityMajor, dev) == cudaSuccess &&
cudaDeviceGetAttribute(&mnr, cudaDevAttrComputeCapabilityMinor, dev) == cudaSuccess;
if (!ok) cudaGetLastError();
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
}
bool fuse_wait_on() {
#if defined(STRATA_USE_HIP)
static const int env = [] {
@@ -287,7 +307,21 @@ bool fuse_wait_on() {
}
return per_dev[dev] == 2;
#else
return false;
// CUDA: STRATA_FUSE_WAIT=1 folds both waits (the plan's and the CPU rows'), =2 only the plan's, =0 neither. Turing
// default 2 (RTX 2080 Ti, Flash-Next Q2_0, two runs each: +0.6..+1.4 % decode); the rows' version makes every row
// block of the copy poll the flag over PCIe and was -1.5 % there, so it stays opt-in.
static const int env = [] { const char* v = std::getenv("STRATA_FUSE_WAIT"); return v != nullptr ? std::atoi(v) : -1; }();
if (env >= 0) return env == 1 || env == 2;
return device_is_sm75();
#endif
}
// 143-amdk's rows version of the folded wait (copy_rows_from_mapped_after): HIP with fuse_wait_on, CUDA STRATA_FUSE_WAIT=1
bool fuse_rows_on() {
#if defined(STRATA_USE_HIP)
return fuse_wait_on();
#else
static const bool on = [] { const char* v = std::getenv("STRATA_FUSE_WAIT"); return v != nullptr && std::atoi(v) == 1; }();
return on;
#endif
}
@@ -1226,6 +1260,22 @@ bool Verifier::record_window(int T, cudaStream_t cs, std::string& err) {
stamp(l, 1, grp);
float* xm = mixed_ + tb * N;
bool il_ready = false; // xil_ holds xq_'s interleaved copy (reset whenever xq_ is rewritten)
// a projection input's q8_1 blocks and their interleaved copy in one launch (native_quantize_q8_1_il, the same
// bytes): Turing default (+0.5..+1 % decode, two launches fewer per GDN layer and per QSA layer); STRATA_QIL=0 / 1
// forces it off / on
auto quant_in = [&](const float* x, int n_in) {
#if !defined(STRATA_USE_HIP)
static const int qil_env = [] { const char* v = std::getenv("STRATA_QIL"); return v != nullptr ? std::atoi(v) : -1; }();
const bool qil = qil_env >= 0 ? qil_env != 0 : device_is_sm75();
if (qil && n >= 2 && n <= 4 && g_mmvq_il()) {
strata::kernels::native_quantize_q8_1_il(x, xq_, xil_, n_in, n, cs);
il_ready = true;
return;
}
#endif
native_quantize_q8_1(x, xq_, n_in, n, cs);
il_ready = false;
};
auto mm = [&](const WeightRef* w, float* out, int n_in, int n_out) {
if (g_mmvq_il() && strata::kernels::native_mmvq_il_supported(w->native_type, n, n_out)) {
if (!il_ready && n >= 2) { // one column reads the plain q8_1 blocks
@@ -1263,7 +1313,7 @@ bool Verifier::record_window(int T, cudaStream_t cs, std::string& err) {
(int) HV, n, side_);
if (cudaEventRecord(mjoin_, side_) != cudaSuccess) { err = "verify: the GDN gates' branch could not join"; return false; }
}
if (!q8_attn) native_quantize_q8_1(xm, xq_, (int) N, n, cs);
if (!q8_attn) quant_in(xm, (int) N);
if (side_proj) { // the gate projection (compute-bound for i-quants) beside qkv and the conv
// the branch reads F4's interleaved copy too (written on cs before the fork; bitwise native_mmvq's
// output), and qkv is recorded before the branch's launch, so its grid is dispatched first and the
@@ -1370,8 +1420,8 @@ bool Verifier::record_window(int T, cudaStream_t cs, std::string& err) {
stamp(l, 6, grp);
// STRATA_QFUSE: done above by gdn_step_norm_multi - but a batch's per-slot recurrence passes it no q8_1
// destination (#1139: the out-projection read stale bytes), so that case quantizes here as without it
if (!g_qfuse() || batch_rec_) native_quantize_q8_1(y_ + (size_t) tb * ZV, xq_, (int) ZV, n, cs);
il_ready = false;
if (!g_qfuse() || batch_rec_) quant_in(y_ + (size_t) tb * ZV, (int) ZV);
else il_ready = false;
mm(wout, bo_ + tb * N, (int) ZV, (int) N);
} else {
// ======================= QSA =======================
@@ -1418,7 +1468,7 @@ bool Verifier::record_window(int T, cudaStream_t cs, std::string& err) {
return e == nullptr || std::atoi(e) != 0;
}();
const bool qb = dec_batch && n > 1 && native_qsa_enabled() && native_rope_enabled() && (!st.kv_q4 || qb_q4);
if (!q8_attn) native_quantize_q8_1(xm, xq_, (int) N, n, cs);
if (!q8_attn) quant_in(xm, (int) N);
// STRATA_DF_BRANCH: the query side (q and its norm/RoPE/rotation on side 0, the indexer query on side 1)
// beside the K/V side; the indexer query joins before the block scores, the query before attention
const bool qbr = br && qb;
@@ -1740,8 +1790,7 @@ bool Verifier::record_window(int T, cudaStream_t cs, std::string& err) {
qsa_gate_apply_f32(attn_ + t * NH * HD, qfull_ + t * NH * 2 * HD, s, attn32_ + t * NH * HD, cs);
}
stamp(l, 14, grp);
native_quantize_q8_1(attn32_ + tb * NH * HD, xq_, (int) (NH * HD), n, cs);
il_ready = false;
quant_in(attn32_ + tb * NH * HD, (int) (NH * HD));
mm(wo, bo_ + tb * N, (int) (NH * HD), (int) N);
}
} catch (const std::exception& e) {
@@ -1965,7 +2014,7 @@ bool Verifier::record_window(int T, cudaStream_t cs, std::string& err) {
copy_or_zero_from_mapped(parts_out, m_ymiss_ + (size_t) tb * K * N, (long long) n * K * N,
skip_ + grp, ring, cs);
} else {
const bool fuse_rows = fuse_wait_on() && !prof_on_ && !remote_opt_ && dec_batch && m_bal_ == nullptr; // 143-amdk
const bool fuse_rows = fuse_rows_on() && !prof_on_ && !remote_opt_ && dec_batch && m_bal_ == nullptr; // 143-amdk
if (!fuse_rows) {
if (m_bal_ != nullptr) // set_pcie_balance: ... and ends as it waits for the CPU's rows
wait_flag_ge_stamped(m_flag_, ring, m_bal_ + ((l - lb_) * 2 + grp) * 4 + 2, nullptr, cs);