From 325c4dd8cbd51decb94d67d0a70716f23a2257ce Mon Sep 17 00:00:00 2001 From: Shogo Okada <33060490+okada-shogo@users.noreply.github.com> Date: Tue, 24 Nov 2026 05:13:58 +0900 Subject: [PATCH] poly: Inkling 2's norm kernels without their parameters in local memory ink_cat_norm_kernel (the loop controllers' norms in a prompt, three pairs a launch) and ink_norm_many_q8_kernel (a token's three norms of a full layer's inputs) took their pointers as p[blockIdx.y]: an index into the kernel's parameters by a register, which nvcc compiles as a copy of the whole struct to local memory in every block (nine and twelve STL.64 on sm_75), and the loads through the pointers read back from there became generic loads (60 LD in ink_cat_norm_kernel) instead of global ones. ink_pick() picks the pointer by comparisons. Nothing else changes: the same threads add the same values in the same order, so the same bits. (rms_norm_many_kernel in kernels.cu has the same pattern; a separate change.) Co-Authored-By: Claude Opus 5.5 --- engine/src/poly/inkling2.cu | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/engine/src/poly/inkling2.cu b/engine/src/poly/inkling2.cu index c5d726639..2a7d0a09a 100644 --- a/engine/src/poly/inkling2.cu +++ b/engine/src/poly/inkling2.cu @@ -557,12 +557,20 @@ __device__ __forceinline__ void cat_squares(const float* cur, const float* msg, __device__ __forceinline__ float cat_scale(float sum, int n_embd) { return 1.0f / sqrtf(sum / (float) n_embd + 1e-6f); } +// Entry j of a launch's array of 3 pointers, picked by comparisons: indexed by a register (p[blockIdx.y]), the +// kernel's parameters were copied to local memory by every block and the loads through the pointers read back from +// there were generic ones, not read-only global loads. +template +__device__ __forceinline__ T ink_pick(const T (&p)[3], int j) { + return j == 0 ? p[0] : j == 1 ? p[1] : p[2]; +} + // A token's pair a block, blockIdx.y the pair. __global__ void ink_cat_norm_kernel(CatNormSet s, int n_embd) { __shared__ float part[kCatThreads / WARP]; - const float* __restrict__ cur = s.cur[blockIdx.y]; - const float* __restrict__ msg = s.msg[blockIdx.y]; - float* __restrict__ out = s.out[blockIdx.y]; + const float* __restrict__ cur = ink_pick(s.cur, blockIdx.y); + const float* __restrict__ msg = ink_pick(s.msg, blockIdx.y); + float* __restrict__ out = ink_pick(s.out, blockIdx.y); const size_t row = size_t(blockIdx.x) * n_embd; const int tid = threadIdx.x; float a, b; @@ -2736,9 +2744,10 @@ __global__ void ink_norm_many_q8_kernel(NormMany m, int n, float eps) { pdl_trigger(); // PDL (pdl.hpp): the launch after this one may start pdl_wait(); __shared__ float part[32]; - const float* xr = m.x[blockIdx.y]; - const float* __restrict__ w = m.w[blockIdx.y]; - float* yr = m.y[blockIdx.y]; + const float* xr = ink_pick(m.x, blockIdx.y); + const float* __restrict__ w = ink_pick(m.w, blockIdx.y); + float* yr = ink_pick(m.y, blockIdx.y); + QB* const q = ink_pick(m.q, blockIdx.y); if (n <= kNormHeld * int(blockDim.x)) { // the values read once and kept for the norm float v[kNormHeld]; float ss = 0.0f; @@ -2758,7 +2767,7 @@ __global__ void ink_norm_many_q8_kernel(NormMany m, int n, float eps) { if (i < n) { const float y = w ? v[h] * scale * w[i] : v[h] * scale; yr[i] = y; - q8_put(m.q[blockIdx.y], i, y); + q8_put(q, i, y); } } return; @@ -2770,7 +2779,7 @@ __global__ void ink_norm_many_q8_kernel(NormMany m, int n, float eps) { for (int i = threadIdx.x; i < n; i += blockDim.x) { const float y = w ? xr[i] * scale * w[i] : xr[i] * scale; yr[i] = y; - q8_put(m.q[blockIdx.y], i, y); + q8_put(q, i, y); } }