SupportTestsF16.cpp 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. #include "SupportTestsF16.h"
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include "Error.h"
  5. #include "Test.h"
  6. #define SNR_THRESHOLD 120
  7. #define REL_ERROR (1.0e-5)
  8. #define REL_Q15_ERROR (1.0e-3)
  9. #define ABS_WEIGHTEDSUM_ERROR (1.0e-1)
  10. #define REL_WEIGHTEDSUM_ERROR (5.0e-3)
  11. #define ABS_ERROR_F32 (1.0e-3)
  12. #define REL_ERROR_F32 (1.0e-3)
  13. #define ABS_Q15_ERROR ((q15_t)10)
  14. #define ABS_Q31_ERROR ((q31_t)80)
  15. #define ABS_Q7_ERROR ((q7_t)10)
  16. void SupportTestsF16::test_weighted_sum_f16()
  17. {
  18. const float16_t *inp = input.ptr();
  19. const float16_t *coefsp = coefs.ptr();
  20. float16_t *refp = ref.ptr();
  21. float16_t *outp = output.ptr();
  22. *outp=arm_weighted_sum_f16(inp, coefsp,this->nbSamples);
  23. ASSERT_CLOSE_ERROR(*outp,refp[this->offset],ABS_WEIGHTEDSUM_ERROR,REL_WEIGHTEDSUM_ERROR);
  24. ASSERT_EMPTY_TAIL(output);
  25. }
  26. void SupportTestsF16::test_copy_f16()
  27. {
  28. const float16_t *inp = input.ptr();
  29. float16_t *outp = output.ptr();
  30. arm_copy_f16(inp, outp,this->nbSamples);
  31. ASSERT_EQ(input,output);
  32. ASSERT_EMPTY_TAIL(output);
  33. }
  34. void SupportTestsF16::test_fill_f16()
  35. {
  36. float16_t *outp = output.ptr();
  37. float16_t val = 1.1;
  38. int i;
  39. arm_fill_f16(val, outp,this->nbSamples);
  40. for(i=0 ; i < this->nbSamples; i++)
  41. {
  42. ASSERT_EQ(val,outp[i]);
  43. }
  44. ASSERT_EMPTY_TAIL(output);
  45. }
  46. void SupportTestsF16::test_f16_q15()
  47. {
  48. const float16_t *inp = input.ptr();
  49. q15_t *outp = outputQ15.ptr();
  50. arm_f16_to_q15(inp, outp,this->nbSamples);
  51. ASSERT_NEAR_EQ(refQ15,outputQ15,ABS_Q15_ERROR);
  52. ASSERT_EMPTY_TAIL(outputQ15);
  53. }
  54. void SupportTestsF16::test_f16_f32()
  55. {
  56. const float16_t *inp = input.ptr();
  57. float32_t *outp = outputF32.ptr();
  58. arm_f16_to_float(inp, outp,this->nbSamples);
  59. ASSERT_REL_ERROR(refF32,outputF32,REL_ERROR_F32);
  60. ASSERT_EMPTY_TAIL(outputF32);
  61. }
  62. void SupportTestsF16::test_f16_f64()
  63. {
  64. const float16_t *inp = input.ptr();
  65. float64_t *outp = outputF64.ptr();
  66. arm_f16_to_f64(inp, outp,this->nbSamples);
  67. ASSERT_REL_ERROR(refF64,outputF64,REL_ERROR_F32);
  68. ASSERT_EMPTY_TAIL(outputF64);
  69. }
  70. void SupportTestsF16::test_q15_f16()
  71. {
  72. const q15_t *inp = inputQ15.ptr();
  73. float16_t *outp = output.ptr();
  74. arm_q15_to_f16(inp, outp,this->nbSamples);
  75. ASSERT_REL_ERROR(ref,output,REL_Q15_ERROR);
  76. ASSERT_EMPTY_TAIL(output);
  77. }
  78. void SupportTestsF16::test_f32_f16()
  79. {
  80. const float32_t *inp = inputF32.ptr();
  81. float16_t *outp = output.ptr();
  82. arm_float_to_f16(inp, outp,this->nbSamples);
  83. ASSERT_REL_ERROR(ref,output,REL_ERROR);
  84. ASSERT_EMPTY_TAIL(output);
  85. }
  86. void SupportTestsF16::test_f64_f16()
  87. {
  88. const float64_t *inp = inputF64.ptr();
  89. float16_t *outp = output.ptr();
  90. arm_f64_to_f16(inp, outp,this->nbSamples);
  91. ASSERT_REL_ERROR(ref,output,REL_ERROR);
  92. ASSERT_EMPTY_TAIL(output);
  93. }
  94. void SupportTestsF16::setUp(Testing::testID_t id,std::vector<Testing::param_t>& paramsArgs,Client::PatternMgr *mgr)
  95. {
  96. (void)paramsArgs;
  97. switch(id)
  98. {
  99. case TEST_WEIGHTED_SUM_F16_1:
  100. this->nbSamples = 7;
  101. input.reload(SupportTestsF16::INPUTS_F16_ID,mgr,this->nbSamples);
  102. coefs.reload(SupportTestsF16::WEIGHTS_F16_ID,mgr,this->nbSamples);
  103. ref.reload(SupportTestsF16::REF_F16_ID,mgr);
  104. output.create(1,SupportTestsF16::OUT_F16_ID,mgr);
  105. this->offset=0;
  106. break;
  107. case TEST_WEIGHTED_SUM_F16_2:
  108. this->nbSamples = 16;
  109. input.reload(SupportTestsF16::INPUTS_F16_ID,mgr,this->nbSamples);
  110. coefs.reload(SupportTestsF16::WEIGHTS_F16_ID,mgr,this->nbSamples);
  111. ref.reload(SupportTestsF16::REF_F16_ID,mgr);
  112. output.create(1,SupportTestsF16::OUT_F16_ID,mgr);
  113. this->offset=1;
  114. break;
  115. case TEST_WEIGHTED_SUM_F16_3:
  116. this->nbSamples = 23;
  117. input.reload(SupportTestsF16::INPUTS_F16_ID,mgr,this->nbSamples);
  118. coefs.reload(SupportTestsF16::WEIGHTS_F16_ID,mgr,this->nbSamples);
  119. ref.reload(SupportTestsF16::REF_F16_ID,mgr);
  120. output.create(1,SupportTestsF16::OUT_F16_ID,mgr);
  121. this->offset=2;
  122. break;
  123. case TEST_COPY_F16_4:
  124. this->nbSamples = 7;
  125. input.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
  126. output.create(input.nbSamples(),SupportTestsF16::OUT_F16_ID,mgr);
  127. break;
  128. case TEST_COPY_F16_5:
  129. this->nbSamples = 16;
  130. input.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
  131. output.create(input.nbSamples(),SupportTestsF16::OUT_F16_ID,mgr);
  132. break;
  133. case TEST_COPY_F16_6:
  134. this->nbSamples = 23;
  135. input.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
  136. output.create(input.nbSamples(),SupportTestsF16::OUT_F16_ID,mgr);
  137. break;
  138. case TEST_FILL_F16_7:
  139. this->nbSamples = 7;
  140. output.create(this->nbSamples,SupportTestsF16::OUT_F16_ID,mgr);
  141. break;
  142. case TEST_FILL_F16_8:
  143. this->nbSamples = 16;
  144. output.create(this->nbSamples,SupportTestsF16::OUT_F16_ID,mgr);
  145. break;
  146. case TEST_FILL_F16_9:
  147. this->nbSamples = 23;
  148. output.create(this->nbSamples,SupportTestsF16::OUT_F16_ID,mgr);
  149. break;
  150. case TEST_F16_Q15_10:
  151. this->nbSamples = 7;
  152. input.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
  153. refQ15.reload(SupportTestsF16::SAMPLES_Q15_ID,mgr,this->nbSamples);
  154. outputQ15.create(this->nbSamples,SupportTestsF16::OUT_Q15_ID,mgr);
  155. break;
  156. case TEST_F16_Q15_11:
  157. this->nbSamples = 16;
  158. input.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
  159. refQ15.reload(SupportTestsF16::SAMPLES_Q15_ID,mgr,this->nbSamples);
  160. outputQ15.create(this->nbSamples,SupportTestsF16::OUT_Q15_ID,mgr);
  161. break;
  162. case TEST_F16_Q15_12:
  163. this->nbSamples = 23;
  164. input.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
  165. refQ15.reload(SupportTestsF16::SAMPLES_Q15_ID,mgr,this->nbSamples);
  166. outputQ15.create(this->nbSamples,SupportTestsF16::OUT_Q15_ID,mgr);
  167. break;
  168. case TEST_F16_F32_13:
  169. this->nbSamples = 7;
  170. input.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
  171. refF32.reload(SupportTestsF16::SAMPLES_F32_ID,mgr,this->nbSamples);
  172. outputF32.create(this->nbSamples,SupportTestsF16::OUT_F32_ID,mgr);
  173. break;
  174. case TEST_F16_F32_14:
  175. this->nbSamples = 16;
  176. input.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
  177. refF32.reload(SupportTestsF16::SAMPLES_F32_ID,mgr,this->nbSamples);
  178. outputF32.create(this->nbSamples,SupportTestsF16::OUT_F32_ID,mgr);
  179. break;
  180. case TEST_F16_F32_15:
  181. this->nbSamples = 23;
  182. input.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
  183. refF32.reload(SupportTestsF16::SAMPLES_F32_ID,mgr,this->nbSamples);
  184. outputF32.create(this->nbSamples,SupportTestsF16::OUT_F32_ID,mgr);
  185. break;
  186. case TEST_Q15_F16_16:
  187. this->nbSamples = 7;
  188. inputQ15.reload(SupportTestsF16::SAMPLES_Q15_ID,mgr,this->nbSamples);
  189. ref.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
  190. output.create(this->nbSamples,SupportTestsF16::OUT_F16_ID,mgr);
  191. break;
  192. case TEST_Q15_F16_17:
  193. this->nbSamples = 16;
  194. inputQ15.reload(SupportTestsF16::SAMPLES_Q15_ID,mgr,this->nbSamples);
  195. ref.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
  196. output.create(this->nbSamples,SupportTestsF16::OUT_F16_ID,mgr);
  197. break;
  198. case TEST_Q15_F16_18:
  199. this->nbSamples = 23;
  200. inputQ15.reload(SupportTestsF16::SAMPLES_Q15_ID,mgr,this->nbSamples);
  201. ref.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
  202. output.create(this->nbSamples,SupportTestsF16::OUT_F16_ID,mgr);
  203. break;
  204. case TEST_F32_F16_19:
  205. this->nbSamples = 7;
  206. inputF32.reload(SupportTestsF16::SAMPLES_F32_ID,mgr,this->nbSamples);
  207. ref.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
  208. output.create(this->nbSamples,SupportTestsF16::OUT_F16_ID,mgr);
  209. break;
  210. case TEST_F32_F16_20:
  211. this->nbSamples = 16;
  212. inputF32.reload(SupportTestsF16::SAMPLES_F32_ID,mgr,this->nbSamples);
  213. ref.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
  214. output.create(this->nbSamples,SupportTestsF16::OUT_F16_ID,mgr);
  215. break;
  216. case TEST_F32_F16_21:
  217. this->nbSamples = 23;
  218. inputF32.reload(SupportTestsF16::SAMPLES_F32_ID,mgr,this->nbSamples);
  219. ref.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
  220. output.create(this->nbSamples,SupportTestsF16::OUT_F16_ID,mgr);
  221. break;
  222. case TEST_F64_F16_22:
  223. this->nbSamples = 7;
  224. inputF64.reload(SupportTestsF16::SAMPLES_F64_ID,mgr,this->nbSamples);
  225. ref.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
  226. output.create(this->nbSamples,SupportTestsF16::OUT_F16_ID,mgr);
  227. break;
  228. case TEST_F64_F16_23:
  229. this->nbSamples = 16;
  230. inputF64.reload(SupportTestsF16::SAMPLES_F64_ID,mgr,this->nbSamples);
  231. ref.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
  232. output.create(this->nbSamples,SupportTestsF16::OUT_F16_ID,mgr);
  233. break;
  234. case TEST_F64_F16_24:
  235. this->nbSamples = 23;
  236. inputF64.reload(SupportTestsF16::SAMPLES_F64_ID,mgr,this->nbSamples);
  237. ref.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
  238. output.create(this->nbSamples,SupportTestsF16::OUT_F16_ID,mgr);
  239. break;
  240. case TEST_F16_F64_25:
  241. this->nbSamples = 7;
  242. input.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
  243. refF64.reload(SupportTestsF16::SAMPLES_F64_ID,mgr,this->nbSamples);
  244. outputF64.create(this->nbSamples,SupportTestsF16::OUT_F32_ID,mgr);
  245. break;
  246. case TEST_F16_F64_26:
  247. this->nbSamples = 16;
  248. input.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
  249. refF64.reload(SupportTestsF16::SAMPLES_F64_ID,mgr,this->nbSamples);
  250. outputF64.create(this->nbSamples,SupportTestsF16::OUT_F32_ID,mgr);
  251. break;
  252. case TEST_F16_F64_27:
  253. this->nbSamples = 23;
  254. input.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
  255. refF64.reload(SupportTestsF16::SAMPLES_F64_ID,mgr,this->nbSamples);
  256. outputF64.create(this->nbSamples,SupportTestsF16::OUT_F32_ID,mgr);
  257. break;
  258. }
  259. }
  260. void SupportTestsF16::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
  261. {
  262. (void)id;
  263. output.dump(mgr);
  264. }