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-utils.h
| 1 | #ifndef HEX_UTILS_H |
| 2 | #define HEX_UTILS_H |
| 3 | |
| 4 | #include <stdbool.h> |
| 5 | #include <stdint.h> |
| 6 | #include <qurt_memory.h> |
| 7 | #include <qurt.h> |
| 8 | |
| 9 | #include "hexagon_types.h" |
| 10 | #include "hexagon_protos.h" |
| 11 | |
| 12 | #include "hex-fastdiv.h" |
| 13 | #include "hex-dump.h" |
| 14 | #include "hex-common.h" |
| 15 | |
| 16 | static inline uint64_t hex_get_cycles() { |
| 17 | uint64_t cycles = 0; |
| 18 | asm volatile(" %0 = c15:14\n" : "=r"(cycles)); |
| 19 | return cycles; |
| 20 | } |
| 21 | |
| 22 | static inline uint64_t hex_get_pktcnt() { |
| 23 | uint64_t pktcnt; |
| 24 | asm volatile(" %0 = c19:18\n" : "=r"(pktcnt)); |
| 25 | return pktcnt; |
| 26 | } |
| 27 | |
| 28 | static inline void hex_l2fetch(const void * p, uint32_t width, uint32_t stride, uint32_t height) { |
| 29 | const uint64_t control = Q6_P_combine_RR(stride, Q6_R_combine_RlRl(width, height)); |
| 30 | Q6_l2fetch_AP((void *) p, control); |
| 31 | } |
| 32 | |
| 33 | static inline void hex_l2fetch_block(const void * addr, size_t size) { |
| 34 | if (size == 0) return; |
| 35 | const uint32_t width = 16384; // 16KB rows |
| 36 | const uint32_t height = (size + width - 1) / width; |
| 37 | hex_l2fetch(addr, width, width, height); |
| 38 | } |
| 39 | |
| 40 | #define HEX_L2_LINE_SIZE 128 |
| 41 | #define HEX_L2_BLOCK_SIZE (HEX_L2_LINE_SIZE * 4) // flush granularity (chunks per thread) |
| 42 | #define HEX_L2_FLUSH_WQ_THRESHOLD (4 * 1024) |
| 43 | #define HEX_L2_FLUSH_ALL_THRESHOLD (4 * 1024 * 1024) |
| 44 | |
| 45 | static inline void hex_l2flush(void * addr, size_t size) { |
| 46 | if (size == 0) return; |
| 47 | const uint32_t s = ((uint32_t) addr) & ~(HEX_L2_LINE_SIZE - 1); |
| 48 | const uint32_t e = (((uint32_t) addr) + size + HEX_L2_LINE_SIZE - 1) & ~(HEX_L2_LINE_SIZE - 1); |
| 49 | for (uint32_t i = s; i < e; i += HEX_L2_LINE_SIZE) { |
| 50 | Q6_dccleaninva_A((void *) i); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | static inline void hex_pause() { |
| 55 | asm volatile(" pause(#255)\n"); |
| 56 | } |
| 57 | |
| 58 | #endif /* HEX_UTILS_H */ |