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

test: cover exact multi-row and fused HIP paths on gfx906

0FL01557b79e78f8f
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e28abd9b0..6a7baf78a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -878,6 +878,21 @@ if(STRATA_ENABLE_CUDA OR STRATA_ENABLE_HIP)
target_include_directories(native_grouped_parity PRIVATE ${_strata_gpu_include_directories})
target_link_libraries(native_grouped_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target})
add_test(NAME native_grouped_parity COMMAND native_grouped_parity)
+ add_executable(mmvf_rows_parity src/kernels/mmvf_rows_parity.cpp)
+ target_include_directories(mmvf_rows_parity PRIVATE ${_strata_gpu_include_directories})
+ target_link_libraries(mmvf_rows_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target})
+ add_test(NAME mmvf_rows_parity COMMAND mmvf_rows_parity)
+ set_tests_properties(mmvf_rows_parity PROPERTIES ENVIRONMENT "STRATA_MMVF_ROWS=1" TIMEOUT 120)
+ if(STRATA_HIP_GFX906)
+ add_test(NAME native_grouped_fused_parity COMMAND native_grouped_parity)
+ set_tests_properties(native_grouped_fused_parity PROPERTIES
+ ENVIRONMENT "STRATA_HIP_SWIGLU_FUSED=1;STRATA_EXP_MODE=7" TIMEOUT 120)
+ add_executable(gfx906_gdn_rec_head tests/hip/gdn_rec_head.cpp)
+ target_include_directories(gfx906_gdn_rec_head PRIVATE ${_strata_gpu_include_directories})
+ target_link_libraries(gfx906_gdn_rec_head PRIVATE strata_prefill ${_strata_gpu_runtime_target})
+ add_test(NAME gfx906_gdn_rec_head COMMAND gfx906_gdn_rec_head)
+ set_tests_properties(gfx906_gdn_rec_head PROPERTIES TIMEOUT 120)
+ endif()
add_executable(shared_expert_parity src/kernels/shared_expert_parity.cpp)
target_include_directories(shared_expert_parity PRIVATE ${_strata_gpu_include_directories})
target_link_libraries(shared_expert_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target})
diff --git a/src/kernels/mmvf_rows_parity.cpp b/src/kernels/mmvf_rows_parity.cpp
new file mode 100644
index 000000000..189f56109
--- /dev/null
+++ b/src/kernels/mmvf_rows_parity.cpp
@@ -0,0 +1,76 @@
+// Exact multi-row BF16/F32 GEMV checks against independent single-row calls.
+// Run with STRATA_MMVF_ROWS=1; synthetic data, no model or private prompts.
+#include "strata/kernels/bf16_gemv.hpp"
+#include <cuda_runtime.h>
+#include <cstdint>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+#include <random>
+#include <vector>
+
+namespace k = strata::kernels;
+static void ck(cudaError_t e) {
+ if (e != cudaSuccess) { std::fprintf(stderr, "%s\n", cudaGetErrorString(e)); std::exit(2); }
+}
+template<class T> static T* alloc(size_t n) {
+ T* p = nullptr; ck(cudaMalloc(&p, n * sizeof(T))); return p;
+}
+int main() {
+ const char* flag = std::getenv("STRATA_MMVF_ROWS");
+ if (!flag || flag[0] != '1') { std::fprintf(stderr, "set STRATA_MMVF_ROWS=1\n"); return 2; }
+ cudaStream_t s; ck(cudaStreamCreate(&s));
+ const int shapes[][2] = {{64,64},{192,67},{512,65},{640,128},{2560,48},
+ {2560,128},{2560,512},{2560,2560},{10240,320}};
+ size_t cases = 0, values = 0, mismatches = 0;
+ for (const auto& shape : shapes) for (int nt = 1; nt <= 8; ++nt)
+ for (int pad : {0,2}) for (int range : {0,1,2}) {
+ const int ni = shape[0], no = shape[1], ldx = ni + pad, ldy = no + pad + 1;
+ std::mt19937 rng(1234 + nt * 17 + pad * 31 + range * 53 + ni + no);
+ std::uniform_real_distribution<float> d(-1.f, 1.f);
+ const float xs = range == 0 ? 1.f : range == 1 ? 1.e-12f : 1.e12f;
+ const float ws = range == 0 ? 1.f : range == 1 ? 1.e-8f : 1.e8f;
+ std::vector<float> x((size_t) nt * ldx);
+ std::vector<uint16_t> w((size_t) (no + 1) * ni);
+ for (auto& v : x) v = d(rng) * xs;
+ for (auto& v : w) { const float f = d(rng) * ws; uint32_t b; std::memcpy(&b,&f,4); v = uint16_t(b >> 16); }
+ float* dx = alloc<float>(x.size()); uint16_t* dw = alloc<uint16_t>(w.size());
+ const size_t count = (size_t) nt * ldy;
+ float* ref = alloc<float>(count); float* got = alloc<float>(count);
+ float* aux = alloc<float>((size_t)nt * 3); float* aref = alloc<float>((size_t)nt * 3);
+ ck(cudaMemcpy(dx,x.data(),x.size()*4,cudaMemcpyHostToDevice));
+ ck(cudaMemcpy(dw,w.data(),w.size()*2,cudaMemcpyHostToDevice));
+ ck(cudaMemset(ref,0xff,count*4)); ck(cudaMemset(got,0xff,count*4));
+ ck(cudaMemset(aux,0xff,(size_t)nt*12)); ck(cudaMemset(aref,0xff,(size_t)nt*12));
+ for (int t = 0; t < nt; ++t) {
+ k::bf16_gemv_fp32_mmvf(dx+(size_t)t*ldx,dw,ref+(size_t)t*ldy,ni,no,s);
+ k::bf16_gemv_fp32_mmvf(dx+(size_t)t*ldx,dw+(size_t)no*ni,aref+t*3,ni,1,s);
+ }
+ ck(cudaStreamSynchronize(s));
+ cudaGraph_t graph; cudaGraphExec_t exec;
+ ck(cudaStreamBeginCapture(s,cudaStreamCaptureModeThreadLocal));
+ k::bf16_gemv_fp32_mmvf_multi(dx,ldx,dw,got,ldy,ni,no,nt,s);
+ ck(cudaStreamEndCapture(s,&graph)); ck(cudaGraphInstantiate(&exec,graph,0));
+ ck(cudaGraphLaunch(exec,s)); ck(cudaStreamSynchronize(s));
+ auto compare = [&](float* a, float* b, size_t n) {
+ std::vector<uint32_t> aa(n),bb(n);
+ ck(cudaMemcpy(aa.data(),a,n*4,cudaMemcpyDeviceToHost));
+ ck(cudaMemcpy(bb.data(),b,n*4,cudaMemcpyDeviceToHost));
+ size_t bad = 0; for (size_t i=0;i<n;++i) bad += aa[i]!=bb[i];
+ values += n; mismatches += bad;
+ if (bad) std::printf("FAIL ni=%d no=%d nt=%d pad=%d range=%d different=%zu\n",ni,no,nt,pad,range,bad);
+ };
+ compare(ref,got,count);
+ ck(cudaMemset(got,0xff,count*4));
+ const bool fused = k::bf16_gemv_fp32_mmvf_multi_aux(dx,ldx,dw,got,ldy,ni,no,nt,
+ dw+(size_t)no*ni,aux,3,s);
+ if (fused) { ck(cudaStreamSynchronize(s)); compare(ref,got,count); compare(aref,aux,(size_t)nt*3); }
+ if (fused != (nt >= 2 && no >= 64)) { std::printf("FAIL eligibility\n"); ++mismatches; }
+ ck(cudaGraphExecDestroy(exec)); ck(cudaGraphDestroy(graph));
+ ck(cudaFree(dx)); ck(cudaFree(dw)); ck(cudaFree(ref)); ck(cudaFree(got)); ck(cudaFree(aux)); ck(cudaFree(aref));
+ ++cases;
+ }
+ ck(cudaStreamDestroy(s));
+ std::printf("mmvf_rows_parity: %zu cases, %zu values, %zu mismatches\n",cases,values,mismatches);
+ return mismatches ? 1 : 0;
+}
diff --git a/src/kernels/native_grouped_parity.cpp b/src/kernels/native_grouped_parity.cpp
index 270de2cb6..67b6e67a3 100644
--- a/src/kernels/native_grouped_parity.cpp
+++ b/src/kernels/native_grouped_parity.cpp
@@ -99,6 +99,7 @@ std::vector<uint8_t> random_rows(int t, int64_t rows, int64_t n, std::mt19937& r
struct Setup {
k::NativeExpertLayout L;
int T = 0, K = 0, cap = 0, n_blobs = 0;
+ int active_lo = 0, active_hi = 0;
size_t slot = 0;
uint8_t* blobs = nullptr;
uint8_t* xq = nullptr;
@@ -174,6 +175,8 @@ struct Setup {
}
if (st.back() > cap) { std::fprintf(stderr, "plan: %d entries > cap %d\n", st.back(), cap); std::exit(2); }
const int ng = (int) p.size();
+ active_lo = base;
+ active_hi = st.back();
std::iota(ds.begin(), ds.end(), 0);
std::shuffle(ds.begin(), ds.end(), rng); // scattered rows of `out`
for (int e = 0; e < cap; ++e) tk_v.push_back(tk(rng));
@@ -197,6 +200,15 @@ struct Setup {
ck(cudaStreamSynchronize(s), "sync");
std::vector<uint32_t> o(out_floats);
ck(cudaMemcpy(o.data(), out, o.size() * 4, cudaMemcpyDeviceToHost), "out");
+ // Fused SwiGLU does not write h or inactive Q8 rows. Compare only the
+ // active Q8_1 bytes, appended after the full output (including padding).
+ const size_t fa = ((size_t) cap * L.n_ff * sizeof(float) + 255) & ~(size_t) 255;
+ const size_t qrow = (size_t) (L.n_ff / 32) * 36;
+ const size_t qb = (size_t) (active_hi - active_lo) * qrow;
+ const size_t old = o.size();
+ o.resize(old + qb / sizeof(uint32_t));
+ if (qb)
+ ck(cudaMemcpy(o.data() + old, scr + 3 * fa + active_lo * qrow, qb, cudaMemcpyDeviceToHost), "active hq");
return o;
}
};
@@ -210,7 +222,7 @@ void check(int gu, int dt, int64_t H, int64_t FF, cudaStream_t s, std::mt19937&
const int ng = S.plan(groups, base, rng);
const auto ref = S.result(true, 0, 0x00, s);
size_t w = 0;
- for (const uint32_t v : ref) w += v != 0xFFFFFFFFu;
+ for (size_t i = 0; i < S.out_floats; ++i) w += ref[i] != 0xFFFFFFFFu;
written += w;
for (const int64_t gy : {(int64_t) 0, (int64_t) 1, (int64_t) 2, (int64_t) 3, (int64_t) 4, (int64_t) S.cap + 3}) {
const auto got = S.result(false, gy, (calls & 1) ? 0x7F : 0x00, s);
@@ -218,7 +230,7 @@ void check(int gu, int dt, int64_t H, int64_t FF, cudaStream_t s, std::mt19937&
size_t diff = 0;
for (size_t i = 0; i < ref.size(); ++i) diff += ref[i] != got[i];
if (diff) {
- std::printf(" %-8s/%-7s base %d, %d groups, grid_groups %lld: %zu of %zu floats differ FAIL\n",
+ std::printf(" %-8s/%-7s base %d, %d groups, grid_groups %lld: %zu of %zu output/Q8 words differ FAIL\n",
name_of(gu), name_of(dt), base, ng, (long long) gy, diff, ref.size());
++bad;
}
@@ -347,6 +359,7 @@ int main(int argc, char** argv) {
#endif
8}) // STRATA_GU_FMTS
for (int dt : {20, 23, 42, 7, 8}) check(gu, dt, 512, 256, s, rng); // STRATA_D_FMTS; IQ4_XS: n_ff % 256
+ check(42, 42, 2560, 640, s, rng);
check(21, 20, 2560, 640, s, rng); // a model's shapes
check(21, 23, 2560, 768, s, rng);
if (do_bench) bench(s, rng);