interplane.Get Omega
Read in your language

ggml

[Ported from github.com/ggml-org/ggml] docs : sync ggml_type enum in gguf.md (#1685)

Brought by drakestapleton

branch master Branches Tags History

ggml / src / ggml-hexagon / htp / hvx-pow.h

42 lines · 1434 bytes Raw Blame History
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) {
13 float ln_base = logf(base);
14 HVX_Vector ln_base_v = hvx_vec_splat_f32(ln_base);
15 HVX_Vector x = hvx_vec_mul_f32_f32(exponent, ln_base_v);
16
17 static const float kInf = INFINITY;
18 static const float kMaxExp = 88.7228f;
19
20 const HVX_Vector max_exp = hvx_vec_splat_f32(kMaxExp);
21 const HVX_Vector inf = hvx_vec_splat_f32(kInf);
22
23 return 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) {
30 HVX_Vector ln_base = hvx_vec_log_f32(base);
31 HVX_Vector x = hvx_vec_mul_f32_f32(exponent, ln_base);
32
33 static const float kInf = INFINITY;
34 static const float kMaxExp = 88.7228f;
35
36 const HVX_Vector max_exp = hvx_vec_splat_f32(kMaxExp);
37 const HVX_Vector inf = hvx_vec_splat_f32(kInf);
38
39 return hvx_vec_exp_f32_guard(x, max_exp, inf);
40}
41
42#endif /* HVX_POW_H */