onnx2versal
Loading...
Searching...
No Matches
softmax.h
1#ifndef SOFTMAX_H_
2#define SOFTMAX_H_
3
4#include <adf.h>
5#include <assert.h>
6
7
25double fastexp(float val);
26
31float fastexp2(float val, int precision);
32
41template <int INP_H, int INP_W, int INP_W_PAD>
43 private:
44 float coef[10] = {1, 0.5, 0.16666666666666666, 0.041666666666666664, 0.008333333333333333, 0.001388888888888889, 0.0001984126984126984, 2.48015873015873e-05, 2.7557319223985893e-06, 2.755731922398589e-07};
45
50 float fastexp3(float val, int precision);
51
52 public:
53 void filter(
54 input_window<float>* in,
55 output_window<float>* out
56 );
57
58 static void registerKernelClass() {
59 REGISTER_FUNCTION(SoftmaxScalar::filter);
60 }
61};
62
63
69template <int INP_H, int INP_W, int INP_W_PAD>
71 public:
72 void filter(
73 input_window<float>* in,
74 output_window<float>* out
75 );
76
77 static void registerKernelClass() {
78 static_assert(INP_W_PAD % 8 == 0);
79 REGISTER_FUNCTION(SoftmaxSingleaxis::filter);
80 }
81};
82
83
89template <int INP_H, int INP_W, int INP_W_PAD>
91 public:
92 void filter(
93 input_window<float>* in,
94 output_window<float>* out
95 );
96
97 static void registerKernelClass() {
98 static_assert(INP_H % 2 == 0 && INP_W_PAD % 8 == 0);
99 REGISTER_FUNCTION(SoftmaxMultiaxis::filter);
100 }
101};
105#endif // SOFTMAX_H_
Vector implementation for multiple axis, SoftmaxMultiaxis<10,10,16> takes 1082 cycles requires INP_H%...
Definition softmax.h:90
Scalar implementation, SoftmaxScalar<10,10,16> takes.
Definition softmax.h:42
Vector implementation for single axis, SoftmaxSingleaxis<10,10,16> takes 1241 cycles requires INP_W_P...
Definition softmax.h:70
float fastexp2(float val, int precision)
approximation with (1 + x/256)^256 Error is small for [-512. 1.5]
Definition qlinearsoftmax.cc:11
double fastexp(float val)
See https://nic.schraudolph.org/pubs/Schraudolph99.pdf.
Definition softmax.cc:9