Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/MojoLlama/blob/main/src/mojollama/kernels/legacy-c/cengine_final.c # MojoLlama Archived Mojo/MAX quantizer and serving research repository (read-only history) Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `MojoLlama / src / mojollama / kernels / legacy-c / cengine_final.c` 93 lines · 3801 bytes Raw Blame History 1 /* cengine_final.c — Uses proven quant_kernels_omp for ALL matmuls. 2 * Drop-in replacement for q4d — calls quant_matmul_omp externally. 3 * Compile: 4 * gcc -O3 -mavx2 -mfma -mf16c -fopenmp -shared -fPIC \ 5 * -o cengine_final.so cengine_final.c \ 6 * -L. -l:quant_kernels_omp.so -Wl,-rpath,/onedev-workspace/work/src/mojollama/kernels -lm 7 */ 8 #include 9 #include 10 #include 11 #include 12 13 /* External: proven OMP kernels */ 14 extern void quant_matmul_omp(const unsigned char*, const float*, float*, int, int, int); 15 extern void rms_norm(const float*, const float*, float*, int, float); 16 extern void silu(float*, int); 17 18 /* External: GQA attention */ 19 extern void gqa_attention_decode(const float*, const float*, const float*, 20 float*, int, int, int, int); 21 22 void process_layer_final( 23 int layer_id, float *x, 24 int L, int N, int NH, int NKH, int HD, int FF, float eps, 25 const unsigned char *w_q, const unsigned char *w_k, const unsigned char *w_v, 26 const unsigned char *w_o, const unsigned char *w_g, const unsigned char *w_u, const unsigned char *w_d, 27 const float *w_an, const float *w_fn, 28 int n_q, int n_k, int n_v, int n_o, int n_g, int n_u, int n_d, 29 int nc_qkv, int nc_down, int nc_o, /* n_cols per projection */ 30 float *kv_k, float *kv_v, int *kv_len, int max_pos, 31 float *xn, float *res, float *q, float *k, float *v, 32 float *att, float *gate, float *up, float *silu_buf, 33 float *oproj, float *ffn 34 ) { 35 int pos = *kv_len; 36 37 memcpy(res, x, N * sizeof(float)); 38 rms_norm(x, xn, w_an, N, eps); /* note: rms_norm(out, x, w, n, eps) */ 39 40 /* QKV — use proven quant_matmul_omp for individual projections */ 41 quant_matmul_omp(w_q, xn, q, n_q, nc_qkv, 2); 42 quant_matmul_omp(w_k, xn, k, n_k, nc_qkv, 2); 43 quant_matmul_omp(w_v, xn, v, n_v, nc_qkv, 2); 44 45 /* RoPE — using on-the-fly computation */ 46 for(int hh=0;hh