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 / hex-dump.h
| 1 | #ifndef HEX_DUMP_H |
| 2 | #define HEX_DUMP_H |
| 3 | |
| 4 | #include <HAP_farf.h> |
| 5 | |
| 6 | static inline void hex_dump_int8_line(char * pref, const int8_t * x, int n) { |
| 7 | char str[1024], *p = str, *p_end = str + sizeof(str); |
| 8 | p += snprintf(p, p_end - p, "%s: ", pref); |
| 9 | for (int i = 0; i < n && p < p_end; i++) { |
| 10 | p += snprintf(p, p_end - p, "%d, ", x[i]); |
| 11 | } |
| 12 | FARF(HIGH, "%s\n", str); |
| 13 | } |
| 14 | |
| 15 | static inline void hex_dump_uint8_line(char * pref, const uint8_t * x, uint32_t n) { |
| 16 | char str[1024], *p = str, *p_end = str + sizeof(str); |
| 17 | p += snprintf(p, p_end - p, "%s: ", pref); |
| 18 | for (int i = 0; i < n && p < p_end; i++) { |
| 19 | p += snprintf(p, p_end - p, "%d, ", x[i]); |
| 20 | } |
| 21 | FARF(HIGH, "%s\n", str); |
| 22 | } |
| 23 | |
| 24 | static inline void hex_dump_uint32_line(char * pref, const uint32_t * x, uint32_t n) { |
| 25 | char str[1024], *p = str, *p_end = str + sizeof(str); |
| 26 | p += snprintf(p, p_end - p, "%s: ", pref); |
| 27 | for (int i = 0; i < n; i++) { |
| 28 | p += snprintf(p, p_end - p, "%u, ", (unsigned int) x[i]); |
| 29 | } |
| 30 | FARF(HIGH, "%s\n", str); |
| 31 | } |
| 32 | |
| 33 | static inline void hex_dump_int32_line(char * pref, const int32_t * x, uint32_t n) { |
| 34 | char str[1024], *p = str, *p_end = str + sizeof(str); |
| 35 | p += snprintf(p, p_end - p, "%s: ", pref); |
| 36 | for (int i = 0; i < n; i++) { |
| 37 | p += snprintf(p, p_end - p, "%d, ", (int) x[i]); |
| 38 | } |
| 39 | FARF(HIGH, "%s\n", str); |
| 40 | } |
| 41 | |
| 42 | static inline void hex_dump_f16_line(char * pref, const __fp16 * x, uint32_t n) { |
| 43 | char str[1024], *p = str, *p_end = str + sizeof(str); |
| 44 | p += snprintf(p, p_end - p, "%s: ", pref); |
| 45 | for (int i = 0; i < n; i++) { |
| 46 | p += snprintf(p, p_end - p, "%.6f, ", (float) x[i]); |
| 47 | } |
| 48 | FARF(HIGH, "%s\n", str); |
| 49 | } |
| 50 | |
| 51 | static inline void hex_dump_f32_line(char * pref, const float * x, uint32_t n) { |
| 52 | char str[1024], *p = str, *p_end = str + sizeof(str); |
| 53 | p += snprintf(p, p_end - p, "%s: ", pref); |
| 54 | for (int i = 0; i < n; i++) { |
| 55 | p += snprintf(p, p_end - p, "%.6f, ", x[i]); |
| 56 | } |
| 57 | FARF(HIGH, "%s\n", str); |
| 58 | } |
| 59 | |
| 60 | static inline void hex_dump_f32(char * pref, const float * x, uint32_t n) { |
| 61 | uint32_t n0 = n / 16; |
| 62 | uint32_t n1 = n % 16; |
| 63 | |
| 64 | uint32_t i = 0; |
| 65 | for (; i < n0; i++) { |
| 66 | hex_dump_f32_line(pref, x + (16 * i), 16); |
| 67 | } |
| 68 | if (n1) { |
| 69 | hex_dump_f32_line(pref, x + (16 * i), n1); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | static inline void hex_dump_f16(char * pref, const __fp16 * x, uint32_t n) { |
| 74 | uint32_t n0 = n / 16; |
| 75 | uint32_t n1 = n % 16; |
| 76 | |
| 77 | uint32_t i = 0; |
| 78 | for (; i < n0; i++) { |
| 79 | hex_dump_f16_line(pref, x + (16 * i), 16); |
| 80 | } |
| 81 | if (n1) { |
| 82 | hex_dump_f16_line(pref, x + (16 * i), n1); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | #endif /* HEX_DUMP_H */ |