FastMathF16.cpp 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. #include "FastMathF16.h"
  2. #include <stdio.h>
  3. #include "Error.h"
  4. #include "Test.h"
  5. #define SNR_THRESHOLD 60
  6. #define SNR_LOG_THRESHOLD 40
  7. #define SNR_ATAN2_THRESHOLD 60
  8. /*
  9. Reference patterns are generated with
  10. a double precision computation.
  11. */
  12. #define REL_ERROR (1.0e-3)
  13. #define ABS_ERROR (1.0e-3)
  14. #define REL_ERROR_ATAN (1.0e-3)
  15. #define ABS_ERROR_ATAN (2.0e-3)
  16. #if 0
  17. void FastMathF16::test_cos_f16()
  18. {
  19. const float16_t *inp = input.ptr();
  20. float16_t *outp = output.ptr();
  21. unsigned long i;
  22. for(i=0; i < ref.nbSamples(); i++)
  23. {
  24. outp[i]=arm_cos_f16(inp[i]);
  25. }
  26. ASSERT_SNR(ref,output,(float16_t)SNR_THRESHOLD);
  27. ASSERT_CLOSE_ERROR(ref,output,ABS_ERROR,REL_ERROR);
  28. }
  29. void FastMathF16::test_sin_f16()
  30. {
  31. const float16_t *inp = input.ptr();
  32. float16_t *outp = output.ptr();
  33. unsigned long i;
  34. for(i=0; i < ref.nbSamples(); i++)
  35. {
  36. outp[i]=arm_sin_f16(inp[i]);
  37. }
  38. ASSERT_SNR(ref,output,(float16_t)SNR_THRESHOLD);
  39. ASSERT_CLOSE_ERROR(ref,output,ABS_ERROR,REL_ERROR);
  40. }
  41. #endif
  42. void FastMathF16::test_atan2_scalar_f16()
  43. {
  44. const float16_t *inp = input.ptr();
  45. float16_t *outp = output.ptr();
  46. float16_t res;
  47. unsigned long i;
  48. arm_status status=ARM_MATH_SUCCESS;
  49. for(i=0; i < ref.nbSamples(); i++)
  50. {
  51. status=arm_atan2_f16(inp[2*i],inp[2*i+1],&res);
  52. outp[i]=res;
  53. ASSERT_TRUE((status == ARM_MATH_SUCCESS));
  54. }
  55. //printf("%f %f %f\n",inp[2*i],inp[2*i+1],outp[i]);
  56. ASSERT_SNR(ref,output,(float16_t)SNR_ATAN2_THRESHOLD);
  57. ASSERT_CLOSE_ERROR(ref,output,ABS_ERROR_ATAN,REL_ERROR_ATAN);
  58. }
  59. void FastMathF16::test_sqrt_f16()
  60. {
  61. const float16_t *inp = input.ptr();
  62. float16_t *outp = output.ptr();
  63. arm_status status;
  64. unsigned long i;
  65. for(i=0; i < ref.nbSamples(); i++)
  66. {
  67. status=arm_sqrt_f16(inp[i],&outp[i]);
  68. ASSERT_TRUE((status == ARM_MATH_SUCCESS) || ((inp[i] < 0.0f) && (status == ARM_MATH_ARGUMENT_ERROR)));
  69. }
  70. ASSERT_SNR(ref,output,(float16_t)SNR_THRESHOLD);
  71. ASSERT_CLOSE_ERROR(ref,output,ABS_ERROR,REL_ERROR);
  72. }
  73. void FastMathF16::test_vlog_f16()
  74. {
  75. const float16_t *inp = input.ptr();
  76. float16_t *outp = output.ptr();
  77. arm_vlog_f16(inp,outp,ref.nbSamples());
  78. //ASSERT_SNR(ref,output,(float16_t)SNR_THRESHOLD);
  79. ASSERT_CLOSE_ERROR(ref,output,ABS_ERROR,REL_ERROR);
  80. ASSERT_EMPTY_TAIL(output);
  81. }
  82. void FastMathF16::test_vexp_f16()
  83. {
  84. const float16_t *inp = input.ptr();
  85. float16_t *outp = output.ptr();
  86. arm_vexp_f16(inp,outp,ref.nbSamples());
  87. ASSERT_CLOSE_ERROR(ref,output,ABS_ERROR,REL_ERROR);
  88. ASSERT_SNR(ref,output,(float16_t)SNR_THRESHOLD);
  89. ASSERT_EMPTY_TAIL(output);
  90. }
  91. void FastMathF16::test_inverse_f16()
  92. {
  93. const float16_t *inp = input.ptr();
  94. float16_t *outp = output.ptr();
  95. arm_vinverse_f16(inp,outp,ref.nbSamples());
  96. ASSERT_CLOSE_ERROR(ref,output,ABS_ERROR,REL_ERROR);
  97. ASSERT_SNR(ref,output,(float16_t)SNR_THRESHOLD);
  98. ASSERT_EMPTY_TAIL(output);
  99. }
  100. void FastMathF16::setUp(Testing::testID_t id,std::vector<Testing::param_t>& paramsArgs,Client::PatternMgr *mgr)
  101. {
  102. (void)paramsArgs;
  103. switch(id)
  104. {
  105. #if 0
  106. case FastMathF16::TEST_COS_F16_1:
  107. {
  108. input.reload(FastMathF16::ANGLES1_F16_ID,mgr);
  109. ref.reload(FastMathF16::COS1_F16_ID,mgr);
  110. output.create(ref.nbSamples(),FastMathF16::OUT_F16_ID,mgr);
  111. }
  112. break;
  113. case FastMathF16::TEST_SIN_F16_2:
  114. {
  115. input.reload(FastMathF16::ANGLES1_F16_ID,mgr);
  116. ref.reload(FastMathF16::SIN1_F16_ID,mgr);
  117. output.create(ref.nbSamples(),FastMathF16::OUT_F16_ID,mgr);
  118. }
  119. break;
  120. #endif
  121. case FastMathF16::TEST_SQRT_F16_3:
  122. {
  123. input.reload(FastMathF16::SQRTINPUT1_F16_ID,mgr);
  124. ref.reload(FastMathF16::SQRT1_F16_ID,mgr);
  125. output.create(ref.nbSamples(),FastMathF16::OUT_F16_ID,mgr);
  126. }
  127. break;
  128. case FastMathF16::TEST_VLOG_F16_4:
  129. {
  130. input.reload(FastMathF16::LOGINPUT1_F16_ID,mgr);
  131. ref.reload(FastMathF16::LOG1_F16_ID,mgr);
  132. output.create(ref.nbSamples(),FastMathF16::OUT_F16_ID,mgr);
  133. }
  134. break;
  135. case FastMathF16::TEST_VLOG_F16_5:
  136. {
  137. input.reload(FastMathF16::LOGINPUT1_F16_ID,mgr,7);
  138. ref.reload(FastMathF16::LOG1_F16_ID,mgr,7);
  139. output.create(ref.nbSamples(),FastMathF16::OUT_F16_ID,mgr);
  140. }
  141. break;
  142. case FastMathF16::TEST_VLOG_F16_6:
  143. {
  144. input.reload(FastMathF16::LOGINPUT1_F16_ID,mgr,16);
  145. ref.reload(FastMathF16::LOG1_F16_ID,mgr,16);
  146. output.create(ref.nbSamples(),FastMathF16::OUT_F16_ID,mgr);
  147. }
  148. break;
  149. case FastMathF16::TEST_VLOG_F16_7:
  150. {
  151. input.reload(FastMathF16::LOGINPUT1_F16_ID,mgr,23);
  152. ref.reload(FastMathF16::LOG1_F16_ID,mgr,23);
  153. output.create(ref.nbSamples(),FastMathF16::OUT_F16_ID,mgr);
  154. }
  155. break;
  156. case FastMathF16::TEST_VEXP_F16_8:
  157. {
  158. input.reload(FastMathF16::EXPINPUT1_F16_ID,mgr);
  159. ref.reload(FastMathF16::EXP1_F16_ID,mgr);
  160. output.create(ref.nbSamples(),FastMathF16::OUT_F16_ID,mgr);
  161. }
  162. break;
  163. case FastMathF16::TEST_VEXP_F16_9:
  164. {
  165. input.reload(FastMathF16::EXPINPUT1_F16_ID,mgr,7);
  166. ref.reload(FastMathF16::EXP1_F16_ID,mgr,7);
  167. output.create(ref.nbSamples(),FastMathF16::OUT_F16_ID,mgr);
  168. }
  169. break;
  170. case FastMathF16::TEST_VEXP_F16_10:
  171. {
  172. input.reload(FastMathF16::EXPINPUT1_F16_ID,mgr,16);
  173. ref.reload(FastMathF16::EXP1_F16_ID,mgr,16);
  174. output.create(ref.nbSamples(),FastMathF16::OUT_F16_ID,mgr);
  175. }
  176. break;
  177. case FastMathF16::TEST_VEXP_F16_11:
  178. {
  179. input.reload(FastMathF16::EXPINPUT1_F16_ID,mgr,23);
  180. ref.reload(FastMathF16::EXP1_F16_ID,mgr,23);
  181. output.create(ref.nbSamples(),FastMathF16::OUT_F16_ID,mgr);
  182. }
  183. break;
  184. case FastMathF16::TEST_INVERSE_F16_12:
  185. {
  186. input.reload(FastMathF16::INPUT1_F16_ID,mgr);
  187. ref.reload(FastMathF16::INVERSE1_F16_ID,mgr);
  188. output.create(ref.nbSamples(),FastMathF16::OUT_F16_ID,mgr);
  189. }
  190. break;
  191. case FastMathF16::TEST_ATAN2_SCALAR_F16_13:
  192. {
  193. input.reload(FastMathF16::ATAN2INPUT1_F16_ID,mgr);
  194. ref.reload(FastMathF16::ATAN2_F16_ID,mgr);
  195. output.create(ref.nbSamples(),FastMathF16::OUT_F16_ID,mgr);
  196. }
  197. break;
  198. }
  199. }
  200. void FastMathF16::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
  201. {
  202. (void)id;
  203. output.dump(mgr);
  204. }