1 #include "SupportTestsF16.h"
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include "Error.h"
5 #include "Test.h"
6
7 #define SNR_THRESHOLD 120
8 #define REL_ERROR (1.0e-5)
9 #define REL_Q15_ERROR (1.0e-3)
10
11 #define ABS_WEIGHTEDSUM_ERROR (1.0e-1)
12 #define REL_WEIGHTEDSUM_ERROR (5.0e-3)
13
14 #define ABS_ERROR_F32 (1.0e-3)
15 #define REL_ERROR_F32 (1.0e-3)
16
17 #define ABS_Q15_ERROR ((q15_t)10)
18 #define ABS_Q31_ERROR ((q31_t)80)
19 #define ABS_Q7_ERROR ((q7_t)10)
20
21
test_weighted_average_f16()22 void SupportTestsF16::test_weighted_average_f16()
23 {
24 const float16_t *inp = input.ptr();
25 const float16_t *coefsp = coefs.ptr();
26 float16_t *refp = ref.ptr();
27
28 float16_t *outp = output.ptr();
29
30
31 *outp=arm_weighted_average_f16(inp, coefsp,this->nbSamples);
32
33 ASSERT_CLOSE_ERROR(*outp,refp[this->offset],ABS_WEIGHTEDSUM_ERROR,REL_WEIGHTEDSUM_ERROR);
34 ASSERT_EMPTY_TAIL(output);
35
36 }
37
38
test_copy_f16()39 void SupportTestsF16::test_copy_f16()
40 {
41 const float16_t *inp = input.ptr();
42 float16_t *outp = output.ptr();
43
44
45 arm_copy_f16(inp, outp,this->nbSamples);
46
47
48 ASSERT_EQ(input,output);
49 ASSERT_EMPTY_TAIL(output);
50
51 }
52
test_fill_f16()53 void SupportTestsF16::test_fill_f16()
54 {
55 float16_t *outp = output.ptr();
56 float16_t val = 1.1;
57 int i;
58
59
60 arm_fill_f16(val, outp,this->nbSamples);
61
62
63 for(i=0 ; i < this->nbSamples; i++)
64 {
65 ASSERT_EQ(val,outp[i]);
66 }
67 ASSERT_EMPTY_TAIL(output);
68
69 }
70
test_f16_q15()71 void SupportTestsF16::test_f16_q15()
72 {
73 const float16_t *inp = input.ptr();
74 q15_t *outp = outputQ15.ptr();
75
76
77 arm_f16_to_q15(inp, outp,this->nbSamples);
78
79
80 ASSERT_NEAR_EQ(refQ15,outputQ15,ABS_Q15_ERROR);
81 ASSERT_EMPTY_TAIL(outputQ15);
82
83 }
84
test_f16_f32()85 void SupportTestsF16::test_f16_f32()
86 {
87 const float16_t *inp = input.ptr();
88 float32_t *outp = outputF32.ptr();
89
90
91 arm_f16_to_float(inp, outp,this->nbSamples);
92
93
94 ASSERT_REL_ERROR(refF32,outputF32,REL_ERROR_F32);
95 ASSERT_EMPTY_TAIL(outputF32);
96
97 }
98
test_f16_f64()99 void SupportTestsF16::test_f16_f64()
100 {
101 const float16_t *inp = input.ptr();
102 float64_t *outp = outputF64.ptr();
103
104
105 arm_f16_to_f64(inp, outp,this->nbSamples);
106
107
108 ASSERT_REL_ERROR(refF64,outputF64,REL_ERROR_F32);
109 ASSERT_EMPTY_TAIL(outputF64);
110
111 }
112
test_q15_f16()113 void SupportTestsF16::test_q15_f16()
114 {
115 const q15_t *inp = inputQ15.ptr();
116 float16_t *outp = output.ptr();
117
118
119 arm_q15_to_f16(inp, outp,this->nbSamples);
120
121
122 ASSERT_REL_ERROR(ref,output,REL_Q15_ERROR);
123 ASSERT_EMPTY_TAIL(output);
124
125 }
126
test_f32_f16()127 void SupportTestsF16::test_f32_f16()
128 {
129 const float32_t *inp = inputF32.ptr();
130 float16_t *outp = output.ptr();
131
132
133 arm_float_to_f16(inp, outp,this->nbSamples);
134
135
136 ASSERT_REL_ERROR(ref,output,REL_ERROR);
137 ASSERT_EMPTY_TAIL(output);
138
139 }
140
test_f64_f16()141 void SupportTestsF16::test_f64_f16()
142 {
143 const float64_t *inp = inputF64.ptr();
144 float16_t *outp = output.ptr();
145
146
147 arm_f64_to_f16(inp, outp,this->nbSamples);
148
149
150 ASSERT_REL_ERROR(ref,output,REL_ERROR);
151 ASSERT_EMPTY_TAIL(output);
152
153 }
154
155
setUp(Testing::testID_t id,std::vector<Testing::param_t> & paramsArgs,Client::PatternMgr * mgr)156 void SupportTestsF16::setUp(Testing::testID_t id,std::vector<Testing::param_t>& paramsArgs,Client::PatternMgr *mgr)
157 {
158
159 (void)paramsArgs;
160 switch(id)
161 {
162
163 case TEST_WEIGHTED_AVERAGE_F16_1:
164 this->nbSamples = 7;
165 input.reload(SupportTestsF16::INPUTS_F16_ID,mgr,this->nbSamples);
166 coefs.reload(SupportTestsF16::WEIGHTS_F16_ID,mgr,this->nbSamples);
167 ref.reload(SupportTestsF16::REF_F16_ID,mgr);
168
169 output.create(1,SupportTestsF16::OUT_F16_ID,mgr);
170
171 this->offset=0;
172 break;
173
174 case TEST_WEIGHTED_AVERAGE_F16_2:
175 this->nbSamples = 16;
176 input.reload(SupportTestsF16::INPUTS_F16_ID,mgr,this->nbSamples);
177 coefs.reload(SupportTestsF16::WEIGHTS_F16_ID,mgr,this->nbSamples);
178 ref.reload(SupportTestsF16::REF_F16_ID,mgr);
179
180 output.create(1,SupportTestsF16::OUT_F16_ID,mgr);
181
182 this->offset=1;
183 break;
184
185 case TEST_WEIGHTED_AVERAGE_F16_3:
186 this->nbSamples = 23;
187 input.reload(SupportTestsF16::INPUTS_F16_ID,mgr,this->nbSamples);
188 coefs.reload(SupportTestsF16::WEIGHTS_F16_ID,mgr,this->nbSamples);
189 ref.reload(SupportTestsF16::REF_F16_ID,mgr);
190
191 output.create(1,SupportTestsF16::OUT_F16_ID,mgr);
192
193 this->offset=2;
194 break;
195
196 case TEST_COPY_F16_4:
197 this->nbSamples = 7;
198 input.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
199
200 output.create(input.nbSamples(),SupportTestsF16::OUT_F16_ID,mgr);
201
202 break;
203
204 case TEST_COPY_F16_5:
205 this->nbSamples = 16;
206 input.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
207
208 output.create(input.nbSamples(),SupportTestsF16::OUT_F16_ID,mgr);
209
210 break;
211
212 case TEST_COPY_F16_6:
213 this->nbSamples = 23;
214 input.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
215
216 output.create(input.nbSamples(),SupportTestsF16::OUT_F16_ID,mgr);
217
218 break;
219
220 case TEST_FILL_F16_7:
221 this->nbSamples = 7;
222
223 output.create(this->nbSamples,SupportTestsF16::OUT_F16_ID,mgr);
224
225 break;
226
227 case TEST_FILL_F16_8:
228 this->nbSamples = 16;
229
230 output.create(this->nbSamples,SupportTestsF16::OUT_F16_ID,mgr);
231
232 break;
233
234 case TEST_FILL_F16_9:
235 this->nbSamples = 23;
236
237 output.create(this->nbSamples,SupportTestsF16::OUT_F16_ID,mgr);
238
239 break;
240
241 case TEST_F16_Q15_10:
242 this->nbSamples = 7;
243 input.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
244 refQ15.reload(SupportTestsF16::SAMPLES_Q15_ID,mgr,this->nbSamples);
245 outputQ15.create(this->nbSamples,SupportTestsF16::OUT_Q15_ID,mgr);
246
247 break;
248
249 case TEST_F16_Q15_11:
250 this->nbSamples = 16;
251 input.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
252 refQ15.reload(SupportTestsF16::SAMPLES_Q15_ID,mgr,this->nbSamples);
253 outputQ15.create(this->nbSamples,SupportTestsF16::OUT_Q15_ID,mgr);
254
255 break;
256
257 case TEST_F16_Q15_12:
258 this->nbSamples = 23;
259 input.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
260 refQ15.reload(SupportTestsF16::SAMPLES_Q15_ID,mgr,this->nbSamples);
261 outputQ15.create(this->nbSamples,SupportTestsF16::OUT_Q15_ID,mgr);
262
263 break;
264
265 case TEST_F16_F32_13:
266 this->nbSamples = 7;
267 input.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
268 refF32.reload(SupportTestsF16::SAMPLES_F32_ID,mgr,this->nbSamples);
269 outputF32.create(this->nbSamples,SupportTestsF16::OUT_F32_ID,mgr);
270
271 break;
272
273 case TEST_F16_F32_14:
274 this->nbSamples = 16;
275 input.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
276 refF32.reload(SupportTestsF16::SAMPLES_F32_ID,mgr,this->nbSamples);
277 outputF32.create(this->nbSamples,SupportTestsF16::OUT_F32_ID,mgr);
278
279 break;
280
281 case TEST_F16_F32_15:
282 this->nbSamples = 23;
283 input.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
284 refF32.reload(SupportTestsF16::SAMPLES_F32_ID,mgr,this->nbSamples);
285 outputF32.create(this->nbSamples,SupportTestsF16::OUT_F32_ID,mgr);
286
287 break;
288
289 case TEST_Q15_F16_16:
290 this->nbSamples = 7;
291 inputQ15.reload(SupportTestsF16::SAMPLES_Q15_ID,mgr,this->nbSamples);
292 ref.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
293 output.create(this->nbSamples,SupportTestsF16::OUT_F16_ID,mgr);
294
295 break;
296
297 case TEST_Q15_F16_17:
298 this->nbSamples = 16;
299 inputQ15.reload(SupportTestsF16::SAMPLES_Q15_ID,mgr,this->nbSamples);
300 ref.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
301 output.create(this->nbSamples,SupportTestsF16::OUT_F16_ID,mgr);
302
303 break;
304
305 case TEST_Q15_F16_18:
306 this->nbSamples = 23;
307 inputQ15.reload(SupportTestsF16::SAMPLES_Q15_ID,mgr,this->nbSamples);
308 ref.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
309 output.create(this->nbSamples,SupportTestsF16::OUT_F16_ID,mgr);
310
311 break;
312
313 case TEST_F32_F16_19:
314 this->nbSamples = 7;
315 inputF32.reload(SupportTestsF16::SAMPLES_F32_ID,mgr,this->nbSamples);
316 ref.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
317 output.create(this->nbSamples,SupportTestsF16::OUT_F16_ID,mgr);
318
319 break;
320
321 case TEST_F32_F16_20:
322 this->nbSamples = 16;
323 inputF32.reload(SupportTestsF16::SAMPLES_F32_ID,mgr,this->nbSamples);
324 ref.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
325 output.create(this->nbSamples,SupportTestsF16::OUT_F16_ID,mgr);
326
327 break;
328
329 case TEST_F32_F16_21:
330 this->nbSamples = 23;
331 inputF32.reload(SupportTestsF16::SAMPLES_F32_ID,mgr,this->nbSamples);
332 ref.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
333 output.create(this->nbSamples,SupportTestsF16::OUT_F16_ID,mgr);
334
335 break;
336
337 case TEST_F64_F16_22:
338 this->nbSamples = 7;
339 inputF64.reload(SupportTestsF16::SAMPLES_F64_ID,mgr,this->nbSamples);
340 ref.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
341 output.create(this->nbSamples,SupportTestsF16::OUT_F16_ID,mgr);
342
343 break;
344
345 case TEST_F64_F16_23:
346 this->nbSamples = 16;
347 inputF64.reload(SupportTestsF16::SAMPLES_F64_ID,mgr,this->nbSamples);
348 ref.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
349 output.create(this->nbSamples,SupportTestsF16::OUT_F16_ID,mgr);
350
351 break;
352
353 case TEST_F64_F16_24:
354 this->nbSamples = 23;
355 inputF64.reload(SupportTestsF16::SAMPLES_F64_ID,mgr,this->nbSamples);
356 ref.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
357 output.create(this->nbSamples,SupportTestsF16::OUT_F16_ID,mgr);
358
359 break;
360
361 case TEST_F16_F64_25:
362 this->nbSamples = 7;
363 input.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
364 refF64.reload(SupportTestsF16::SAMPLES_F64_ID,mgr,this->nbSamples);
365 outputF64.create(this->nbSamples,SupportTestsF16::OUT_F32_ID,mgr);
366
367 break;
368
369 case TEST_F16_F64_26:
370 this->nbSamples = 16;
371 input.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
372 refF64.reload(SupportTestsF16::SAMPLES_F64_ID,mgr,this->nbSamples);
373 outputF64.create(this->nbSamples,SupportTestsF16::OUT_F32_ID,mgr);
374
375 break;
376
377 case TEST_F16_F64_27:
378 this->nbSamples = 23;
379 input.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
380 refF64.reload(SupportTestsF16::SAMPLES_F64_ID,mgr,this->nbSamples);
381 outputF64.create(this->nbSamples,SupportTestsF16::OUT_F32_ID,mgr);
382
383 break;
384
385
386 }
387
388 }
389
tearDown(Testing::testID_t id,Client::PatternMgr * mgr)390 void SupportTestsF16::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
391 {
392 (void)id;
393 output.dump(mgr);
394 }
395