onnx2versal
Loading...
Searching...
No Matches
quantize_linear.h
1#ifndef QUANTIZE_LINEAR_H
2#define QUANTIZE_LINEAR_H
3
4#include <adf.h>
5#include <assert.h>
6
7
24template <typename TT, int INP_H, int INP_W, int OUT_W>
26
27 private:
28 float y_scale;
29 TT y_zero; // same type as output
30
31 public:
33 float y_scale,
34 TT y_zero
35 ): y_scale(y_scale), y_zero(y_zero) {};
36
37 void filter(
38 input_window<float>* in,
39 output_window<TT>* out
40 );
41
42 static void registerKernelClass() {
43 static_assert(INP_W <= OUT_W);
44 REGISTER_FUNCTION(QuantizeLinearScalar::filter);
45 }
46};
47
48
54template <typename TT, int INP_H, int INP_W, int OUT_W>
56
57 private:
58 float y_scale;
59 TT y_zero; // same type as output
60
61 // precompute
62 int xbitshift = 16; // ybitshift in [0:16], acc48 result
63 int ybitshift;
64 int16_t y_scale_inv_int;
65
66 public:
68 float y_scale,
69 TT y_zero
70 );
71
72 void filter(
73 input_window<float>* in,
74 output_window<TT>* out
75 );
76
77 static void registerKernelClass() {
78 static_assert(INP_W%4 == 0 && OUT_W%16 == 0);
79 static_assert(INP_W <= OUT_W);
80 REGISTER_FUNCTION(QuantizeLinear::filter);
81 }
82};
83
84
90template <typename TT, int INP_H, int INP_W, int OUT_W>
92
93 private:
94 float y_scale;
95 TT y_zero; // same type as output
96
97 public:
99 float y_scale,
100 TT y_zero
101 ): y_scale(y_scale), y_zero(y_zero) {};
102
103 void filter(
104 input_window<float>* in,
105 output_window<TT>* out
106 );
107
108 static void registerKernelClass() {
109 static_assert(INP_W%4 == 0 && OUT_W%16 == 0);
110 static_assert(INP_W <= OUT_W);
111 REGISTER_FUNCTION(QuantizeLinearFmul::filter);
112 }
113};
114
115
121template <typename TT, int INP_H, int INP_W, int OUT_W>
123
124 private:
125 float y_scale;
126 TT y_zero; // same type as output
127
128 public:
130 float y_scale,
131 TT y_zero
132 ): y_scale(y_scale), y_zero(y_zero) {};
133
134 void filter(
135 input_stream<float>* in,
136 output_stream<TT>* out
137 );
138
139 static void registerKernelClass() {
140 static_assert(INP_W%4 == 0 && OUT_W%16 == 0);
141 static_assert(INP_W <= OUT_W);
142 REGISTER_FUNCTION(QuantizeLinearFmulStream::filter);
143 }
144};
148#endif // QUANTIZE_LINEAR_H
Vector stream implementation, requires INP_W%4==0, OUT_W%16==0, INP_W <= OUT_W, QuantizeLinearFmulStr...
Definition quantize_linear.h:122
Vector implementation, requires INP_W%4==0, OUT_W%16==0, INP_W <= OUT_W, QuantizeLinearFmul<1*1*28*28...
Definition quantize_linear.h:91
Scalar implementation, requires INP_W <= OUT_W, QuantizeLinearScalar<1*1*28*28> takes 92121 cycles.
Definition quantize_linear.h:25
Vector implementation, requires INP_W%4==0, OUT_W%16==0, INP_W <= OUT_W, QuantizeLinear<1*1*28*28> ta...
Definition quantize_linear.h:55