Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions engine/src/poly/inkling2.cu
Original file line number Diff line number Diff line change
Expand Up @@ -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 <class T>
__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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
}
}

Expand Down
Loading