char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
89f10baad
char/aliceai-t5-moe
1#ifndef HVX_DUMP_H 2#define HVX_DUMP_H 3 4#include <HAP_farf.h> 5 6#include <stdbool.h> 7#include <stdint.h> 8 9#include "hex-utils.h" 10#include "hvx-types.h" 11 12static void hvx_vec_dump_f16_n (char * pref ,HVX_Vector v ,uint32_t n ) { 13HVX_VectorAlias u = { .v = v }; 14 15const uint32_t n0 = n /16 ; 16const uint32_t n1 = n %16 ; 17int i = 0 ; 18for (;i < n0 ;i ++ ) { 19hex_dump_f16_line (pref ,u .fp16 + (16 * i ),16 ); 20 } 21if (n1 ) { 22hex_dump_f16_line (pref ,u .fp16 + (16 * i ),n1 ); 23 } 24} 25 26static void hvx_vec_dump_f16 (char * pref ,HVX_Vector v ) { 27hvx_vec_dump_f16_n (pref ,v ,64 ); 28} 29 30static void hvx_vec_dump_f32_n (char * pref ,HVX_Vector v ,uint32_t n ) { 31HVX_VectorAlias u = { .v = v }; 32 33const uint32_t n0 = n /16 ; 34const uint32_t n1 = n %16 ; 35int i = 0 ; 36for (;i < n0 ;i ++ ) { 37hex_dump_f32_line (pref ,u .fp32 + (16 * i ),16 ); 38 } 39if (n1 ) { 40hex_dump_f32_line (pref ,u .fp32 + (16 * i ),n1 ); 41 } 42} 43 44static void hvx_vec_dump_f32_hmt (char * pref ,HVX_Vector v ) { 45union { 46HVX_Vector v ; 47float d [32 ]; 48 }u = { .v = v }; 49 50FARF (HIGH ,"%s: %.6f %.6f %.6f %.6f ... %.6f %.6f %.6f %.6f ... %.6f %.6f %.6f %.6f\n" ,pref ,u .d [0 ],u .d [1 ], 51u .d [2 ],u .d [3 ],u .d [12 ],u .d [13 ],u .d [14 ],u .d [15 ],u .d [28 ],u .d [29 ],u .d [30 ],u .d [31 ]); 52} 53 54static void hvx_vec_dump_f32 (char * pref ,HVX_Vector v ) { 55hvx_vec_dump_f32_n (pref ,v ,32 ); 56} 57 58static void hvx_vec_dump_int32 (char * pref ,HVX_Vector v ) { 59union { 60HVX_Vector v ; 61int32_t d [32 ]; 62 }u = { .v = v }; 63 64for (int i = 0 ;i < 32 /16 ;i ++ ) { 65hex_dump_int32_line (pref ,u .d + (16 * i ),16 ); 66 } 67} 68 69static void hvx_vec_dump_int32_hmt (char * pref ,HVX_Vector v ) { 70union { 71HVX_Vector v ; 72int32_t d [32 ]; 73 }u = { .v = v }; 74 75FARF (HIGH ,"%s: %d %d %d %d ... %d %d %d %d ... %d %d %d %d\n" ,pref ,u .d [0 ],u .d [1 ],u .d [2 ],u .d [3 ],u .d [12 ], 76u .d [13 ],u .d [14 ],u .d [15 ],u .d [28 ],u .d [29 ],u .d [30 ],u .d [31 ]); 77} 78 79static void hvx_vec_dump_int8_hmt (char * pref ,HVX_Vector v ) { 80union { 81HVX_Vector v ; 82int8_t d [128 ]; 83 }u = { .v = v }; 84 85FARF (HIGH ,"%s: %d %d %d %d ... %d %d %d %d ... %d %d %d %d\n" ,pref ,u .d [0 ],u .d [1 ],u .d [2 ],u .d [3 ],u .d [60 ], 86u .d [61 ],u .d [62 ],u .d [63 ],u .d [124 ],u .d [125 ],u .d [126 ],u .d [127 ]); 87} 88 89static void hvx_vec_dump_int8 (char * pref ,HVX_Vector v ) { 90union { 91HVX_Vector v ; 92int8_t d [128 ]; 93 }u = { .v = v }; 94 95for (int i = 0 ;i < 128 /16 ;i ++ ) { 96hex_dump_int8_line (pref ,u .d + (16 * i ),16 ); 97 } 98} 99 100static void hvx_vec_dump_uint8 (char * pref ,HVX_Vector v ) { 101union { 102HVX_Vector v ; 103uint8_t d [128 ]; 104 }u = { .v = v }; 105 106for (int i = 0 ;i < 128 /16 ;i ++ ) { 107hex_dump_uint8_line (pref ,u .d + (16 * i ),16 ); 108 } 109} 110 111static bool hvx_vec_eq (HVX_Vector v0 ,HVX_Vector v1 ,size_t n ) { 112typedef union { 113HVX_Vector v ; 114int8_t d [128 ]; 115 }U ; 116 117U u0 = { .v = v0 }; 118U u1 = { .v = v1 }; 119 120for (int i = 0 ;i < n ;i ++ ) { 121if (u0 .d [i ]!= u1 .d [i ]) { 122return false; 123 } 124 } 125 126return true; 127} 128 129#endif /* HVX_DUMP_H */