@@ -127,60 +127,6 @@ void dequantize(
127127 }
128128}
129129
130- // Requantize the int8_t/uint8_t in value to a uint8_t/int8_t out value.
131- // The scale and zero_point for requantization are in the args.
132- template <typename IT, typename OT>
133- __attribute__ ((always_inline)) OT requantize (
134- const IT in,
135- float in_scale,
136- int32_t in_zero_point,
137- float inv_out_scale,
138- int32_t out_zero_point) {
139- float dequant = dequantize<IT>(in, in_scale, in_zero_point);
140- return quantize<OT>(dequant, inv_out_scale, out_zero_point);
141- }
142-
143- // Requantize the int8_t/uint8_t in array to a uint8_t/int8_t out array.
144- // The scale and zero_point for requantization are in the args.
145- template <typename IT, typename OT>
146- void requantize (
147- OT* __restrict__ out,
148- const IT* __restrict__ in,
149- float in_scale,
150- int32_t in_zero_point,
151- float inv_out_scale,
152- int32_t out_zero_point,
153- size_t size) {
154- xtfloatx2 in_scale_vec = (xtfloatx2)in_scale;
155- xtfloatx2 in_zero_vec = XT_FLOAT_SX2 (in_zero_point, 0 );
156- xtfloatx2 inv_out_scale_vec = (xtfloatx2)inv_out_scale;
157- xtfloatx2 out_zero_vec = XT_FLOAT_SX2 (out_zero_point, 0 );
158-
159- float min_val = std::numeric_limits<OT>::min ();
160- float max_val = std::numeric_limits<OT>::max ();
161-
162- size_t i = 0 ;
163- // Vectorize by 2
164- for (; i < (size & ~1 ); i += 2 ) {
165- xtfloatx2 in_vec = {(float )in[i], (float )in[i + 1 ]};
166- xtfloatx2 t0 = XT_SUB_SX2 (in_vec, in_zero_vec);
167- xtfloatx2 t1 = XT_MUL_SX2 (t0, in_scale_vec);
168-
169- xtfloatx2 acc = out_zero_vec;
170- XT_MADD_SX2 (acc, inv_out_scale_vec, t1);
171- xtfloatx2 t2 = XT_FIROUND_SX2 (acc);
172- ae_int32x2 t3 =
173- XT_UTRUNC_SX2 (XT_MAX_SX2 (XT_MIN_SX2 (t2, max_val), min_val), 0 );
174- out[i] = AE_MOVAD32_H (t3);
175- out[i + 1 ] = AE_MOVAD32_L (t3);
176- }
177- // Handle residual iteration
178- if (i < size) {
179- out[i] = requantize<IT, OT>(
180- in[i], in_scale, in_zero_point, inv_out_scale, out_zero_point);
181- }
182- }
183-
184130// explicit template instantiation
185131
186132#define typed_quantize_val (dtype ) \
@@ -229,34 +175,6 @@ typed_dequantize_vec(uint16_t);
229175typed_dequantize_vec (int32_t );
230176#undef typed_dequantize_vec
231177
232- #define typed_requantize_val (itype, otype ) \
233- template __attribute__((always_inline)) otype requantize ( \
234- const itype in, \
235- float in_scale, \
236- int32_t in_zero_point, \
237- float inv_out_scale, \
238- int32_t out_zero_point);
239- typed_requantize_val (int8_t , int8_t );
240- typed_requantize_val (uint8_t , uint8_t );
241- typed_requantize_val (int8_t , uint8_t );
242- typed_requantize_val (uint8_t , int8_t );
243- #undef typed_requantize_val
244-
245- #define typed_requantize_vec (itype, otype ) \
246- template void requantize ( \
247- otype* __restrict__ out, \
248- const itype* __restrict__ in, \
249- float in_scale, \
250- int32_t in_zero_point, \
251- float inv_out_scale, \
252- int32_t out_zero_point, \
253- size_t size);
254- typed_requantize_vec (int8_t , int8_t );
255- typed_requantize_vec (uint8_t , uint8_t );
256- typed_requantize_vec (int8_t , uint8_t );
257- typed_requantize_vec (uint8_t , int8_t );
258- #undef typed_requantize_vec
259-
260178}; // namespace kernels
261179}; // namespace HiFi
262180}; // namespace impl
0 commit comments