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

#2091 sm_75: the hyper-connection xn16 written as the FP16 its tensor-core GEMMs read (bitwise)

Rafa8bdef963cc0e
diff --git a/include/strata/prefill/gemm.hpp b/include/strata/prefill/gemm.hpp
index 0740fd0d2..4d8cbebcf 100644
--- a/include/strata/prefill/gemm.hpp
+++ b/include/strata/prefill/gemm.hpp
@@ -28,8 +28,12 @@ public:
/// Y[T, N] (fp32, row stride ldy) = X[T, K] (bf16, row-major) . W[N, K]^T (bf16, row-major). `beta` = 1 adds.
/// Below sm_80 (no BF16 tensor cores): Volta converts both to FP16 and runs the FP16 tensor-core GEMM (Turing with
/// STRATA_BF16_TC=1), Pascal widens both to fp32 (cublasSgemm); see gemm.cu.
+ /// `x_f16`: X holds, instead of BF16, the FP16 values the Turing tensor-core path would convert it to
+ /// (prefill's xn16 with its f16img writers): that path skips the conversion; any other converts back.
void bf16(const uint16_t* X, const uint16_t* W, float* Y, int64_t T, int64_t N, int64_t K, int64_t ldy = 0,
- float beta = 0.0f, int64_t ldx = 0);
+ float beta = 0.0f, int64_t ldx = 0, bool x_f16 = false);
+ /// true when bf16() runs its products through FP16 tensor cores here (Turing, STRATA_BF16_TC): where X may be FP16
+ bool bf16_converts_x() const;
/// S (STRATA_HCD_EXACT): the HC down projection (N 320, K 10240) by the WMMA kernel that reproduces hipBLASLt's
/// solution 1176 / 1177 bit for bit; false (nothing launched) unless hipBLASLt would take one of those for this
diff --git a/include/strata/prefill/kernels.hpp b/include/strata/prefill/kernels.hpp
index f12f34b94..8e16467a3 100644
--- a/include/strata/prefill/kernels.hpp
+++ b/include/strata/prefill/kernels.hpp
@@ -16,10 +16,10 @@ namespace strata::prefill {
/// xn[t, c*2560 + d] = R[t,c,d] * rsqrt(mean_d R[t,c,:]^2 + eps) * w_norm[c*2560 + d]; also its BF16 image.
/// `xn16_lo` (null: none) takes bf16(x - xn16): W.xn16 + W.xn16_lo is the product with ~16 mantissa bits of x.
void gr_norm(const float* R, const float* w_norm, float eps, float* xn, uint16_t* xn16, int64_t T, void* stream,
- uint16_t* xn16_lo = nullptr);
+ uint16_t* xn16_lo = nullptr, bool f16img = false);
/// F-1: gr_norm without its FP32 output: the row scales rs[t*4 + c] and the BF16 image; gr_mix_r then reads R.
void gr_norm_rs(const float* R, const float* w_norm, float eps, float* rs, uint16_t* xn16, int64_t T, void* stream,
- uint16_t* xn16_lo = nullptr, int64_t ldx = 0); // ldx: xn16's token stride (0 = 10240)
+ uint16_t* xn16_lo = nullptr, int64_t ldx = 0, bool f16img = false); // ldx: xn16's token stride (0 = 10240)
/// gr_mix with xn recomputed from R, rs and w_norm exactly as gr_norm computes it (the same bits).
void gr_mix_r(const float* R, const float* rs, const float* w_norm, const float* gated, float* mixed, uint16_t* mixed16,
int64_t T, void* stream, uint16_t* mixed_h = nullptr, uint16_t* mixed16_lo = nullptr);
@@ -31,13 +31,13 @@ bool gr_upmix(const uint16_t* lo16, const uint16_t* w_up, const float* R, const
float* mixed, uint16_t* mixed16, uint16_t* mixed_h, int64_t T, void* stream);
void gr_write_norm_rs(float* R, const float* bo, const float* inj, int64_t inj_ld, const float* w_norm_next, float eps,
float* rs, uint16_t* xn16, int64_t T, void* stream, uint16_t* xn16_lo = nullptr,
- int64_t ldx = 0);
+ int64_t ldx = 0, bool f16img = false);
/// S23 (STRATA_CVEC_FUSE=1): gr_write, then the control vector (v_l = layer l's direction row, *s_l its scale,
/// *on the request flag, mode 0 project / 1 add; cvec_kernel's arithmetic), then gr_norm_rs with the next half's
/// norm - one pass over R, the same bits as the three kernels.
void gr_write_cvec_norm_rs(float* R, const float* bo, const float* inj, int64_t inj_ld, const float* v_l,
const float* s_l, const int* on, int mode, const float* w_norm_next, float eps, float* rs,
- uint16_t* xn16, int64_t T, void* stream, uint16_t* xn16_lo = nullptr, int64_t ldx = 0);
+ uint16_t* xn16, int64_t T, void* stream, uint16_t* xn16_lo = nullptr, int64_t ldx = 0, bool f16img = false);
/// lo16[t, k] = bf16(silu(lo[t, k] / hc))
void gr_silu(const float* lo, uint16_t* lo16, int64_t T, void* stream, uint16_t* lo16_lo = nullptr);
/// The BF16-weight GEMMs' activation image (gr_* kernels, to_bf16) in FP16 instead of BF16, on the current device.
diff --git a/src/prefill/gemm.cu b/src/prefill/gemm.cu
index 300da53b7..9ad9eb105 100644
--- a/src/prefill/gemm.cu
+++ b/src/prefill/gemm.cu
@@ -621,8 +621,19 @@ bool Gemm::bf16_hcd_exact(const uint16_t* X, int64_t ldx, const uint16_t* W, flo
#endif
}
+bool Gemm::bf16_converts_x() const {
+#if defined(__HIPCC__) || defined(STRATA_EXPERIMENTAL_SM60)
+ return false;
+#else
+ return bf16_path() == 1;
+#endif
+}
+__global__ void f16_to_bf16_kernel(const __half* __restrict__ in, uint16_t* __restrict__ out, int64_t n) {
+ const int64_t i = (int64_t) blockIdx.x * blockDim.x + threadIdx.x;
+ if (i < n) out[i] = (uint16_t) (__float_as_uint(__half2float(in[i])) >> 16); // exact: the value was a BF16
+}
void Gemm::bf16(const uint16_t* X, const uint16_t* W, float* Y, int64_t T, int64_t N, int64_t K, int64_t ldy,
- float beta, int64_t ldx) {
+ float beta, int64_t ldx, bool x_f16) {
if (T <= 0 || N <= 0) return;
if (ldy <= 0) ldy = N;
if (ldx <= K) ldx = 0;
@@ -708,14 +719,34 @@ void Gemm::bf16(const uint16_t* X, const uint16_t* W, float* Y, int64_t T, int64
bf16_to_f16(W + n0 * K, tc_w_, nn * K, (cudaStream_t) stream_);
for (int64_t t0 = 0; t0 < T; t0 += x_rows) {
const int64_t n = std::min<int64_t>(x_rows, T - t0);
- bf16_to_f16(X + t0 * K, tc_x_, n * K, (cudaStream_t) stream_);
- f16(tc_x_, tc_w_, Y + t0 * ldy + n0, n, nn, K, ldy, beta);
+ if (x_f16) { // already the converted values (the same slices: the same GEMMs)
+ f16(X + t0 * K, tc_w_, Y + t0 * ldy + n0, n, nn, K, ldy, beta);
+ } else {
+ bf16_to_f16(X + t0 * K, tc_x_, n * K, (cudaStream_t) stream_);
+ f16(tc_x_, tc_w_, Y + t0 * ldy + n0, n, nn, K, ldy, beta);
+ }
}
}
}
return;
}
}
+#endif
+#if !defined(__HIPCC__)
+ if (x_f16) { // not the tensor-core path after all (one output row, or no room): X back to BF16, a slice at a time
+ const int64_t x_rows = std::max<int64_t>(1, std::min<int64_t>(T, kXSliceElems / K));
+ if (!grow(tc_x_, tc_x_elems_, x_rows * K)) {
+ std::fprintf(stderr, "prefill gemm: no GPU memory for converting an FP16 image back to BF16\n");
+ std::exit(1);
+ }
+ for (int64_t t0 = 0; t0 < T; t0 += x_rows) {
+ const int64_t n = std::min<int64_t>(x_rows, T - t0);
+ f16_to_bf16_kernel<<<(unsigned) ((n * K + 255) / 256), 256, 0, (cudaStream_t) stream_>>>(
+ reinterpret_cast<const __half*>(X + t0 * K), tc_x_, n * K);
+ bf16(tc_x_, W, Y + t0 * ldy, n, N, K, ldy, beta, 0, false);
+ }
+ return;
+ }
#endif
// Column-major view: Y^T[N, T] = W[N, K] (stored K x N col-major, transposed) . X^T[K, T].
ck(cublasGemmEx((cublasHandle_t) handle_, CUBLAS_OP_T, CUBLAS_OP_N, (int) N, (int) T, (int) K, &alpha, W,
diff --git a/src/prefill/kernels.cu b/src/prefill/kernels.cu
index f58a189c6..50178462a 100644
--- a/src/prefill/kernels.cu
+++ b/src/prefill/kernels.cu
@@ -45,6 +45,14 @@ __device__ __forceinline__ uint16_t hf(float f) { return __half_as_ushort(__floa
// A SwiGLU product for an FP16 GEMM: saturated, so a token with a massive activation cannot turn into inf and then
// NaN in the down projection (decode's q8_1 has room to ~8e6; FP16 ends at 65504). A NaN stays NaN (fminf/fmaxf
// would make it -65504 and hide where it came from); finite values below 65504 round exactly as before.
+// Turing's FP16 image of the hyper-connection's xn16 (gemm.cu's bf16_to_f16_kernel applied to a BF16 value): the
+// writers store what the BF16 tensor-core path would convert, so the GEMM reads it without a conversion pass
+__device__ __forceinline__ uint16_t bf_to_hf_conv(uint16_t b) {
+ float f = __uint_as_float((uint32_t) b << 16);
+ if (f > 65504.0f && !isinf(f)) f = 65504.0f;
+ else if (f < -65504.0f && !isinf(f)) f = -65504.0f;
+ return __half_as_ushort(__float2half_rn(f));
+}
__device__ __forceinline__ uint16_t hf_sat(float f) { return hf(isnan(f) ? f : fminf(fmaxf(f, -65504.0f), 65504.0f)); }
// The prompt path's 16-bit activation image for the BF16-weight GEMMs: BF16, or FP16 where the GEMM library is fast
// only in FP16 (prompt_f16() in gemm.cu: rocBLAS on gfx103x). Set once per device before the first prompt.
@@ -76,7 +84,8 @@ unsigned blocks_for(int64_t n, int t = 256) { return (unsigned) ((n + t - 1) / t
// ---------------------------------------------------------------- hyper-connection
__global__ void gr_norm_kernel(const float* __restrict__ R, const float* __restrict__ w, float eps,
- float* __restrict__ xn, uint16_t* __restrict__ xn16, uint16_t* __restrict__ xn16_lo) {
+ float* __restrict__ xn, uint16_t* __restrict__ xn16, uint16_t* __restrict__ xn16_lo,
+ int f16img) {
__shared__ float sh[32];
const int64_t row = blockIdx.x; // t * 4 + c
const int c = (int) (row % HC);
@@ -88,7 +97,7 @@ __global__ void gr_norm_kernel(const float* __restrict__ R, const float* __restr
const float v = r[d] * rs * w[c * N + d];
xn[row * N + d] = v;
const uint16_t h = act16(v);
- xn16[row * N + d] = h;
+ xn16[row * N + d] = f16img ? bf_to_hf_conv(h) : h;
if (xn16_lo) xn16_lo[row * N + d] = bf_lo(v, h);
}
}
@@ -96,7 +105,7 @@ __global__ void gr_norm_kernel(const float* __restrict__ R, const float* __restr
// so the FP32 copy of the normalized rows (T x 10240 floats) is neither written nor read
__global__ void gr_norm_rs_kernel(const float* __restrict__ R, const float* __restrict__ w, float eps,
float* __restrict__ rs_out, uint16_t* __restrict__ xn16,
- uint16_t* __restrict__ xn16_lo, int64_t ldx) {
+ uint16_t* __restrict__ xn16_lo, int64_t ldx, int f16img) {
__shared__ float sh[32];
const int64_t row = blockIdx.x; // t * 4 + c
const int c = (int) (row % HC);
@@ -109,7 +118,7 @@ __global__ void gr_norm_rs_kernel(const float* __restrict__ R, const float* __re
for (int d = threadIdx.x; d < N; d += blockDim.x) {
const float v = r[d] * rs * w[c * N + d];
const uint16_t h = act16(v);
- xn16[xo + d] = h;
+ xn16[xo + d] = f16img ? bf_to_hf_conv(h) : h;
if (xn16_lo) xn16_lo[xo + d] = bf_lo(v, h);
}
}
@@ -143,7 +152,7 @@ __global__ void __launch_bounds__(256) gr_write_norm_rs_kernel(float* __restrict
const float* __restrict__ inj, int64_t inj_ld,
const float* __restrict__ w, float eps,
float* __restrict__ rs_out, uint16_t* __restrict__ xn16,
- uint16_t* __restrict__ xn16_lo, int64_t ldx) {
+ uint16_t* __restrict__ xn16_lo, int64_t ldx, int f16img) {
__shared__ float sh[32];
const int64_t row = blockIdx.x; // t * 4 + c
const int64_t t = row / HC;
@@ -168,7 +177,7 @@ __global__ void __launch_bounds__(256) gr_write_norm_rs_kernel(float* __restrict
for (int d = threadIdx.x; d < N; d += 256, ++k) {
const float x = v[k] * rs * w[c * N + d];
const uint16_t h = act16(x);
- xn16[xo + d] = h;
+ xn16[xo + d] = f16img ? bf_to_hf_conv(h) : h;
if (xn16_lo) xn16_lo[xo + d] = bf_lo(x, h);
}
}
@@ -180,7 +189,7 @@ __global__ void __launch_bounds__(256) gr_write_cvec_norm_rs_kernel(
float* __restrict__ R, const float* __restrict__ bo, const float* __restrict__ inj, int64_t inj_ld,
const float* __restrict__ v_l, const float* __restrict__ s_l, const int* __restrict__ on, int mode,
const float* __restrict__ w, float eps, float* __restrict__ rs_out, uint16_t* __restrict__ xn16,
- uint16_t* __restrict__ xn16_lo, int64_t ldx) {
+ uint16_t* __restrict__ xn16_lo, int64_t ldx, int f16img) {
__shared__ float sh[32];
__shared__ float part[8];
const int64_t row = blockIdx.x; // t * 4 + c
@@ -230,7 +239,7 @@ __global__ void __launch_bounds__(256) gr_write_cvec_norm_rs_kernel(
for (int d = threadIdx.x; d < N; d += 256, ++k) {
const float y = x[k] * rs * w[c * N + d];
const uint16_t h = act16(y);
- xn16[t * ldx + (int64_t) c * N + d] = h;
+ xn16[t * ldx + (int64_t) c * N + d] = f16img ? bf_to_hf_conv(h) : h;
if (xn16_lo) xn16_lo[t * ldx + (int64_t) c * N + d] = bf_lo(y, h);
}
}
@@ -1844,14 +1853,14 @@ void to_bf16(const float* x, uint16_t* y, int64_t n, void* stream, uint16_t* ylo
}
void gr_norm(const float* R, const float* w_norm, float eps, float* xn, uint16_t* xn16, int64_t T, void* stream,
- uint16_t* xn16_lo) {
- gr_norm_kernel<<<(unsigned) (T * HC), 256, 0, (cudaStream_t) stream>>>(R, w_norm, eps, xn, xn16, xn16_lo);
+ uint16_t* xn16_lo, bool f16img) {
+ gr_norm_kernel<<<(unsigned) (T * HC), 256, 0, (cudaStream_t) stream>>>(R, w_norm, eps, xn, xn16, xn16_lo, f16img ? 1 : 0);
check("gr_norm");
}
void gr_norm_rs(const float* R, const float* w_norm, float eps, float* rs, uint16_t* xn16, int64_t T, void* stream,
- uint16_t* xn16_lo, int64_t ldx) {
+ uint16_t* xn16_lo, int64_t ldx, bool f16img) {
gr_norm_rs_kernel<<<(unsigned) (T * HC), 256, 0, (cudaStream_t) stream>>>(R, w_norm, eps, rs, xn16, xn16_lo,
- ldx > 0 ? ldx : D);
+ ldx > 0 ? ldx : D, f16img ? 1 : 0);
check("gr_norm_rs");
}
void gr_mix_r(const float* R, const float* rs, const float* w_norm, const float* gated, float* mixed, uint16_t* mixed16,
@@ -1881,17 +1890,17 @@ bool gr_upmix(const uint16_t* lo16, const uint16_t* w_up, const float* R, const
#endif
}
void gr_write_norm_rs(float* R, const float* bo, const float* inj, int64_t inj_ld, const float* w_norm_next, float eps,
- float* rs, uint16_t* xn16, int64_t T, void* stream, uint16_t* xn16_lo, int64_t ldx) {
+ float* rs, uint16_t* xn16, int64_t T, void* stream, uint16_t* xn16_lo, int64_t ldx, bool f16img) {
gr_write_norm_rs_kernel<<<(unsigned) (T * HC), 256, 0, (cudaStream_t) stream>>>(R, bo, inj, inj_ld, w_norm_next, eps,
rs, xn16, xn16_lo,
- ldx > 0 ? ldx : D);
+ ldx > 0 ? ldx : D, f16img ? 1 : 0);
check("gr_write_norm_rs");
}
void gr_write_cvec_norm_rs(float* R, const float* bo, const float* inj, int64_t inj_ld, const float* v_l,
const float* s_l, const int* on, int mode, const float* w_norm_next, float eps, float* rs,
- uint16_t* xn16, int64_t T, void* stream, uint16_t* xn16_lo, int64_t ldx) {
+ uint16_t* xn16, int64_t T, void* stream, uint16_t* xn16_lo, int64_t ldx, bool f16img) {
gr_write_cvec_norm_rs_kernel<<<(unsigned) (T * HC), 256, 0, (cudaStream_t) stream>>>(
- R, bo, inj, inj_ld, v_l, s_l, on, mode, w_norm_next, eps, rs, xn16, xn16_lo, ldx > 0 ? ldx : D);
+ R, bo, inj, inj_ld, v_l, s_l, on, mode, w_norm_next, eps, rs, xn16, xn16_lo, ldx > 0 ? ldx : D, f16img ? 1 : 0);
check("gr_write_cvec_norm_rs");
}
void gr_silu(const float* lo, uint16_t* lo16, int64_t T, void* stream, uint16_t* lo16_lo) {
diff --git a/src/prefill/prefill.cpp b/src/prefill/prefill.cpp
index 2fa71c7ce..7fc6319ca 100644
--- a/src/prefill/prefill.cpp
+++ b/src/prefill/prefill.cpp
@@ -773,6 +773,7 @@ struct Prefill::Impl {
float* mixed = nullptr;
uint16_t *mixed_bf = nullptr, *mixed_h = nullptr;
bool f16_io = false; // HIP, STRATA_HIP_PROMPT_F16=1: this stage's 16-bit GEMMs run FP16 in and out (set in init)
+ bool xn_f16 = false; // Turing, BF16 on FP16 tensor cores: xn16 written as the FP16 values the GEMM would convert
uint16_t *xn16_lo = nullptr, *lo16_lo = nullptr, *mixed_bf_lo = nullptr; // bf16x2(): the BF16 GEMMs' low parts
float* bo = nullptr;
// GDN
@@ -1223,6 +1224,10 @@ bool Prefill::init(const core::WeightTable& wt, const core::ModelGeometry& g, co
m.f16_io = prompt_f16();
m.gemm.set_f16_io(m.f16_io);
set_act_f16(m.f16_io);
+ // the hyper-connection's xn16 straight as the FP16 the tensor-core GEMM reads (its two readers then skip the
+ // conversion pass; the same values): STRATA_XN_F16=0 keeps the BF16 image
+ static const bool xn_env = [] { const char* e = std::getenv("STRATA_XN_F16"); return e == nullptr || e[0] != '0'; }();
+ m.xn_f16 = xn_env && !m.f16_io && m.gemm.bf16_converts_x();
}
if (!carve(T, &o)) {
size_t fb = 0, tb = 0;
@@ -1987,9 +1992,9 @@ bool native_proj(Gemm& gm, const core::WeightRef* w, const uint16_t* X, float* Y
return true;
}
bool bf16_proj(Gemm& gm, const core::WeightRef* w, const uint16_t* X, float* Y, int64_t T, const std::string& name,
- std::string& err, int64_t ldy = 0, const uint16_t* X_lo = nullptr, int64_t ldx = 0) {
+ std::string& err, int64_t ldy = 0, const uint16_t* X_lo = nullptr, int64_t ldx = 0, bool x_f16 = false) {
if (w->kind != core::WeightKind::Bf16InF32 || !w->data) { err = "prefill: " + name + " is not a resident BF16 tensor"; return false; }
- gm.bf16(X, (const uint16_t*) w->data, Y, T, w->ne1 > 0 ? w->ne1 : 1, w->ne0, ldy, 0.0f, ldx);
+ gm.bf16(X, (const uint16_t*) w->data, Y, T, w->ne1 > 0 ? w->ne1 : 1, w->ne0, ldy, 0.0f, ldx, x_f16);
if (X_lo) gm.bf16(X_lo, (const uint16_t*) w->data, Y, T, w->ne1 > 0 ? w->ne1 : 1, w->ne0, ldy, 1.0f);
return true;
}
@@ -2617,8 +2622,9 @@ bool Prefill::run_impl(const int64_t* tokens, int64_t n, int64_t pos0, std::stri
// the xn16 token stride of this chunk (the writers of both halves and of the fused write-backs use it)
const int64_t ldx = hc_pad() && T >= std::max<int64_t>(pf_switch_min_t(), 64) && !gr_unfused() &&
!m.xn16_lo ? D + XN_PAD : D;
- if (gr_unfused()) gr_norm(m.R, (const float*) wn->data, EPS, m.xn, m.xn16, T, m.cs, m.xn16_lo);
- else if (!normed) gr_norm_rs(m.R, (const float*) wn->data, EPS, m.grs, m.xn16, T, m.cs, m.xn16_lo, ldx);
+ const bool xf16 = m.xn_f16 && !m.xn16_lo && ldx == D; // xn16 holds FP16 (its writers and readers below)
+ if (gr_unfused()) gr_norm(m.R, (const float*) wn->data, EPS, m.xn, m.xn16, T, m.cs, m.xn16_lo, xf16);
+ else if (!normed) gr_norm_rs(m.R, (const float*) wn->data, EPS, m.grs, m.xn16, T, m.cs, m.xn16_lo, ldx, xf16);
normed = false;
bool hcd = false;
bool hdown = false;
@@ -2635,7 +2641,7 @@ bool Prefill::run_impl(const int64_t* tokens, int64_t n, int64_t pos0, std::stri
}
hcd = true;
}
- if (!hcd && !hdown && !bf16_proj(m.gemm, wd, m.xn16, m.lo, T, sd, err, 0, m.xn16_lo, ldx != D ? ldx : 0)) return false;
+ if (!hcd && !hdown && !bf16_proj(m.gemm, wd, m.xn16, m.lo, T, sd, err, 0, m.xn16_lo, ldx != D ? ldx : 0, xf16)) return false;
gr_silu(m.lo, m.lo16, T, m.cs, m.lo16_lo);
bool upmixed = false;
if (hc_upmix() && T >= pf_switch_min_t() && !gr_unfused() && !m.lo16_lo && !m.mixed_bf_lo &&
@@ -2665,7 +2671,7 @@ bool Prefill::run_impl(const int64_t* tokens, int64_t n, int64_t pos0, std::stri
}
}
if (!upmixed && !bf16_proj(m.gemm, wu, m.lo16, m.gated, T, su, err, 0, m.lo16_lo)) return false;
- if (!hcd && !bf16_proj(m.gemm, wi, m.xn16, m.inj, T, si, err, 0, m.xn16_lo, ldx != D ? ldx : 0)) return false;
+ if (!hcd && !bf16_proj(m.gemm, wi, m.xn16, m.inj, T, si, err, 0, m.xn16_lo, ldx != D ? ldx : 0, xf16)) return false;
if (upmixed) {
} else if (gr_unfused()) {
gr_mix(m.xn, m.gated, m.mixed, m.mixed_bf, T, m.cs, m.mixed_h, m.mixed_bf_lo);
@@ -4110,10 +4116,10 @@ bool Prefill::run_impl(const int64_t* tokens, int64_t n, int64_t pos0, std::stri
cudaMemcpyAsync(Rc, m.R, (size_t) T * D * 4, cudaMemcpyDeviceToDevice, m.cs);
gr_write(Rc, m.bo, m.inj, HC, T, m.cs);
strata::kernels::cvec_apply(Rc, l, T, D, nullptr, 0, nullptr, 0, false, m.cs);
- gr_norm_rs(Rc, (const float*) wnn->data, EPS, rc, xc, T, m.cs, nullptr, D);
+ gr_norm_rs(Rc, (const float*) wnn->data, EPS, rc, xc, T, m.cs, nullptr, D, xf16);
gr_write_cvec_norm_rs(m.R, m.bo, m.inj, HC, cv_dir + l * N, cv_s + l, cv_on,
strata::kernels::cvec().mode, (const float*) wnn->data, EPS, m.grs,
- m.xn16, T, m.cs, m.xn16_lo, ldx);
+ m.xn16, T, m.cs, m.xn16_lo, ldx, xf16);
std::vector<float> a((size_t) T * D), b((size_t) T * D), ra((size_t) T * HC), rb((size_t) T * HC);
std::vector<uint16_t> xa((size_t) T * D), xb((size_t) T * D);
cudaMemcpyAsync(a.data(), m.R, a.size() * 4, cudaMemcpyDeviceToHost, m.cs);
@@ -4132,11 +4138,11 @@ bool Prefill::run_impl(const int64_t* tokens, int64_t n, int64_t pos0, std::stri
} else
gr_write_cvec_norm_rs(m.R, m.bo, m.inj, HC, cv_dir + l * N, cv_s + l, cv_on,
strata::kernels::cvec().mode, (const float*) wnn->data, EPS, m.grs, m.xn16,
- T, m.cs, m.xn16_lo, ldx);
+ T, m.cs, m.xn16_lo, ldx, xf16);
normed = true;
} else if (wnn) {
gr_write_norm_rs(m.R, m.bo, m.inj, HC, (const float*) wnn->data, EPS, m.grs, m.xn16, T, m.cs,
- m.xn16_lo, ldx);
+ m.xn16_lo, ldx, xf16);
normed = true;
} else {
gr_write(m.R, m.bo, m.inj, HC, T, m.cs);