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-hexagon/htp/hex-common.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-hexagon / htp / hex-common.h` 93 lines ยท 2023 bytes Raw Blame History 1 #ifndef HEX_COMMON_H 2 #define HEX_COMMON_H 3 4 #include 5 #include 6 #include 7 8 #ifndef SIZE_MAX 9 #define SIZE_MAX ((size_t)-1) 10 #endif 11 12 #ifndef MAX 13 #define MAX(a, b) ((a) > (b) ? (a) : (b)) 14 #endif 15 16 #ifndef MIN 17 #define MIN(a, b) ((a) < (b) ? (a) : (b)) 18 #endif 19 20 #ifndef HEX_L2_LINE_SIZE 21 #define HEX_L2_LINE_SIZE 128 22 #endif 23 24 static inline uint32_t hex_ceil_pow2(uint32_t x) { 25 if (x <= 1) { return 1; } 26 int p = 2; 27 x--; 28 while (x >>= 1) { p <<= 1; } 29 return p; 30 } 31 32 static inline size_t hmx_ceil_div(size_t num, size_t den) { 33 return (num + den - 1) / den; 34 } 35 36 static inline int32_t hex_is_aligned(const void * addr, uint32_t align) { 37 return ((size_t) addr & (align - 1)) == 0; 38 } 39 40 static inline size_t hex_align_up(size_t v, size_t align) { 41 return hmx_ceil_div(v, align) * align; 42 } 43 44 static inline size_t hex_align_down(size_t v, size_t align) { 45 return (v / align) * align; 46 } 47 48 static inline int32_t hex_is_one_chunk(void * addr, uint32_t n, uint32_t chunk_size) { 49 uint32_t left_off = (size_t) addr & (chunk_size - 1); 50 uint32_t right_off = left_off + n; 51 return right_off <= chunk_size; 52 } 53 54 static inline uint32_t hex_round_up(uint32_t n, uint32_t m) { 55 return m * ((n + m - 1) / m); 56 } 57 58 static inline size_t hex_smin(size_t a, size_t b) { 59 return a < b ? a : b; 60 } 61 62 static inline size_t hex_smax(size_t a, size_t b) { 63 return a > b ? a : b; 64 } 65 66 static inline void hex_swap_ptr(void ** p1, void ** p2) { 67 void * t = *p1; 68 *p1 = *p2; 69 *p2 = t; 70 } 71 72 static inline bool hex_mul_overflow(size_t a, size_t b, size_t *out) { 73 if (a != 0 && b > SIZE_MAX / a) return true; 74 *out = a * b; 75 return false; 76 } 77 78 static inline bool hex_add_overflow(size_t a, size_t b, size_t *out) { 79 if (a > SIZE_MAX - b) return true; 80 *out = a + b; 81 return false; 82 } 83 84 static inline uint32_t hex_gcd_u32(uint32_t a, uint32_t b) { 85 while (b != 0) { 86 uint32_t t = b; 87 b = a % b; 88 a = t; 89 } 90 return a; 91 } 92 93 #endif // HEX_COMMON_H