Skip to content

armgit / janas

Public Imported from GitHub
0

37 tok/s from Qwen3-Next-80B (48 GB) on a 32 GB laptop, 24 without drafts vs 2.8 for llama.cpp; reading 62 vs 16 tok/s. Faster than llama.cpp on all 13 models compared in Q4_K_M. LLMs bigger than your RAM, pure C, CPU or GPU.

2.2 KB
Raw Blame
/* SPDX-License-Identifier: GPL-3.0-or-later
   Copyright (C) 2026 Maurizio Cammalleri */
#version 450
// A Gated DeltaNet layer of the whole block on the GPU (gpu_token.c), its
// first step: the causal convolution of the q|k|v channels, then SiLU, as
// model_rec.c's conv_head does - out[t][c] = SiLU(sum over i < d of
// w[i][c] x in(t - d + 1 + i, c)) for the a + n rows of the call: the a
// tokens of the last call to replay (the position buffer's word 3, their
// inputs the log's rows 0 .. a - 1), then the block's n (mixed); in(s) for
// s < 0 is row d - 1 + s of the layer's convolution state (the half the
// position buffer's word 1 names). A thread a channel, a workgroup row of
// 256 channels per row; the rows past a + n (the dispatch's room for a
// replay) do nothing.
#extension GL_EXT_buffer_reference : require
#extension GL_EXT_buffer_reference_uvec2 : require

layout(local_size_x = 256) in;

layout(buffer_reference, std430, buffer_reference_align = 4) readonly buffer R { float v[]; };
layout(buffer_reference, std430, buffer_reference_align = 4) writeonly buffer W { float v[]; };
layout(buffer_reference, std430, buffer_reference_align = 4) readonly buffer RP { uint v[]; };

// mixed: n rows of cc; log: the layer's logged rows, cc floats each; out:
// a + n rows of cc; w: d rows of cc; state: two halves of hs floats, this
// layer's (d - 1) rows of cc at so in each
layout(push_constant) uniform P { uvec2 mixed, out_, w, state, pos, log_; uint cc, d, hs, so, n; } p;

void main()
{
    uint c = gl_WorkGroupID.x * 256u + gl_LocalInvocationID.x, t = gl_WorkGroupID.y;
    uint a = RP(p.pos).v[3];
    if (c >= p.cc || t >= a + p.n)
        return;
    R M = R(p.mixed), L = R(p.log_), Wt = R(p.w), S = R(p.state);
    uint base = RP(p.pos).v[1] * p.hs + p.so;
    float s = 0.0;
    for (uint i = 0; i < p.d; i++) {
        int r = int(t) - int(p.d) + 1 + int(i);
        float x = r >= int(a) ? M.v[uint(r - int(a)) * p.cc + c]
                  : r >= 0    ? L.v[uint(r) * p.cc + c]
                              : S.v[base + uint(int(p.d) - 1 + r) * p.cc + c];
        s = i == 0u ? x * Wt.v[c] : fma(x, Wt.v[i * p.cc + c], s);
    }
    W(p.out_).v[t * p.cc + c] = s / (1.0 + exp(-s));
}