SupportTestsF16.cpp 7.6 KB

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