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