| 19149 | } |
| 19150 | |
| 19151 | size_t ggml_quantize_q5_0(const float * src, void * dst, int n, int k, int64_t * hist) { |
| 19152 | assert(k % QK5_0 == 0); |
| 19153 | const int nb = k / QK5_0; |
| 19154 | |
| 19155 | for (int b = 0; b < n; b += k) { |
| 19156 | block_q5_0 * restrict y = (block_q5_0 *)dst + b/QK5_0; |
| 19157 | |
| 19158 | quantize_row_q5_0_reference(src + b, y, k); |
| 19159 | |
| 19160 | for (int i = 0; i < nb; i++) { |
| 19161 | uint32_t qh; |
| 19162 | memcpy(&qh, &y[i].qh, sizeof(qh)); |
| 19163 | |
| 19164 | for (int j = 0; j < QK5_0; j += 2) { |
| 19165 | const uint8_t vh0 = ((qh & (1u << (j + 0 ))) >> (j + 0 )) << 4; |
| 19166 | const uint8_t vh1 = ((qh & (1u << (j + 16))) >> (j + 12)); |
| 19167 | |
| 19168 | // cast to 16 bins |
| 19169 | const uint8_t vi0 = ((y[i].qs[j/2] & 0x0F) | vh0) / 2; |
| 19170 | const uint8_t vi1 = ((y[i].qs[j/2] >> 4) | vh1) / 2; |
| 19171 | |
| 19172 | hist[vi0]++; |
| 19173 | hist[vi1]++; |
| 19174 | } |
| 19175 | } |
| 19176 | } |
| 19177 | |
| 19178 | return (n/QK5_0*sizeof(block_q5_0)); |
| 19179 | } |
| 19180 | |
| 19181 | size_t ggml_quantize_q5_1(const float * src, void * dst, int n, int k, int64_t * hist) { |
| 19182 | assert(k % QK5_1 == 0); |
no test coverage detected