FastMathF16.cpp 6.4 KB

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