FastMathF16.cpp 6.5 KB

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