Skip to content

Run frontier MoE models on hardware you already own — pure C, zero deps, experts streamed from disk. Tiny engine, immense model. 🐦

C

qwen36 tier: qt_dn_gpu_*, the DeltaNet layer joins its two projections on the card

kreuzzelg16f47f0ab7c7
diff --git a/c/qwen36_tier.c b/c/qwen36_tier.c
index 742769d9..37effa41 100644
--- a/c/qwen36_tier.c
+++ b/c/qwen36_tier.c
@@ -856,6 +856,39 @@ int qt_dnproj_matmul_batch(int layer, float *y, const float *x, int S, int I, in
return 0;
}
+/* ---- the DeltaNet layer on the device (see qwen36_tier.h) ---------------- */
+static struct { ColiCudaDn *d; int dev, on, dnout; } G_dn[QT_DN_MAX_LAYERS];
+int qt_dn_gpu_ready(int layer){ return layer >= 0 && layer < QT_DN_MAX_LAYERS && G_dn[layer].on; }
+int qt_dn_gpu_init(int layer, int vh, int vk, int kdim, int vdim, int conv_dim, int convk, int hidden,
+ const float *conv_w, const float *norm_w, float eps, int dnout_handle_plus1){
+ if(layer < 0 || layer >= QT_DN_MAX_LAYERS) return 0;
+ if(!qt_dnproj_ready(layer)) return 0; /* the in_proj must be on the card */
+ int h = dnout_handle_plus1 - 1;
+ if(h < 0 || h >= G_dense_n || !G_dense[h].on) return 0; /* and the out_proj */
+ if(G_dense[h].dev != G_dnp[layer].dev) return 0; /* on the same card */
+ ColiCudaDn *d = coli_cuda_dn_create(G_dnp[layer].dev, vh, vk, kdim, vdim, conv_dim, convk, hidden, conv_w, norm_w, eps);
+ if(!d) return 0; /* older backend or no memory: CPU path stands */
+ G_dn[layer].d = d; G_dn[layer].dev = G_dnp[layer].dev; G_dn[layer].dnout = h; G_dn[layer].on = 1;
+ return 1;
+}
+int qt_dn_gpu_set_state(int layer, const float *ring, const float *rec){
+ return qt_dn_gpu_ready(layer) && coli_cuda_dn_set_state(G_dn[layer].d, ring, rec);
+}
+int qt_dn_gpu_get_state(int layer, float *ring, float *rec){
+ /* also after a failed step (on == 0): the object still holds the state */
+ return layer >= 0 && layer < QT_DN_MAX_LAYERS && G_dn[layer].d && coli_cuda_dn_get_state(G_dn[layer].d, ring, rec);
+}
+int qt_dn_gpu_step(int layer, const float *x, float *out, const float *egh, const float *beta){
+ if(!qt_dn_gpu_ready(layer)) return 0;
+ if(coli_cuda_dn_step(G_dn[layer].d, G_dnp[layer].t, G_dense[G_dn[layer].dnout].t, x, out, egh, beta)) return 1;
+ fprintf(stderr,"[dn] layer %d GPU step failed; CPU from here on\n", layer);
+ G_dn[layer].on = 0;
+ return 0;
+}
+static void dn_gpu_free_all(void){
+ for(int l=0;l<QT_DN_MAX_LAYERS;l++){ if(G_dn[l].d) coli_cuda_dn_free(G_dn[l].d); G_dn[l].d=NULL; G_dn[l].on=0; }
+}
+
int qt_dnproj_matmul(int layer, float *y, const float *x, int I, int O){
return qt_dnproj_matmul_batch(layer, y, x, 1, I, O);
}
@@ -1207,6 +1240,7 @@ void qt_stats(void){
}
static void dense_free_all(void){
+ dn_gpu_free_all();
for(int h = 0; h < G_dense_n; h++){ if(G_dense[h].t) coli_cuda_tensor_free(G_dense[h].t); G_dense[h].t = NULL; G_dense[h].on = 0; }
G_dense_n = 0;
if(G_lmh.t) coli_cuda_tensor_free(G_lmh.t);
diff --git a/c/qwen36_tier.h b/c/qwen36_tier.h
index 41a73bf7..cee2a85b 100644
--- a/c/qwen36_tier.h
+++ b/c/qwen36_tier.h
@@ -80,6 +80,22 @@ int qt_dnproj_init(int layer, const int8_t *q, const float *sc,
int qt_dnproj_matmul(int layer, float *y, const float *x, int I, int O);
int qt_dnproj_ready(int layer);
int qt_dnproj_matmul_batch(int layer, float *y, const float *x, int S, int I, int O);
+
+/* The whole DeltaNet layer on the device (backend coli_cuda_dn_*): after the
+ * input projection (qt_dnproj_init) and the out_proj (a qt_dense handle) have
+ * both landed on the same device, qt_dn_gpu_init puts the layer's conv ring,
+ * recurrent state and norm/conv weights there too; qt_dn_gpu_step then runs a
+ * decode token end to end on the card, host in, host out. The host copy of
+ * the state stays the engine's, moved with qt_dn_gpu_set/get_state whenever
+ * the CPU path (prefill, snapshot, reset) needs it. A failing step turns the
+ * layer off, like every other GPU path here, and the engine continues on the
+ * CPU from the state it can still get back. */
+int qt_dn_gpu_init(int layer, int vh, int vk, int kdim, int vdim, int conv_dim, int convk, int hidden,
+ const float *conv_w, const float *norm_w, float eps, int dnout_handle_plus1);
+int qt_dn_gpu_ready(int layer);
+int qt_dn_gpu_set_state(int layer, const float *ring, const float *rec); /* NULL = zero */
+int qt_dn_gpu_get_state(int layer, float *ring, float *rec);
+int qt_dn_gpu_step(int layer, const float *x, float *out, const float *egh, const float *beta);
/* Generic resident dense matrix (int8 per-row, one GEMV per call), addressed
* by a handle: the Qwen3.8 trunk uses this for every matrix it places. Offer
* the size with qt_trunk_offer(name, layer, bytes) before qt_init, ask
@@ -155,6 +171,11 @@ static inline int qt_dnproj_init(int a,const int8_t*b,const float*c,int d,int e
static inline int qt_dnproj_matmul(int a,float*b,const float*c,int d,int e){(void)a;(void)b;(void)c;(void)d;(void)e;return 0;}
static inline int qt_dnproj_ready(int a){(void)a;return 0;}
static inline int qt_dnproj_matmul_batch(int a,float*b,const float*c,int d,int e,int f){(void)a;(void)b;(void)c;(void)d;(void)e;(void)f;return 0;}
+static inline int qt_dn_gpu_init(int a,int b,int c,int d,int e,int f,int g,int i,const float*j,const float*k,float l,int m){(void)a;(void)b;(void)c;(void)d;(void)e;(void)f;(void)g;(void)i;(void)j;(void)k;(void)l;(void)m;return 0;}
+static inline int qt_dn_gpu_ready(int a){(void)a;return 0;}
+static inline int qt_dn_gpu_set_state(int a,const float*b,const float*c){(void)a;(void)b;(void)c;return 0;}
+static inline int qt_dn_gpu_get_state(int a,float*b,float*c){(void)a;(void)b;(void)c;return 0;}
+static inline int qt_dn_gpu_step(int a,const float*b,float*c,const float*d,const float*e){(void)a;(void)b;(void)c;(void)d;(void)e;return 0;}
static inline int qt_dense_init(const int8_t*a,const float*b,int c,int d,int e){(void)a;(void)b;(void)c;(void)d;(void)e;return -1;}
static inline int qt_dense_matmul(int a,float*b,const float*c,int d,int e){(void)a;(void)b;(void)c;(void)d;(void)e;return 0;}
static inline int qt_dense_matmul_batch(int a,float*b,const float*c,int d,int e,int f){(void)a;(void)b;(void)c;(void)d;(void)e;(void)f;return 0;}