ggml
[Ported from github.com/ggml-org/ggml] docs : sync ggml_type enum in gguf.md (#1685)
Brought by drakestapleton
ggml / src / ggml-hexagon / htp-repack.h
| 1 | #ifndef HTP_REPACK_H |
| 2 | #define HTP_REPACK_H |
| 3 | |
| 4 | #include <stddef.h> |
| 5 | #include <stdint.h> |
| 6 | |
| 7 | #include "ggml.h" |
| 8 | #include "htp/htp-tensor.h" |
| 9 | |
| 10 | static inline bool htp_is_tiled_weight_type(enum ggml_type type) { |
| 11 | return type == GGML_TYPE_Q4_0 || type == GGML_TYPE_Q4_1 || |
| 12 | type == GGML_TYPE_Q8_0 || type == GGML_TYPE_IQ4_NL || |
| 13 | type == GGML_TYPE_MXFP4 || type == GGML_TYPE_Q1_0 || |
| 14 | type == GGML_TYPE_Q6_K || |
| 15 | type == GGML_TYPE_Q4_K || type == GGML_TYPE_Q5_K || |
| 16 | type == GGML_TYPE_Q3_K || type == GGML_TYPE_Q2_K || |
| 17 | type == GGML_TYPE_Q2_0 || |
| 18 | type == GGML_TYPE_F16 || type == GGML_TYPE_F32 || |
| 19 | type == GGML_TYPE_BF16; |
| 20 | } |
| 21 | |
| 22 | static inline bool htp_is_tiled_weight_tensor(const struct ggml_tensor * t) { |
| 23 | if (!ggml_is_contiguous(t) || ggml_is_view(t)) { |
| 24 | return false; |
| 25 | } |
| 26 | if (!htp_is_tiled_weight_type(t->type)) { |
| 27 | return false; |
| 28 | } |
| 29 | if (t->ne[0] < 32) { |
| 30 | return false; |
| 31 | } |
| 32 | if (!ggml_is_quantized(t->type)) { |
| 33 | return (t->ne[0] % 32 == 0) && (t->ne[1] % 32 == 0) && (t->ne[2] == 1) && (t->ne[3] == 1); |
| 34 | } |
| 35 | return t->ne[3] == 1; |
| 36 | } |
| 37 | |
| 38 | // Size of one tiled row in the DSP tiled layout. The Q3_K..Q6_K tiles store uncompressed scales/mins, |
| 39 | // so they are larger than the ggml blocks. For the other tiled types (Q2_K included) the tile has the same size. |
| 40 | static inline size_t htp_tiled_row_size(enum ggml_type type, int64_t ne0) { |
| 41 | if (type == GGML_TYPE_F16 || type == GGML_TYPE_F32 || type == GGML_TYPE_BF16) { |
| 42 | return (size_t) ne0 * sizeof(ggml_fp16_t); |
| 43 | } |
| 44 | if (type == GGML_TYPE_Q6_K) { |
| 45 | return (size_t) (ne0 / 32) * (HTP_TENSOR_TILE_SIZE_Q6_K / 32); |
| 46 | } |
| 47 | if (type == GGML_TYPE_Q2_0) { |
| 48 | return (size_t) (ne0 / 64) * 18; |
| 49 | } |
| 50 | if (type == GGML_TYPE_Q4_K) { |
| 51 | return (size_t) (ne0 / 32) * (HTP_TENSOR_TILE_SIZE_Q4_K / 32); |
| 52 | } |
| 53 | if (type == GGML_TYPE_Q5_K) { |
| 54 | return (size_t) (ne0 / 32) * (HTP_TENSOR_TILE_SIZE_Q5_K / 32); |
| 55 | } |
| 56 | if (type == GGML_TYPE_Q3_K) { |
| 57 | return (size_t) (ne0 / 32) * (HTP_TENSOR_TILE_SIZE_Q3_K / 32); |
| 58 | } |
| 59 | return ggml_row_size(type, ne0); |
| 60 | } |
| 61 | |
| 62 | static inline bool htp_is_hmx_weight_type(enum ggml_type type) { |
| 63 | return htp_is_tiled_weight_type(type); |
| 64 | } |
| 65 | |
| 66 | void htp_repack_tensor_tiled(struct ggml_tensor * t, const void * data, size_t size); |
| 67 | void htp_unpack_tensor_tiled(void * data, const struct ggml_tensor * t, size_t offset, size_t size); |
| 68 | |
| 69 | #endif // HTP_REPACK_H |