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/cengine2.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 / cengine2.c` 194 lines · 8818 bytes Raw Blame History 1 /* cengine2.c — Clean C forward pass. No struct, flat arrays. 2 * 3 * engine_forward(tok, ...all weight pointers and dims as flat arrays..., logits) 4 * 5 * Uses only the call stack and explicit parameters — no struct layout worries. 6 * 7 * Compile: 8 * gcc -O3 -mavx2 -mfma -mf16c -fopenmp -shared -fPIC \ 9 * -o cengine2.so cengine2.c -lm 10 */ 11 #include 12 #include 13 #include 14 #include 15 #include 16 17 #define Q4_0_BS 18 18 #define Q8_0_BS 34 19 20 static inline float f16_to_f32(uint16_t h) { return _cvtsh_ss(h); } 21 static inline float hsum_ps(__m256 v) { 22 __m128 l=_mm256_castps256_ps128(v),h=_mm256_extractf128_ps(v,1); 23 l=_mm_add_ps(l,h);l=_mm_hadd_ps(l,l);l=_mm_hadd_ps(l,l);return _mm_cvtss_f32(l); 24 } 25 26 /* Q4_0 dot — inline AVX2 */ 27 static inline float q4d(const uint8_t *W, const float *x, int nc, int r) { 28 int bp=nc/32; float total=0.0f; 29 for(int b=0;bmx)mx=dot;} 94 float se=0;for(int s=0;s