SupportTestsF16.cpp 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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 ABS_WEIGHTEDSUM_ERROR (1.0e-1)
  9. #define REL_WEIGHTEDSUM_ERROR (5.0e-3)
  10. #define ABS_ERROR_F32 (1.0e-3)
  11. #define REL_ERROR_F32 (1.0e-3)
  12. #define ABS_Q15_ERROR ((q15_t)10)
  13. #define ABS_Q31_ERROR ((q31_t)80)
  14. #define ABS_Q7_ERROR ((q7_t)10)
  15. void SupportTestsF16::test_weighted_sum_f16()
  16. {
  17. const float16_t *inp = input.ptr();
  18. const float16_t *coefsp = coefs.ptr();
  19. float16_t *refp = ref.ptr();
  20. float16_t *outp = output.ptr();
  21. *outp=arm_weighted_sum_f16(inp, coefsp,this->nbSamples);
  22. ASSERT_CLOSE_ERROR(*outp,refp[this->offset],ABS_WEIGHTEDSUM_ERROR,REL_WEIGHTEDSUM_ERROR);
  23. ASSERT_EMPTY_TAIL(output);
  24. }
  25. void SupportTestsF16::test_copy_f16()
  26. {
  27. const float16_t *inp = input.ptr();
  28. float16_t *outp = output.ptr();
  29. arm_copy_f16(inp, outp,this->nbSamples);
  30. ASSERT_EQ(input,output);
  31. ASSERT_EMPTY_TAIL(output);
  32. }
  33. void SupportTestsF16::test_fill_f16()
  34. {
  35. float16_t *outp = output.ptr();
  36. float16_t val = 1.1;
  37. int i;
  38. arm_fill_f16(val, outp,this->nbSamples);
  39. for(i=0 ; i < this->nbSamples; i++)
  40. {
  41. ASSERT_EQ(val,outp[i]);
  42. }
  43. ASSERT_EMPTY_TAIL(output);
  44. }
  45. void SupportTestsF16::test_f16_q15()
  46. {
  47. const float16_t *inp = input.ptr();
  48. q15_t *outp = outputQ15.ptr();
  49. arm_f16_to_q15(inp, outp,this->nbSamples);
  50. ASSERT_NEAR_EQ(refQ15,outputQ15,ABS_Q15_ERROR);
  51. ASSERT_EMPTY_TAIL(outputQ15);
  52. }
  53. void SupportTestsF16::test_f16_f32()
  54. {
  55. const float16_t *inp = input.ptr();
  56. float32_t *outp = outputF32.ptr();
  57. arm_f16_to_float(inp, outp,this->nbSamples);
  58. ASSERT_REL_ERROR(refF32,outputF32,REL_ERROR_F32);
  59. ASSERT_EMPTY_TAIL(outputF32);
  60. }
  61. void SupportTestsF16::test_q15_f16()
  62. {
  63. const q15_t *inp = inputQ15.ptr();
  64. float16_t *outp = output.ptr();
  65. arm_q15_to_f16(inp, outp,this->nbSamples);
  66. ASSERT_REL_ERROR(ref,output,REL_ERROR);
  67. ASSERT_EMPTY_TAIL(outputF32);
  68. }
  69. void SupportTestsF16::test_f32_f16()
  70. {
  71. const float32_t *inp = inputF32.ptr();
  72. float16_t *outp = output.ptr();
  73. arm_float_to_f16(inp, outp,this->nbSamples);
  74. ASSERT_REL_ERROR(ref,output,REL_ERROR);
  75. ASSERT_EMPTY_TAIL(outputF32);
  76. }
  77. void SupportTestsF16::setUp(Testing::testID_t id,std::vector<Testing::param_t>& paramsArgs,Client::PatternMgr *mgr)
  78. {
  79. (void)paramsArgs;
  80. switch(id)
  81. {
  82. case TEST_WEIGHTED_SUM_F16_1:
  83. this->nbSamples = 7;
  84. input.reload(SupportTestsF16::INPUTS_F16_ID,mgr,this->nbSamples);
  85. coefs.reload(SupportTestsF16::WEIGHTS_F16_ID,mgr,this->nbSamples);
  86. ref.reload(SupportTestsF16::REF_F16_ID,mgr);
  87. output.create(1,SupportTestsF16::OUT_F16_ID,mgr);
  88. this->offset=0;
  89. break;
  90. case TEST_WEIGHTED_SUM_F16_2:
  91. this->nbSamples = 16;
  92. input.reload(SupportTestsF16::INPUTS_F16_ID,mgr,this->nbSamples);
  93. coefs.reload(SupportTestsF16::WEIGHTS_F16_ID,mgr,this->nbSamples);
  94. ref.reload(SupportTestsF16::REF_F16_ID,mgr);
  95. output.create(1,SupportTestsF16::OUT_F16_ID,mgr);
  96. this->offset=1;
  97. break;
  98. case TEST_WEIGHTED_SUM_F16_3:
  99. this->nbSamples = 23;
  100. input.reload(SupportTestsF16::INPUTS_F16_ID,mgr,this->nbSamples);
  101. coefs.reload(SupportTestsF16::WEIGHTS_F16_ID,mgr,this->nbSamples);
  102. ref.reload(SupportTestsF16::REF_F16_ID,mgr);
  103. output.create(1,SupportTestsF16::OUT_F16_ID,mgr);
  104. this->offset=2;
  105. break;
  106. case TEST_COPY_F16_4:
  107. this->nbSamples = 7;
  108. input.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
  109. output.create(input.nbSamples(),SupportTestsF16::OUT_F16_ID,mgr);
  110. break;
  111. case TEST_COPY_F16_5:
  112. this->nbSamples = 16;
  113. input.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
  114. output.create(input.nbSamples(),SupportTestsF16::OUT_F16_ID,mgr);
  115. break;
  116. case TEST_COPY_F16_6:
  117. this->nbSamples = 23;
  118. input.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
  119. output.create(input.nbSamples(),SupportTestsF16::OUT_F16_ID,mgr);
  120. break;
  121. case TEST_FILL_F16_7:
  122. this->nbSamples = 7;
  123. output.create(this->nbSamples,SupportTestsF16::OUT_F16_ID,mgr);
  124. break;
  125. case TEST_FILL_F16_8:
  126. this->nbSamples = 16;
  127. output.create(this->nbSamples,SupportTestsF16::OUT_F16_ID,mgr);
  128. break;
  129. case TEST_FILL_F16_9:
  130. this->nbSamples = 23;
  131. output.create(this->nbSamples,SupportTestsF16::OUT_F16_ID,mgr);
  132. break;
  133. case TEST_F16_Q15_10:
  134. this->nbSamples = 7;
  135. input.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
  136. refQ15.reload(SupportTestsF16::SAMPLES_Q15_ID,mgr,this->nbSamples);
  137. outputQ15.create(this->nbSamples,SupportTestsF16::OUT_Q15_ID,mgr);
  138. break;
  139. case TEST_F16_Q15_11:
  140. this->nbSamples = 16;
  141. input.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
  142. refQ15.reload(SupportTestsF16::SAMPLES_Q15_ID,mgr,this->nbSamples);
  143. outputQ15.create(this->nbSamples,SupportTestsF16::OUT_Q15_ID,mgr);
  144. break;
  145. case TEST_F16_Q15_12:
  146. this->nbSamples = 23;
  147. input.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
  148. refQ15.reload(SupportTestsF16::SAMPLES_Q15_ID,mgr,this->nbSamples);
  149. outputQ15.create(this->nbSamples,SupportTestsF16::OUT_Q15_ID,mgr);
  150. break;
  151. case TEST_F16_F32_13:
  152. this->nbSamples = 7;
  153. input.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
  154. refF32.reload(SupportTestsF16::SAMPLES_F32_ID,mgr,this->nbSamples);
  155. outputF32.create(this->nbSamples,SupportTestsF16::OUT_F32_ID,mgr);
  156. break;
  157. case TEST_F16_F32_14:
  158. this->nbSamples = 16;
  159. input.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
  160. refF32.reload(SupportTestsF16::SAMPLES_F32_ID,mgr,this->nbSamples);
  161. outputF32.create(this->nbSamples,SupportTestsF16::OUT_F32_ID,mgr);
  162. break;
  163. case TEST_F16_F32_15:
  164. this->nbSamples = 23;
  165. input.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
  166. refF32.reload(SupportTestsF16::SAMPLES_F32_ID,mgr,this->nbSamples);
  167. outputF32.create(this->nbSamples,SupportTestsF16::OUT_F32_ID,mgr);
  168. break;
  169. case TEST_Q15_F16_16:
  170. this->nbSamples = 7;
  171. inputQ15.reload(SupportTestsF16::SAMPLES_Q15_ID,mgr,this->nbSamples);
  172. ref.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
  173. output.create(this->nbSamples,SupportTestsF16::OUT_F16_ID,mgr);
  174. break;
  175. case TEST_Q15_F16_17:
  176. this->nbSamples = 16;
  177. inputQ15.reload(SupportTestsF16::SAMPLES_Q15_ID,mgr,this->nbSamples);
  178. ref.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
  179. output.create(this->nbSamples,SupportTestsF16::OUT_F16_ID,mgr);
  180. break;
  181. case TEST_Q15_F16_18:
  182. this->nbSamples = 23;
  183. inputQ15.reload(SupportTestsF16::SAMPLES_Q15_ID,mgr,this->nbSamples);
  184. ref.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
  185. output.create(this->nbSamples,SupportTestsF16::OUT_F16_ID,mgr);
  186. break;
  187. case TEST_F32_F16_19:
  188. this->nbSamples = 7;
  189. inputF32.reload(SupportTestsF16::SAMPLES_F32_ID,mgr,this->nbSamples);
  190. ref.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
  191. output.create(this->nbSamples,SupportTestsF16::OUT_F16_ID,mgr);
  192. break;
  193. case TEST_F32_F16_20:
  194. this->nbSamples = 16;
  195. inputF32.reload(SupportTestsF16::SAMPLES_F32_ID,mgr,this->nbSamples);
  196. ref.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
  197. output.create(this->nbSamples,SupportTestsF16::OUT_F16_ID,mgr);
  198. break;
  199. case TEST_F32_F16_21:
  200. this->nbSamples = 23;
  201. inputF32.reload(SupportTestsF16::SAMPLES_F32_ID,mgr,this->nbSamples);
  202. ref.reload(SupportTestsF16::SAMPLES_F16_ID,mgr,this->nbSamples);
  203. output.create(this->nbSamples,SupportTestsF16::OUT_F16_ID,mgr);
  204. break;
  205. }
  206. }
  207. void SupportTestsF16::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
  208. {
  209. (void)id;
  210. output.dump(mgr);
  211. }