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/ggml/blob/master/src/ggml-cpu/spacemit/ime_kernels.h # ggml [Ported from github.com/ggml-org/ggml] docs : sync ggml_type enum in gguf.md (#1685) Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `ggml / src / ggml-cpu / spacemit / ime_kernels.h` 199 lines ยท 8410 bytes Raw Blame History 1 #pragma once 2 3 #include 4 #include 5 #include 6 7 namespace spacemit_kernels { 8 9 #define BLOCK_QNK_LEN 256 10 11 template struct nrow_block_q2_k { 12 // [4bit scale + 4bit zp] * N * 16 13 uint8_t scales[N * BLOCK_QNK_LEN / 16]; 14 // [b0, b16, b32, b48] [b1, b17, b33, b49] ... [b15, b31, b47, b63] 15 // [b64, b80, b96, b112] ...[b79, b95, b111, b127] 16 // [b128, b144, b160, b176] ...[b143, b159, b175, b191] 17 // [b192, b208, b224, b240] ...[b207, b223, b239, b255] 18 uint8_t qs[N * BLOCK_QNK_LEN / 4]; 19 uint16_t scales16[N]; 20 uint16_t zeros16[N]; 21 }; 22 23 template struct nrow_block_q3_k { 24 // [8bit scale] * N * 16 25 int8_t scales[N * 16]; 26 // [b0, b1, b2, b3, b4, b5, b6, b7] ... [b248, b249, b250, b251, b252, b253, b254, b255] 27 uint8_t hmask[N * BLOCK_QNK_LEN / 8]; 28 // [b0, b16, b32, b48] [b1, b17, b33, b49] ... [b15, b31, b47, b63] 29 // [b64, b80, b96, b112] ...[b79, b95, b111, b127] 30 // [b128, b144, b160, b176] ...[b143, b159, b175, b191] 31 // [b192, b208, b224, b240] ...[b207, b223, b239, b255] 32 uint8_t qs[N * BLOCK_QNK_LEN / 4]; 33 uint16_t scales16[N]; 34 }; 35 36 template struct nrow_block_mxfp4 { 37 uint8_t e[N]; 38 uint8_t qh[4 * N]; 39 uint8_t qs[16 * N]; 40 }; 41 42 template struct __attribute__((packed)) nrow_block_q5_1 { 43 uint16_t scales16[N]; 44 uint8_t zp[N]; 45 // n0 [bh0, bh1, bh2, bh3, bh4, bh5, bh6, bh7] .... 46 uint8_t qh[4 * N]; 47 // n0 [b0, b1], [b2, b3] .... [b30, b31] 48 // n1 [b0, b1], [b2, b3] .... [b30, b31] 49 uint8_t qs[16 * N]; 50 }; 51 52 static_assert(sizeof(nrow_block_q5_1<1>) == sizeof(uint8_t) + 22, "wrong nrow_block_q5_1 block size/padding"); 53 54 template struct __attribute__((packed)) nrow_block_q5_0 { 55 uint16_t scales16[N]; 56 // n0 [bh0, bh1, bh2, bh3, bh4, bh5, bh6, bh7] .... 57 uint8_t qh[4 * N]; 58 // n0 [b0, b1], [b2, b3] .... [b30, b31] 59 // n1 [b0, b1], [b2, b3] .... [b30, b31] 60 uint8_t qs[16 * N]; 61 }; 62 63 static_assert(sizeof(nrow_block_q5_0<1>) == 22, "wrong nrow_block_q5_0 block size/padding"); 64 65 using gemm_kernel_quantize_def = std::function< 66 size_t(size_t, const uint8_t *, const uint8_t *, const uint8_t *, float *, size_t, size_t, size_t, size_t)>; 67 68 using moe_gemm_kernel_quantize_def = std::function< 69 size_t(size_t, const uint8_t **, const uint8_t *, const uint8_t *, float **, size_t, size_t, size_t, size_t)>; 70 71 namespace ime1 { 72 size_t gemm_kernel_i8i4(size_t blk_len, 73 const uint8_t * quant_a_ptr, 74 const uint8_t * quant_b_data, 75 const uint8_t * quant_b_zp, 76 float * c_ptr, 77 size_t count_m, 78 size_t count_n, 79 size_t k_blks, 80 size_t ldc); 81 82 size_t gemm_kernel_i8i8(size_t blk_len, 83 const uint8_t * quant_a_ptr, 84 const uint8_t * quant_b_data, 85 const uint8_t * quant_b_zp, 86 float * c_ptr, 87 size_t count_m, 88 size_t count_n, 89 size_t k_blks, 90 size_t ldc); 91 92 void quantize_a_row_i8(size_t blk_len, const float * a_ptr, size_t count_k, uint8_t * quant_a_ptr); 93 94 void quantize_a_4row_i8(size_t blk_len, const float * a_ptr, size_t count_k, uint8_t * quant_a_ptr); 95 96 } // namespace ime1 97 98 namespace ime2 { 99 size_t gemm_kernel_i8i2k(size_t blk_len, 100 const uint8_t * quant_a_ptr, 101 const uint8_t * quant_b_data, 102 const uint8_t * quant_b_zp, 103 float * c_ptr, 104 size_t count_m, 105 size_t count_n, 106 size_t k_blks, 107 size_t ldc); 108 109 size_t gemm_kernel_i8i3k(size_t blk_len, 110 const uint8_t * quant_a_ptr, 111 const uint8_t * quant_b_data, 112 const uint8_t * quant_b_zp, 113 float * c_ptr, 114 size_t count_m, 115 size_t count_n, 116 size_t k_blks, 117 size_t ldc); 118 119 size_t gemm_kernel_i8i4(size_t blk_len, 120 const uint8_t * quant_a_ptr, 121 const uint8_t * quant_b_data, 122 const uint8_t * quant_b_zp, 123 float * c_ptr, 124 size_t count_m, 125 size_t count_n, 126 size_t k_blks, 127 size_t ldc); 128 129 size_t gemm_kernel_i8i4_hp(size_t blk_len, 130 const uint8_t * quant_a_ptr, 131 const uint8_t * quant_b_data, 132 const uint8_t * quant_b_zp, 133 float * c_ptr, 134 size_t count_m, 135 size_t count_n, 136 size_t k_blks, 137 size_t ldc); 138 139 size_t moe_m2_gemm_kernel_i8i4(size_t blk_len, 140 const uint8_t ** quant_a_ptr, 141 const uint8_t * quant_b_data, 142 const uint8_t * quant_b_zp, 143 float ** c_ptr, 144 size_t count_m, 145 size_t count_n, 146 size_t k_blks, 147 size_t ldc); 148 149 size_t gemm_kernel_i8i8(size_t blk_len, 150 const uint8_t * quant_a_ptr, 151 const uint8_t * quant_b_data, 152 const uint8_t * quant_b_zp, 153 float * c_ptr, 154 size_t count_m, 155 size_t count_n, 156 size_t k_blks, 157 size_t ldc); 158 159 size_t gemm_kernel_i8mxfp4(size_t blk_len, 160 const uint8_t * quant_a_ptr, 161 const uint8_t * quant_b_data, 162 const uint8_t * quant_b_zp, 163 float * c_ptr, 164 size_t count_m, 165 size_t count_n, 166 size_t k_blks, 167 size_t ldc); 168 169 size_t moe_m2_gemm_kernel_i8mxfp4(size_t blk_len, 170 const uint8_t ** quant_a_ptr, 171 const uint8_t * quant_b_data, 172 const uint8_t * quant_b_zp, 173 float ** c_ptr, 174 size_t count_m, 175 size_t count_n, 176 size_t k_blks, 177 size_t ldc); 178 179 size_t gemm_kernel_i8i5(size_t blk_len, 180 const uint8_t * quant_a_ptr, 181 const uint8_t * quant_b_data, 182 const uint8_t * quant_b_zp, 183 float * c_ptr, 184 size_t count_m, 185 size_t count_n, 186 size_t k_blks, 187 size_t ldc); 188 189 size_t moe_m2_gemm_kernel_i8i5(size_t blk_len, 190 const uint8_t ** quant_a_ptr, 191 const uint8_t * quant_b_data, 192 const uint8_t * quant_b_zp, 193 float ** c_ptr, 194 size_t count_m, 195 size_t count_n, 196 size_t k_blks, 197 size_t ldc); 198 } // namespace ime2 199 } // namespace spacemit_kernels