1 #include "BinaryTestsF16.h" 2 #include <stdio.h> 3 #include "Error.h" 4 5 #define SNR_THRESHOLD 60 6 7 /* 8 9 Reference patterns are generated with 10 a double precision computation. 11 12 */ 13 #define REL_ERROR (2.0e-3) 14 #define ABS_ERROR (2.0e-3) 15 16 17 /* Upper bound of maximum matrix dimension used by Python */ 18 #define MAXMATRIXDIM 40 19 20 21 #define LOADDATA2() \ 22 const float16_t *inp1=input1.ptr(); \ 23 const float16_t *inp2=input2.ptr(); \ 24 \ 25 float16_t *ap=a.ptr(); \ 26 float16_t *bp=b.ptr(); \ 27 \ 28 float16_t *outp=output.ptr(); \ 29 int16_t *dimsp = dims.ptr(); \ 30 int nbMatrixes = dims.nbSamples() / 3;\ 31 int rows,internal,columns; \ 32 int i; 33 34 35 36 37 38 #define PREPAREDATA2() \ 39 in1.numRows=rows; \ 40 in1.numCols=internal; \ 41 memcpy((void*)ap,(const void*)inp1,2*sizeof(float16_t)*rows*internal);\ 42 in1.pData = ap; \ 43 \ 44 in2.numRows=internal; \ 45 in2.numCols=columns; \ 46 memcpy((void*)bp,(const void*)inp2,2*sizeof(float16_t)*internal*columns);\ 47 in2.pData = bp; \ 48 \ 49 out.numRows=rows; \ 50 out.numCols=columns; \ 51 out.pData = outp; 52 53 54 test_mat_mult_f16()55 void BinaryTestsF16::test_mat_mult_f16() 56 { 57 LOADDATA2(); 58 arm_status status; 59 60 for(i=0;i < nbMatrixes ; i ++) 61 { 62 rows = *dimsp++; 63 internal = *dimsp++; 64 columns = *dimsp++; 65 66 PREPAREDATA2(); 67 68 status=arm_mat_mult_f16(&this->in1,&this->in2,&this->out); 69 ASSERT_TRUE(status==ARM_MATH_SUCCESS); 70 71 outp += (rows * columns); 72 73 } 74 75 ASSERT_EMPTY_TAIL(output); 76 77 ASSERT_SNR(output,ref,(float16_t)SNR_THRESHOLD); 78 79 ASSERT_CLOSE_ERROR(output,ref,ABS_ERROR,REL_ERROR); 80 81 } 82 test_mat_cmplx_mult_f16()83 void BinaryTestsF16::test_mat_cmplx_mult_f16() 84 { 85 LOADDATA2(); 86 arm_status status; 87 88 for(i=0;i < nbMatrixes ; i ++) 89 { 90 rows = *dimsp++; 91 internal = *dimsp++; 92 columns = *dimsp++; 93 94 PREPAREDATA2(); 95 96 status=arm_mat_cmplx_mult_f16(&this->in1,&this->in2,&this->out); 97 ASSERT_TRUE(status==ARM_MATH_SUCCESS); 98 99 outp += (2*rows * columns); 100 101 } 102 103 ASSERT_EMPTY_TAIL(output); 104 105 ASSERT_SNR(output,ref,(float16_t)SNR_THRESHOLD); 106 107 ASSERT_CLOSE_ERROR(output,ref,ABS_ERROR,REL_ERROR); 108 109 } 110 111 setUp(Testing::testID_t id,std::vector<Testing::param_t> & params,Client::PatternMgr * mgr)112 void BinaryTestsF16::setUp(Testing::testID_t id,std::vector<Testing::param_t>& params,Client::PatternMgr *mgr) 113 { 114 115 116 (void)params; 117 switch(id) 118 { 119 case TEST_MAT_MULT_F16_1: 120 input1.reload(BinaryTestsF16::INPUTS1_F16_ID,mgr); 121 input2.reload(BinaryTestsF16::INPUTS2_F16_ID,mgr); 122 dims.reload(BinaryTestsF16::DIMSBINARY1_S16_ID,mgr); 123 124 ref.reload(BinaryTestsF16::REFMUL1_F16_ID,mgr); 125 126 output.create(ref.nbSamples(),BinaryTestsF16::OUT_F16_ID,mgr); 127 a.create(MAXMATRIXDIM*MAXMATRIXDIM,BinaryTestsF16::TMPA_F16_ID,mgr); 128 b.create(MAXMATRIXDIM*MAXMATRIXDIM,BinaryTestsF16::TMPB_F16_ID,mgr); 129 break; 130 131 case TEST_MAT_CMPLX_MULT_F16_2: 132 input1.reload(BinaryTestsF16::INPUTSC1_F16_ID,mgr); 133 input2.reload(BinaryTestsF16::INPUTSC2_F16_ID,mgr); 134 dims.reload(BinaryTestsF16::DIMSBINARY1_S16_ID,mgr); 135 136 ref.reload(BinaryTestsF16::REFCMPLXMUL1_F16_ID,mgr); 137 138 output.create(ref.nbSamples(),BinaryTestsF16::OUT_F16_ID,mgr); 139 a.create(2*MAXMATRIXDIM*MAXMATRIXDIM,BinaryTestsF16::TMPA_F16_ID,mgr); 140 b.create(2*MAXMATRIXDIM*MAXMATRIXDIM,BinaryTestsF16::TMPB_F16_ID,mgr); 141 break; 142 143 144 145 146 } 147 148 149 150 } 151 tearDown(Testing::testID_t id,Client::PatternMgr * mgr)152 void BinaryTestsF16::tearDown(Testing::testID_t id,Client::PatternMgr *mgr) 153 { 154 (void)id; 155 output.dump(mgr); 156 } 157