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_batch_clean.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_batch_clean.c` 42 lines · 1288 bytes Raw Blame History 1 /* cengine_batch.c — vLLM-style concurrent batched inference. 2 * Uses q4_0_batch_matmul for all weight projections across B tokens. 3 */ 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include 10 #include 11 #define Q4_0_BS 18 12 #define Q8_0_BS 34 13 #define BLOCK_SIZE 64 14 #define MAX_BLOCKS 1024 15 #define QK_K 256 16 17 /* K-quant block structures (from llama.cpp) */ 18 typedef struct { 19 uint16_t d; // half: super-block scale 20 uint16_t dm; // half: super-block min 21 uint8_t scales[12]; // 8 × 6-bit scale/min pairs 22 uint8_t qs[128]; // 4-bit nibbles (256 elements) 23 } block_q4_K; 24 25 typedef struct { 26 uint8_t ql[128]; // lower 4 bits of quants 27 uint8_t qh[64]; // upper 2 bits of quants 28 int8_t scales[16]; // 16 × int8 scales (one per 16 elements) 29 uint16_t d; // half: super-block scale 30 } block_q6_K; 31 32 /* GGML half <-> float conversion */ 33 static inline float gf16(uint16_t h) { 34 return _cvtsh_ss(h); 35 } 36 37 /* Q4_K scale extraction */ 38 static inline void k4_scale(int j, const uint8_t *q, uint8_t *d, uint8_t *m) { 39 if (j < 4) { *d = q[j] & 63; *m = q[j+4] & 63; } 40 else { *d = (q[j+4] & 0xF) | ((q[j-4] >> 6) << 4); 41 *m = (q[j+4] >> 4) | ((q[j] >> 6) << 4); } 42 }