char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
eafe15a5e
char/aliceai-t5-moe
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 16static inline uint64_t hex_get_cycles () { 17uint64_t cycles = 0 ; 18 asmvolatile (" %0 = c15:14\n" :"=r" (cycles )); 19return cycles ; 20} 21 22static inline uint64_t hex_get_pktcnt () { 23uint64_t pktcnt ; 24 asmvolatile (" %0 = c19:18\n" :"=r" (pktcnt )); 25return pktcnt ; 26} 27 28static inline void hex_l2fetch (const void * p ,uint32_t width ,uint32_t stride ,uint32_t height ) { 29const uint64_t control = Q6_P_combine_RR (stride ,Q6_R_combine_RlRl (width ,height )); 30Q6_l2fetch_AP ((void * )p ,control ); 31} 32 33static inline void hex_l2fetch_block (const void * addr ,size_t size ) { 34if (size == 0 )return ; 35const uint32_t width = 16384 ;// 16KB rows 36const uint32_t height = (size + width - 1 ) /width ; 37hex_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 (lines per loop iteration) 42#define HEX_L2_FLUSH_WQ_THRESHOLD (4 * 1024) 43#define HEX_L2_FLUSH_ALL_THRESHOLD (4 * 1024 * 1024) 44 45static inline void hex_l2flush (void * addr ,size_t size ) { 46const uint32_t s = ((uint32_t )addr )& ~(HEX_L2_LINE_SIZE - 1 ); 47const uint32_t e = (((uint32_t )addr )+ size + HEX_L2_LINE_SIZE - 1 )& ~(HEX_L2_LINE_SIZE - 1 ); 48const uint32_t eb = s + ((e - s )& ~(HEX_L2_BLOCK_SIZE - 1 )); 49for (uint32_t i = s ;i < eb ;i += HEX_L2_BLOCK_SIZE ) { 50Q6_dccleaninva_A ((void * ) (i + HEX_L2_LINE_SIZE * 0 )); 51Q6_dccleaninva_A ((void * ) (i + HEX_L2_LINE_SIZE * 1 )); 52Q6_dccleaninva_A ((void * ) (i + HEX_L2_LINE_SIZE * 2 )); 53Q6_dccleaninva_A ((void * ) (i + HEX_L2_LINE_SIZE * 3 )); 54 } 55for (uint32_t i = eb ;i < e ;i += HEX_L2_LINE_SIZE ) { 56Q6_dccleaninva_A ((void * )i ); 57 } 58} 59 60static inline void hex_pause () { 61 asmvolatile (" pause(#255)\n" ); 62} 63 64#endif /* HEX_UTILS_H */