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++
Commit graph: every GDN layer's conv history + state, and every QSA layer's tail restore + indexer append, in one launch each (STRATA_COMMIT_BATCH, default on; =0 keeps the per-layer loop)
Niko12216f3e38100ed2
diff --git a/include/strata/kernels/native_qsa_indexer.hpp b/include/strata/kernels/native_qsa_indexer.hppindex 092af4519..be2ae65fc 100644--- a/include/strata/kernels/native_qsa_indexer.hpp+++ b/include/strata/kernels/native_qsa_indexer.hpp@@ -49,4 +49,21 @@ void native_qsa_indexer_append_steps(const float* raw, const int32_t* relative_pconst QsaIndexerBuffers& buffers, const QsaShapes& shapes,int64_t max_cells, const RopeScaling& scaling, void* stream);+// engine-latency: the commit's append of the same window rows into several QSA layers in one launch. Layer i reads+// raw0 + i * raw_stride and its own gamma/buffers; with tail_src[i] set its tail is first restored from there (the+// commit's snapshot, mapped memory), as copy_from_mapped did before the per-layer append. Bitwise the per-layer calls.+struct QsaIndexerLayers {+ static constexpr int kMax = 16;+ const float* gamma[kMax] = {};+ const float* tail_src[kMax] = {};+ float* tail[kMax] = {};+ float* dead[kMax] = {};+ float* pooled[kMax] = {};+ int32_t* block_pos[kMax] = {};+};+void native_qsa_indexer_append_steps_layers(const float* raw0, int64_t raw_stride, const int32_t* relative_pos_device,+ int pos_stride, int n_steps, int32_t pos_base, float epsilon,+ const QsaIndexerLayers& layers, int n_layers, const QsaShapes& shapes,+ int64_t max_cells, const RopeScaling& scaling, void* stream);+} // namespace strata::kernelsdiff --git a/include/strata/kernels/verify_kernels.hpp b/include/strata/kernels/verify_kernels.hppindex 87e5d5cc3..5b37cdf49 100644--- a/include/strata/kernels/verify_kernels.hpp+++ b/include/strata/kernels/verify_kernels.hpp@@ -41,6 +41,15 @@ void gdn_ab_multi(const float* x, const uint16_t* w_alpha, const uint16_t* w_betvoid gdn_step_norm_multi(float* state, const float* h, int conv_channels, const float* gate, const float* beta,const float* z, const float* gamma, float eps, float* y, int h_k, int h_v, int n_tok,const int32_t* n_keep, void* stream, int t_out_begin = 0, void* xq_out = nullptr);+/// The commit of `n_layers` GDN layers in two launches (engine-latency): layer i's conv history is+/// `state + i * state_stride + conv_off` and its qkv rows `qkv + i * qkv_stride`, as gdn_conv_commit; its recurrence+/// state `state + i * state_stride` over the first *n_keep rows of `h + i * h_stride` / `gate|beta + i * gb_stride`, as+/// gdn_step_norm_multi's commit (n_keep set, no outputs). Every layer's arithmetic is the per-layer call's, so the result+/// is bitwise the loop of per-layer calls. Returns false (nothing launched) when the per-layer commit would not take the+/// state-only kernel (STRATA_GDN_SPLIT=1, STRATA_GDN_COMMIT_SPLIT=0, STRATA_DBG_GDN=1): the caller then keeps the loop.+bool gdn_commit_layers(float* state, int64_t state_stride, int64_t conv_off, const float* qkv, int64_t qkv_stride,+ const float* h, int64_t h_stride, const float* gate, const float* beta, int64_t gb_stride,+ int conv_channels, int h_k, int h_v, int n_max, int n_layers, const int32_t* n_keep, void* stream);/// (xq_out, S26 STRATA_QFUSE: also write the q8_1 image of output rows [t_out_begin, n_tok) there - the bytes/// native_quantize_q8_1(y + t_out_begin * value_dim, xq_out, value_dim, n_tok - t_out_begin) would write.)/// Spin until *flag >= value (a mapped host flag). The value is fixed at capture, so several rings can bediff --git a/src/core/verify.cpp b/src/core/verify.cppindex 3995ae9dd..f4cc74973 100644--- a/src/core/verify.cpp+++ b/src/core/verify.cpp@@ -1990,9 +1990,62 @@ bool Verifier::capture_commit(std::string& err) {copy_i32_from_mapped(commit_, m_commit_, 2 + MT, cs_);int64_t qsa_index = 0, gdn_index = 0;for (int64_t l = 0; l < lb_; ++l) (is_qsa_layer(g, l) ? qsa_index : gdn_index) += 1;+ // engine-latency (STRATA_COMMIT_BATCH, default on; =0 keeps the per-layer loop): every GDN layer's conv history and+ // state in two launches instead of two per layer (~70 graph nodes fewer; the same arithmetic per layer, bitwise).+ // The commit runs between a window and the draft round, which on HIP waits for it.+ static const bool commit_batch = [] { const char* e = std::getenv("STRATA_COMMIT_BATCH"); return !e || e[0] != '0'; }();+ bool gdn_batched = false;+ if (commit_batch) {+ int64_t n_gdn = 0;+ bool norms_ok = true; // the per-layer loop checks each layer's ssm_norm.weight: keep that check+ for (int64_t l = lb_; l < le_ && norms_ok; ++l)+ if (!is_qsa_layer(g, l)) {+ ++n_gdn;+ norms_ok = need(LayerView(*wt_, l), "ssm_norm.weight", err) != nullptr;+ }+ if (!norms_ok) ok = false;+ else if (n_gdn > 0)+ gdn_batched = gdn_commit_layers(+ ss.gdn_state + (size_t) (gdn_index - ss.gdn_ord0) * gdn_floats, (int64_t) gdn_floats,+ (int64_t) g.ssm_state_size * g.ssm_v_heads * g.ssm_state_size, qkv_L_ + (size_t) gdn_index * MT * C,+ MT * C, h_L_ + (size_t) gdn_index * MT * C, MT * C, gate_L_ + (size_t) gdn_index * MT * HV,+ beta_L_ + (size_t) gdn_index * MT * HV, MT * HV, (int) C, (int) g.ssm_k_heads, (int) HV, (int) MT,+ (int) n_gdn, commit_, cs_);+ }+ // the QSA layers' tail restore + indexer append, one launch for all of them (one block per layer)+ bool qsa_batched = false;+ if (commit_batch && ok && !g_no_batch_kv) {+ QsaIndexerLayers il;+ int nq = 0;+ int64_t mc = -1;+ bool fits = true;+ for (int64_t l = lb_, qi = qsa_index; l < le_ && fits; ++l) {+ if (!is_qsa_layer(g, l)) continue;+ const WeightRef* wikn = need(LayerView(*wt_, l), "indexer.k_norm.weight", err);+ if (!wikn) { ok = false; fits = false; break; }+ const QsaState& st = ss.qsa_states[qi];+ if (nq >= QsaIndexerLayers::kMax || (mc >= 0 && st.max_cells != mc)) { fits = false; break; }+ mc = st.max_cells;+ il.gamma[nq] = (const float*) wikn->data;+ il.tail_src[nq] = tail_snap_ + (size_t) qi * TS;+ il.tail[nq] = st.idx_tail; il.dead[nq] = st.idx_dead; il.pooled[nq] = st.idx_pooled;+ il.block_pos[nq] = st.idx_block_pos;+ ++nq;+ ++qi;+ }+ if (ok && fits && nq > 0) {+ native_qsa_indexer_append_steps_layers(idx_raw_L_ + (size_t) qsa_index * MT * ID, MT * ID, commit_ + 2, 1,+ (int) MT, 0, EPS, il, nq, s, mc, rope_scaling(), cs_);+ qsa_batched = true;+ }+ }for (int64_t l = lb_; l < le_ && ok; ++l) {const LayerView v(*wt_, l);- if (!is_qsa_layer(g, l)) {+ if (is_qsa_layer(g, l) && qsa_batched) {+ ++qsa_index;+ } else if (!is_qsa_layer(g, l) && gdn_batched) {+ ++gdn_index;+ } else if (!is_qsa_layer(g, l)) {const WeightRef* wnm = need(v, "ssm_norm.weight", err);if (!wnm) { ok = false; break; }float* state = ss.gdn_state + (size_t) (gdn_index - ss.gdn_ord0) * gdn_floats;@@ -2505,7 +2558,28 @@ bool Verifier::commit(int n_keep, std::string& err) {// a one-token window has advanced the state itself (record_window): no commit graph} else {std::atomic_thread_fence(std::memory_order_seq_cst);+ // STRATA_COMMIT_TIMING=1 (measurement only): the commit graph's GPU time, from an event pair around it (read at the+ // next commit, when the pair has long completed); printed every 300 commits+ static struct CommitTiming {+ bool on = false, pending = false;+ cudaEvent_t b = nullptr, e = nullptr;+ double ms = 0;+ int64_t n = 0;+ CommitTiming() { const char* v = std::getenv("STRATA_COMMIT_TIMING"); on = v != nullptr && v[0] == '1'; }+ } ct;+ if (ct.on && ct.b == nullptr &&+ (cudaEventCreate(&ct.b) != cudaSuccess || cudaEventCreate(&ct.e) != cudaSuccess)) { ct.on = false; (void) cudaGetLastError(); }+ if (ct.on && ct.pending) {+ float ms = 0;+ if (cudaEventSynchronize(ct.e) == cudaSuccess && cudaEventElapsedTime(&ms, ct.b, ct.e) == cudaSuccess) { ct.ms += ms; ++ct.n; }+ ct.pending = false;+ if (ct.n > 0 && ct.n % 300 == 0)+ std::fprintf(stderr, "strata verify: commit graph %.3f ms GPU on average over %lld commits\n", ct.ms / (double) ct.n,+ (long long) ct.n);+ }+ if (ct.on) cudaEventRecord(ct.b, cs_);const cudaError_t le = cudaGraphLaunch(commit_exec_, cs_);+ if (ct.on) { cudaEventRecord(ct.e, cs_); ct.pending = true; }if (le != cudaSuccess) { err = std::string("verify: commit launch: ") + cudaGetErrorString(le); return false; }// set_commit_async: no wait here - the next window runs on the same stream after it, and the drafter (its own// stream) reads only this window's final rows and its own K/V. h_commit_ is next written after the next window'sdiff --git a/src/kernels/cuda/native_qsa_indexer.cu b/src/kernels/cuda/native_qsa_indexer.cuindex f919e8ca4..dcb28768c 100644--- a/src/kernels/cuda/native_qsa_indexer.cu+++ b/src/kernels/cuda/native_qsa_indexer.cu@@ -43,14 +43,14 @@ __device__ float warp_sum(float x) {// no table applies - the default - so the default kernel is 0.1.31's code exactly (the table read is not in it;// with it merely skipped at run time, the compiled default path changed its results).template <bool TAB>-__global__ void append(const float* __restrict__ raw, const int32_t* __restrict__ pos_dev,+__device__ __forceinline__ void append_body(const float* __restrict__ raw, const int32_t* __restrict__ pos_dev,int pos_stride, int n_steps,int pos_base, const float* __restrict__ gamma, float epsilon,float* __restrict__ tail, float* __restrict__ dead,float* __restrict__ pooled, int32_t* __restrict__ block_pos,int max_cells, float theta_scale, float freq_scale, float corr_low,float corr_high, float ext_factor, float mscale,- const int32_t* __restrict__ mtab, RopeTab rt) {+ const int32_t* __restrict__ mtab, const RopeTab& rt) {__shared__ float values[D];__shared__ float partials[32];const int d = threadIdx.x;@@ -113,6 +113,35 @@ __global__ void append(const float* __restrict__ raw, const int32_t* __restrict_if (n_steps > 1) __syncthreads();}}+template <bool TAB>+__global__ void append(const float* __restrict__ raw, const int32_t* __restrict__ pos_dev,+ int pos_stride, int n_steps,+ int pos_base, const float* __restrict__ gamma, float epsilon,+ float* __restrict__ tail, float* __restrict__ dead,+ float* __restrict__ pooled, int32_t* __restrict__ block_pos,+ int max_cells, float theta_scale, float freq_scale, float corr_low,+ float corr_high, float ext_factor, float mscale,+ const int32_t* __restrict__ mtab, RopeTab rt) {+ append_body<TAB>(raw, pos_dev, pos_stride, n_steps, pos_base, gamma, epsilon, tail, dead, pooled, block_pos, max_cells,+ theta_scale, freq_scale, corr_low, corr_high, ext_factor, mscale, mtab, rt);+}+// engine-latency: the commit's appends of several QSA layers in one launch, one block per layer (blockIdx.x); each block+// first restores its layer's tail from the window's snapshot (the commit's copy_from_mapped), then runs append's body+template <bool TAB>+__global__ void append_layers(const float* __restrict__ raw0, long long raw_stride, const int32_t* __restrict__ pos_dev,+ int pos_stride, int n_steps, int pos_base, float epsilon, QsaIndexerLayers L, int max_cells,+ float theta_scale, float freq_scale, float corr_low, float corr_high, float ext_factor,+ float mscale, const int32_t* __restrict__ mtab, RopeTab rt) {+ const int i = blockIdx.x;+ float* tail = L.tail[i];+ if (L.tail_src[i] != nullptr) {+ for (int j = threadIdx.x; j < (R - 1) * D; j += blockDim.x) tail[j] = L.tail_src[i][j];+ __syncthreads();+ }+ append_body<TAB>(raw0 + (long long) i * raw_stride, pos_dev, pos_stride, n_steps, pos_base, L.gamma[i], epsilon, tail,+ L.dead[i], L.pooled[i], L.block_pos[i], max_cells, theta_scale, freq_scale, corr_low, corr_high,+ ext_factor, mscale, mtab, rt);+}// ---- C-2: the batched append. The pooled key of a completed block b (its last cell pos = 4b+3), computed with// the single append's arithmetic: keys rounded through F16, summed tail[0]+tail[1]+tail[2]+incoming in that order,// the RMS norm, gamma, the rotation at pos_base + 4b. `k(j)` is the key of the block's cell j: a row of this batch@@ -265,6 +294,41 @@ void native_qsa_indexer_append_steps(const float* raw, const int32_t* relative_pif (error != cudaSuccess) throw std::runtime_error(cudaGetErrorString(error));}+void native_qsa_indexer_append_steps_layers(const float* raw0, int64_t raw_stride, const int32_t* relative_pos_device,+ int pos_stride, int n_steps, int32_t pos_base, float epsilon,+ const QsaIndexerLayers& layers, int n_layers, const QsaShapes& s,+ int64_t max_cells, const RopeScaling& scaling, void* stream) {+ if (n_steps <= 0 || n_layers <= 0) return;+ if (!stream || n_layers > QsaIndexerLayers::kMax || s.idx_dim != D || s.idx_block != R || s.n_rot != ROT ||+ max_cells < 1 || max_cells > INT32_MAX || pos_base < 0 || pos_base % R ||+ int64_t(pos_base) + max_cells > INT32_MAX || !std::isfinite(epsilon) || epsilon <= 0.0f ||+ rope_scaling_invalid(scaling) != nullptr)+ throw std::invalid_argument("native QSA indexer (layers): bad geometry, layer count or parameters");+ for (int i = 0; i < n_layers; ++i) { // the per-layer append's span checks, layer by layer+ const std::size_t pos_span = (n_steps == 1 || pos_stride <= 0) ? 4 : (std::size_t(n_steps - 1) * pos_stride + 1) * 4;+ const Span spans[] = {{raw0 + (std::size_t) i * (std::size_t) raw_stride, std::size_t(n_steps)*D*4},+ {relative_pos_device,pos_span},{layers.gamma[i],D*4},{layers.tail[i],(R-1)*D*4},{layers.dead[i],D*4},+ {layers.pooled[i],std::size_t(max_cells/R+1)*D*4},{layers.block_pos[i],4}};+ for (const auto& span : spans) validate(span);+ for (int a = 0; a < 7; ++a) for (int b = a + 1; b < 7; ++b)+ if (overlaps(spans[a], spans[b])) throw std::invalid_argument("native QSA indexer buffers overlap");+ }+ const float theta_scale = powf((float) scaling.freq_base, -2.0f / ROT);+ const RopeKernelArgs k = scaling.kernel_args(ROT);+ const RopeTab rt = rope_table_for(scaling);+ const cudaStream_t st = static_cast<cudaStream_t>(stream);+ if (rt.cos != nullptr)+ append_layers<true><<<n_layers, THREADS, 0, st>>>(raw0, (long long) raw_stride, relative_pos_device, pos_stride, n_steps,+ pos_base, epsilon, layers, int(max_cells), theta_scale, k.freq_scale, k.corr_low, k.corr_high, k.ext_factor,+ k.attn_factor, mrope_table(), rt);+ else+ append_layers<false><<<n_layers, THREADS, 0, st>>>(raw0, (long long) raw_stride, relative_pos_device, pos_stride, n_steps,+ pos_base, epsilon, layers, int(max_cells), theta_scale, k.freq_scale, k.corr_low, k.corr_high, k.ext_factor,+ k.attn_factor, mrope_table(), rt);+ const auto error = cudaGetLastError();+ if (error != cudaSuccess) throw std::runtime_error(cudaGetErrorString(error));+}+void native_qsa_indexer_append(const float* raw, const int32_t* relative_pos_device, int32_t pos_base,const float* gamma, float epsilon, const QsaIndexerBuffers& b,const QsaShapes& s, int64_t max_cells, const RopeScaling& scaling, void* stream) {diff --git a/src/kernels/cuda/verify_kernels.cu b/src/kernels/cuda/verify_kernels.cuindex ac2855d78..16d7ef037 100644--- a/src/kernels/cuda/verify_kernels.cu+++ b/src/kernels/cuda/verify_kernels.cu@@ -170,6 +170,10 @@ __global__ void __launch_bounds__(S) gdn_conv_ab_kernel(int conv_blocks, float*// (48 * 4 = 192 blocks of 128 threads across all SMs, vs 48 blocks of 512 threads), with no sq/o/norm/z/y work.// DBG (STRATA_DBG_GDN=1, #937): a window count the launch never allowed (n_keep is read from device memory; n_max is the// rows the window holds) is reported and the commit skipped, where the fault would be a memory-aperture violation+__device__ __forceinline__ void gdn_step_commit_body(float* __restrict__ state, const float* __restrict__ hbuf, int C,+ const float* __restrict__ gate, const float* __restrict__ beta,+ int h_k, int h_v, int n);+template <bool DBG>__global__ void __launch_bounds__(32 * RG) gdn_step_commit_kernel(float* __restrict__ state,const float* __restrict__ hbuf, int C,@@ -184,6 +188,46 @@ __global__ void __launch_bounds__(32 * RG) gdn_step_commit_kernel(float* __restrprintf("strata DBG: gdn_step_commit: n_keep %d is past the window's %d rows: commit skipped (#937)\n", n, n_max);return;}+ gdn_step_commit_body(state, hbuf, C, gate, beta, h_k, h_v, n);+}++// engine-latency: gdn_step_commit_kernel for every GDN layer of the commit in one launch (blockIdx.z = the layer); each+// layer's blocks run gdn_step_commit_body on that layer's state and rows, exactly as its own launch did+__global__ void __launch_bounds__(32 * RG) gdn_step_commit_layers_kernel(float* __restrict__ state, long long state_stride,+ const float* __restrict__ hbuf, long long h_stride,+ int C, const float* __restrict__ gate,+ const float* __restrict__ beta, long long gb_stride,+ int h_k, int h_v, const int32_t* __restrict__ n_keep) {+ const int n = *n_keep;+ if (n <= 0) return;+ const long long z = blockIdx.z;+ gdn_step_commit_body(state + z * state_stride, hbuf + z * h_stride, C, gate + z * gb_stride, beta + z * gb_stride, h_k,+ h_v, n);+}++// engine-latency: gdn_conv_commit_kernel for every GDN layer in one launch (blockIdx.y = the layer)+__global__ void gdn_conv_commit_layers_kernel(float* __restrict__ hist0, long long hist_stride, const float* __restrict__ qkv0,+ long long qkv_stride, int C, const int32_t* __restrict__ n_keep) {+ const int c = blockIdx.x * blockDim.x + threadIdx.x;+ if (c >= C) return;+ const int n = *n_keep;+ if (n <= 0) return;+ float* hist = hist0 + (long long) blockIdx.y * hist_stride;+ const float* qkv = qkv0 + (long long) blockIdx.y * qkv_stride;+ float seq[3];+#pragma unroll+ for (int j = 0; j < 3; ++j) {+ const int src = n + j; // the last three of [hist(3) | x_0..x_{n-1}]+ seq[j] = src < 3 ? hist[c * 3 + src] : qkv[(size_t) (src - 3) * C + c];+ }+ hist[c * 3] = seq[0];+ hist[c * 3 + 1] = seq[1];+ hist[c * 3 + 2] = seq[2];+}++__device__ __forceinline__ void gdn_step_commit_body(float* __restrict__ state, const float* __restrict__ hbuf, int C,+ const float* __restrict__ gate, const float* __restrict__ beta,+ int h_k, int h_v, int n) {__shared__ float sk[S];__shared__ float red[RG][32];const int head = blockIdx.x;@@ -970,6 +1014,29 @@ void gdn_conv_commit(float* history, const float* qkv, int channels, const int32check("gdn_conv_commit");}+bool gdn_commit_layers(float* state, int64_t state_stride, int64_t conv_off, const float* qkv, int64_t qkv_stride,+ const float* h, int64_t h_stride, const float* gate, const float* beta, int64_t gb_stride,+ int conv_channels, int h_k, int h_v, int n_max, int n_layers, const int32_t* n_keep, void* stream) {+ // the per-layer commit's kernel choice (gdn_step_norm_multi below): only its state-only kernel is batched here+ static const bool per_layer = [] {+ const char* sp = std::getenv("STRATA_GDN_SPLIT");+ const char* cs = std::getenv("STRATA_GDN_COMMIT_SPLIT");+ const char* dbg = std::getenv("STRATA_DBG_GDN");+ return (sp && sp[0] == '1') || (cs && cs[0] == '0') || (dbg && dbg[0] == '1');+ }();+ if (per_layer || n_layers <= 0 || n_layers > 65535 || n_max < 1 || n_max > kVerifyMaxT || n_keep == nullptr ||+ h_v <= 0 || h_k <= 0 || h_v % h_k != 0)+ return false;+ cudaStream_t st = (cudaStream_t) stream;+ gdn_conv_commit_layers_kernel<<<dim3((unsigned) ((conv_channels + 255) / 256), (unsigned) n_layers), 256, 0, st>>>(+ state + conv_off, (long long) state_stride, qkv, (long long) qkv_stride, conv_channels, n_keep);+ gdn_step_commit_layers_kernel<<<dim3((unsigned) h_v, 4u, (unsigned) n_layers), dim3(32, RG), 0, st>>>(+ state, (long long) state_stride, h, (long long) h_stride, conv_channels, gate, beta, (long long) gb_stride, h_k, h_v,+ n_keep);+ check("gdn_commit_layers");+ return true;+}+void gdn_ab_multi(const float* x, const uint16_t* w_alpha, const uint16_t* w_beta, const float* dt, const float* ssm_a,float* gate, float* beta, int n_embd, int h_v, int n_tok, void* stream) {if (n_embd % 8 != 0 || n_tok < 1 || n_tok > kVerifyMaxT) {diff --git a/src/kernels/gdn_parity.cpp b/src/kernels/gdn_parity.cppindex 7e0b1d00c..a9ea9214a 100644--- a/src/kernels/gdn_parity.cpp+++ b/src/kernels/gdn_parity.cpp@@ -520,6 +520,70 @@ int main(int argc, char** argv) {bad += ab_bad + sn_bad;}+ // ================= 6. the layer-batched commit (engine-latency), bitwise against the per-layer calls =================+ // gdn_commit_layers runs every layer's conv-history commit and state commit in one launch each; the per-layer loop+ // (gdn_conv_commit + gdn_step_norm_multi with n_keep, no outputs) is the reference. Several layers with their own+ // state, rows and gate/beta; n_keep 1..T; memcmp on the whole state arena (states and conv histories).+ {+ const int qk = S * h_k, C = 2 * qk + S * h_v, L = 5, MT = strata::kernels::kVerifyMaxT;+ const int64_t conv_off = (int64_t) S * h_v * S, stride = conv_off + (int64_t) C * 3;+ std::vector<float> st0((size_t) (stride * L)), hb((size_t) L * MT * C), qkv((size_t) L * MT * C),+ gt((size_t) L * MT * h_v), bt((size_t) L * MT * h_v), zdummy((size_t) MT * S * h_v), gm(S, 1.0f);+ for (auto& x : st0) x = gauss(rng) * 0.1f;+ for (auto& x : hb) x = gauss(rng) * 0.1f;+ for (auto& x : qkv) x = gauss(rng);+ for (auto& x : gt) x = -(0.5f + (float) (rng() % 100) / 50.0f);+ for (auto& x : bt) x = (float) (rng() % 100) / 100.0f;+ float *d_a = nullptr, *d_b = nullptr, *d_h = nullptr, *d_qkv = nullptr, *d_g = nullptr, *d_bt = nullptr,+ *d_z = nullptr, *d_y = nullptr, *d_gm = nullptr;+ int32_t* d_nk = nullptr;+ check(cudaMalloc(&d_a, st0.size() * 4), "la"); check(cudaMalloc(&d_b, st0.size() * 4), "lb");+ check(cudaMalloc(&d_h, hb.size() * 4), "lh"); check(cudaMalloc(&d_qkv, qkv.size() * 4), "lq");+ check(cudaMalloc(&d_g, gt.size() * 4), "lg"); check(cudaMalloc(&d_bt, bt.size() * 4), "lbt");+ check(cudaMalloc(&d_z, zdummy.size() * 4), "lz"); check(cudaMalloc(&d_y, zdummy.size() * 4), "ly");+ check(cudaMalloc(&d_gm, gm.size() * 4), "lgm"); check(cudaMalloc(&d_nk, 4), "lnk");+ check(cudaMemcpy(d_h, hb.data(), hb.size() * 4, cudaMemcpyHostToDevice), "lch");+ check(cudaMemcpy(d_qkv, qkv.data(), qkv.size() * 4, cudaMemcpyHostToDevice), "lcq");+ check(cudaMemcpy(d_g, gt.data(), gt.size() * 4, cudaMemcpyHostToDevice), "lcg");+ check(cudaMemcpy(d_bt, bt.data(), bt.size() * 4, cudaMemcpyHostToDevice), "lcb");+ check(cudaMemcpy(d_gm, gm.data(), gm.size() * 4, cudaMemcpyHostToDevice), "lcm");+ check(cudaMemset(d_z, 0, zdummy.size() * 4), "lz0");+ int lb_bad = 0, lb_n = 0;+ bool launched = true;+ for (int nk = 1; nk <= MT && launched; ++nk) {+ check(cudaMemcpy(d_nk, &nk, 4, cudaMemcpyHostToDevice), "lnk1");+ check(cudaMemcpy(d_a, st0.data(), st0.size() * 4, cudaMemcpyHostToDevice), "lca");+ check(cudaMemcpy(d_b, st0.data(), st0.size() * 4, cudaMemcpyHostToDevice), "lcb2");+ for (int l = 0; l < L; ++l) { // the reference: the per-layer calls+ float* stl = d_a + (size_t) l * stride;+ strata::kernels::gdn_conv_commit(stl + conv_off, d_qkv + (size_t) l * MT * C, C, d_nk, nullptr);+ strata::kernels::gdn_step_norm_multi(stl, d_h + (size_t) l * MT * C, C, d_g + (size_t) l * MT * h_v,+ d_bt + (size_t) l * MT * h_v, d_z, d_gm, 1e-6f, d_y, h_k, h_v, MT, d_nk,+ nullptr, MT);+ }+ launched = strata::kernels::gdn_commit_layers(d_b, stride, conv_off, d_qkv, (int64_t) MT * C, d_h, (int64_t) MT * C,+ d_g, d_bt, (int64_t) MT * h_v, C, h_k, h_v, MT, L, d_nk, nullptr);+ if (!launched) break;+ check(cudaDeviceSynchronize(), "lsync");+ std::vector<float> a(st0.size()), b(st0.size());+ check(cudaMemcpy(a.data(), d_a, a.size() * 4, cudaMemcpyDeviceToHost), "lda");+ check(cudaMemcpy(b.data(), d_b, b.size() * 4, cudaMemcpyDeviceToHost), "ldb");+ ++lb_n;+ if (std::memcmp(a.data(), b.data(), a.size() * 4) != 0 || std::memcmp(a.data(), st0.data(), a.size() * 4) == 0) {+ std::printf(" *** gdn_commit_layers n_keep=%d differs from the per-layer commit (or wrote nothing) ***\n", nk);+ ++lb_bad;+ }+ }+ cudaFree(d_a); cudaFree(d_b); cudaFree(d_h); cudaFree(d_qkv); cudaFree(d_g); cudaFree(d_bt); cudaFree(d_z);+ cudaFree(d_y); cudaFree(d_gm); cudaFree(d_nk);+ if (launched)+ std::printf(" %-42s %s (%d cases, %d layers)\n", "gdn_commit_layers == per-layer commit", lb_bad ? "*** NO ***" : "bitwise",+ lb_n, L);+ else+ std::printf(" %-42s skipped (the per-layer commit is not the state-only kernel here)\n", "gdn_commit_layers");+ bad += lb_bad;+ }+std::printf("\ngdn: %d failures\n", bad);if (bad) return 1;if (selftest) std::printf("gdn_parity OK\n");diff --git a/src/kernels/qsa_parity.cpp b/src/kernels/qsa_parity.cppindex a23f0695d..3508ff38b 100644--- a/src/kernels/qsa_parity.cpp+++ b/src/kernels/qsa_parity.cpp@@ -1455,6 +1455,60 @@ int main(int argc, char** argv) {same ? "bit-identical" : "*** WRONG ***");if (!same) ++g_bad;}+ // engine-latency: native_qsa_indexer_append_steps_layers - the commit's tail restore + append for several+ // layers in one launch - against the per-layer copy + append_steps (3 layers, each its own raw rows, tail+ // snapshot and buffers; cells 2..NB+1 so the first completed block reads the restored tail)+ {+ constexpr int NL = 3;+ Dev<float> pr[NL], dr[NL], tr[NL], pl[NL], dl[NL], tl[NL], src[NL];+ Dev<int32_t> br[NL], bl[NL];+ for (int i = 0; i < NL; ++i) {+ pr[i].alloc(prows); dr[i].alloc((size_t) IDXD); tr[i].alloc(trows);+ pl[i].alloc(prows); dl[i].alloc((size_t) IDXD); tl[i].alloc(trows);+ br[i].alloc(1); bl[i].alloc(1);+ std::vector<float> ts(trows);+ for (auto& x : ts) x = (float) gauss(rng);+ src[i].put(ts);+ }+ for (int i = 0; i < NL; ++i) {+ check(cudaMemset(pr[i].p, 0, prows * 4), "z"); check(cudaMemset(pl[i].p, 0, prows * 4), "z");+ check(cudaMemset(dr[i].p, 0, IDXD * 4), "z"); check(cudaMemset(dl[i].p, 0, IDXD * 4), "z");+ check(cudaMemset(tr[i].p, 0, trows * 4), "z"); check(cudaMemset(tl[i].p, 0, trows * 4), "z");+ check(cudaMemset(br[i].p, 0, 4), "z"); check(cudaMemset(bl[i].p, 0, 4), "z");+ }+ std::vector<float> rawL((size_t) NL * NB * IDXD);+ for (auto& x : rawL) x = (float) gauss(rng);+ Dev<float> drawL;+ drawL.put(rawL);+ Dev<int32_t> dposL((size_t) NB);+ std::vector<int32_t> hp((size_t) NB);+ for (int64_t t = 0; t < NB; ++t) hp[(size_t) t] = (int32_t) (2 + t);+ check(cudaMemcpy(dposL.p, hp.data(), hp.size() * 4, cudaMemcpyHostToDevice), "pos");+ strata::kernels::QsaIndexerLayers il;+ for (int i = 0; i < NL; ++i) { // the reference: copy + append_steps, layer by layer+ check(cudaMemcpyAsync(tr[i].p, src[i].p, trows * 4, cudaMemcpyDeviceToDevice, cs), "cp");+ strata::kernels::QsaIndexerBuffers b{tr[i].p, dr[i].p, pr[i].p, br[i].p};+ strata::kernels::native_qsa_indexer_append_steps(drawL.p + (size_t) i * NB * IDXD, dposL.p, 1, (int) NB, BASE,+ dw_kn.p, EPS, b, S, MC, sc, cs);+ il.gamma[i] = dw_kn.p; il.tail_src[i] = src[i].p; il.tail[i] = tl[i].p; il.dead[i] = dl[i].p;+ il.pooled[i] = pl[i].p; il.block_pos[i] = bl[i].p;+ }+ strata::kernels::native_qsa_indexer_append_steps_layers(drawL.p, (int64_t) NB * IDXD, dposL.p, 1, (int) NB, BASE,+ EPS, il, NL, S, MC, sc, cs);+ check(cudaStreamSynchronize(cs), "sync");+ bool same = true;+ for (int i = 0; i < NL; ++i) {+ const std::vector<float> a1 = pr[i].get(prows), b1 = pl[i].get(prows), a2 = dr[i].get((size_t) IDXD),+ b2 = dl[i].get((size_t) IDXD), a3 = tr[i].get(trows), b3 = tl[i].get(trows);+ const std::vector<int32_t> a4 = br[i].get(1), b4 = bl[i].get(1);+ same = same && std::memcmp(a1.data(), b1.data(), a1.size() * 4) == 0 &&+ std::memcmp(a2.data(), b2.data(), a2.size() * 4) == 0 &&+ std::memcmp(a3.data(), b3.data(), a3.size() * 4) == 0 && a4[0] == b4[0];+ }+ std::printf(" %-44s %s\n", (std::string("append_steps_layers (3) vs per layer, ") + var.name).c_str(),+ same ? "bit-identical" : "*** WRONG ***");+ if (!same) ++g_bad;+ }check(cudaStreamSynchronize(cs), "sync");const std::vector<float> pa = pooledA.get(prows), pb = pooledB.get(prows);const std::vector<float> da = deadA.get((size_t) IDXD), db = deadB.get((size_t) IDXD);