char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
8f7f3bf14
char/aliceai-t5-moe
1#ifndef HVX_POW_H 2#define HVX_POW_H 3 4#include <math.h> 5#include "hvx-base.h" 6#include "hvx-exp.h" 7#include "hvx-log.h" 8 9// Approximates base^exponent element-wise for float vectors. 10// base must be a positive constant. exponent is an HVX f32 vector. 11// Uses base^x = exp(x * ln(base)). 12static inline HVX_Vector hvx_vec_pow_const_base_f32 (float base ,HVX_Vector exponent ) { 13float ln_base = logf (base ); 14HVX_Vector ln_base_v = hvx_vec_splat_f32 (ln_base ); 15HVX_Vector x = hvx_vec_mul_f32_f32 (exponent ,ln_base_v ); 16 17static const float kInf = INFINITY ; 18static const float kMaxExp = 88.7228f ; 19 20const HVX_Vector max_exp = hvx_vec_splat_f32 (kMaxExp ); 21const HVX_Vector inf = hvx_vec_splat_f32 (kInf ); 22 23return hvx_vec_exp_f32_guard (x ,max_exp ,inf ); 24} 25 26// Approximates base^exponent element-wise for float vectors. 27// base and exponent are HVX f32 vectors. base elements must be positive. 28// Uses base^exponent = exp(exponent * ln(base)). 29static inline HVX_Vector hvx_vec_pow_f32 (HVX_Vector base ,HVX_Vector exponent ) { 30HVX_Vector ln_base = hvx_vec_log_f32 (base ); 31HVX_Vector x = hvx_vec_mul_f32_f32 (exponent ,ln_base ); 32 33static const float kInf = INFINITY ; 34static const float kMaxExp = 88.7228f ; 35 36const HVX_Vector max_exp = hvx_vec_splat_f32 (kMaxExp ); 37const HVX_Vector inf = hvx_vec_splat_f32 (kInf ); 38 39return hvx_vec_exp_f32_guard (x ,max_exp ,inf ); 40} 41 42#endif /* HVX_POW_H */