UnaryF16.cpp 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. #include "UnaryF16.h"
  2. #include "Error.h"
  3. /* Upper bound of maximum matrix dimension used by Python */
  4. #define MAXMATRIXDIM 40
  5. /*
  6. Offset in input test pattern for matrix of dimension d * d.
  7. Must be coherent with Python script Matrix.py
  8. */
  9. static int cholesky_offset(int d)
  10. {
  11. int offset=14;
  12. switch (d)
  13. {
  14. case 4:
  15. offset = 14;
  16. break;
  17. case 8:
  18. offset = 79;
  19. break;
  20. case 9:
  21. offset = 143;
  22. break;
  23. case 15:
  24. offset = 224;
  25. break;
  26. case 16:
  27. offset = 449;
  28. break;
  29. default:
  30. offset = 14;
  31. break;
  32. }
  33. return(offset);
  34. }
  35. void UnaryF16::test_mat_scale_f16()
  36. {
  37. arm_mat_scale_f16(&this->in1,0.5,&this->out);
  38. }
  39. void UnaryF16::test_mat_inverse_f16()
  40. {
  41. arm_mat_inverse_f16(&this->in1,&this->out);
  42. }
  43. void UnaryF16::test_mat_trans_f16()
  44. {
  45. arm_mat_trans_f16(&this->in1,&this->out);
  46. }
  47. void UnaryF16::test_mat_cmplx_trans_f16()
  48. {
  49. arm_mat_cmplx_trans_f16(&this->in1,&this->out);
  50. }
  51. void UnaryF16::test_mat_add_f16()
  52. {
  53. arm_mat_add_f16(&this->in1,&this->in1,&this->out);
  54. }
  55. void UnaryF16::test_mat_sub_f16()
  56. {
  57. arm_mat_sub_f16(&this->in1,&this->in1,&this->out);
  58. }
  59. void UnaryF16::test_mat_vec_mult_f16()
  60. {
  61. arm_mat_vec_mult_f16(&this->in1, vecp, outp);
  62. }
  63. void UnaryF16::test_mat_cholesky_dpo_f16()
  64. {
  65. arm_mat_cholesky_f16(&this->in1,&this->out);
  66. }
  67. void UnaryF16::test_solve_upper_triangular_f16()
  68. {
  69. arm_mat_solve_upper_triangular_f16(&this->in1,&this->in2,&this->out);
  70. }
  71. void UnaryF16::test_solve_lower_triangular_f16()
  72. {
  73. arm_mat_solve_lower_triangular_f16(&this->in1,&this->in2,&this->out);
  74. }
  75. void UnaryF16::setUp(Testing::testID_t id,std::vector<Testing::param_t>& params,Client::PatternMgr *mgr)
  76. {
  77. std::vector<Testing::param_t>::iterator it = params.begin();
  78. this->nbr = *it++;
  79. this->nbc = *it;
  80. switch(id)
  81. {
  82. case TEST_MAT_VEC_MULT_F16_6:
  83. input1.reload(UnaryF16::INPUTA_F16_ID,mgr,this->nbr*this->nbc);
  84. vec.reload(UnaryF16::INPUTVEC1_F16_ID,mgr,this->nbc);
  85. output.create(this->nbr,UnaryF16::OUT_F16_ID,mgr);
  86. vecp=vec.ptr();
  87. outp=output.ptr();
  88. this->in1.numRows = this->nbr;
  89. this->in1.numCols = this->nbc;
  90. this->in1.pData = input1.ptr();
  91. break;
  92. case TEST_MAT_TRANS_F16_3:
  93. input1.reload(UnaryF16::INPUTA_F16_ID,mgr,this->nbr*this->nbc);
  94. output.create(this->nbr*this->nbc,UnaryF16::OUT_F16_ID,mgr);
  95. this->out.numRows = this->nbc;
  96. this->out.numCols = this->nbr;
  97. this->out.pData = output.ptr();
  98. this->in1.numRows = this->nbr;
  99. this->in1.numCols = this->nbc;
  100. this->in1.pData = input1.ptr();
  101. break;
  102. case TEST_MAT_CMPLX_TRANS_F16_7:
  103. input1.reload(UnaryF16::INPUTAC_F16_ID,mgr,2*this->nbr*this->nbc);
  104. output.create(2*this->nbr*this->nbc,UnaryF16::OUT_F16_ID,mgr);
  105. this->out.numRows = this->nbc;
  106. this->out.numCols = this->nbr;
  107. this->out.pData = output.ptr();
  108. this->in1.numRows = this->nbr;
  109. this->in1.numCols = this->nbc;
  110. this->in1.pData = input1.ptr();
  111. break;
  112. case TEST_MAT_CHOLESKY_DPO_F16_8:
  113. {
  114. int offset=14;
  115. float16_t *p;
  116. float16_t *aPtr;
  117. input1.reload(UnaryF16::INPUTSCHOLESKY1_DPO_F16_ID,mgr);
  118. output.create(this->nbc * this->nbr,UnaryF16::OUT_F16_ID,mgr);
  119. a.create(this->nbr*this->nbc,UnaryF16::TMPA_F16_ID,mgr);
  120. /* Offsets must be coherent with the sizes used in python script
  121. Matrix.py for pattern generation */
  122. offset=cholesky_offset(this->nbr);
  123. p = input1.ptr();
  124. aPtr = a.ptr();
  125. memcpy(aPtr,p + offset,sizeof(float16_t)*this->nbr*this->nbr);
  126. this->out.numRows = this->nbr;
  127. this->out.numCols = this->nbc;
  128. this->out.pData = output.ptr();
  129. this->in1.numRows = this->nbr;
  130. this->in1.numCols = this->nbc;
  131. this->in1.pData = aPtr;
  132. }
  133. break;
  134. case TEST_SOLVE_UPPER_TRIANGULAR_F16_9:
  135. {
  136. int offset=14;
  137. float16_t *p;
  138. float16_t *aPtr;
  139. float16_t *bPtr;
  140. input1.reload(UnaryF16::INPUT_UT_DPO_F16_ID,mgr);
  141. input2.reload(UnaryF16::INPUT_RNDA_DPO_F16_ID,mgr);
  142. output.create(this->nbc * this->nbr,UnaryF16::OUT_F16_ID,mgr);
  143. a.create(this->nbr*this->nbc,UnaryF16::TMPA_F16_ID,mgr);
  144. b.create(this->nbr*this->nbc,UnaryF16::TMPB_F16_ID,mgr);
  145. /* Offsets must be coherent with the sizes used in python script
  146. Matrix.py for pattern generation */
  147. offset=cholesky_offset(this->nbr);
  148. p = input1.ptr();
  149. aPtr = a.ptr();
  150. memcpy(aPtr,&p[offset],sizeof(float16_t)*this->nbr*this->nbr);
  151. p = input2.ptr();
  152. bPtr = b.ptr();
  153. memcpy(bPtr,&p[offset],sizeof(float16_t)*this->nbr*this->nbr);
  154. this->out.numRows = this->nbr;
  155. this->out.numCols = this->nbc;
  156. this->out.pData = output.ptr();
  157. this->in1.numRows = this->nbr;
  158. this->in1.numCols = this->nbc;
  159. this->in1.pData = aPtr;
  160. this->in2.numRows = this->nbr;
  161. this->in2.numCols = this->nbc;
  162. this->in2.pData = bPtr;
  163. }
  164. break;
  165. case TEST_SOLVE_LOWER_TRIANGULAR_F16_10:
  166. {
  167. int offset=14;
  168. float16_t *p;
  169. float16_t *aPtr;
  170. float16_t *bPtr;
  171. input1.reload(UnaryF16::INPUT_LT_DPO_F16_ID,mgr);
  172. input2.reload(UnaryF16::INPUT_RNDA_DPO_F16_ID,mgr);
  173. output.create(this->nbc * this->nbr,UnaryF16::OUT_F16_ID,mgr);
  174. a.create(this->nbr*this->nbc,UnaryF16::TMPA_F16_ID,mgr);
  175. b.create(this->nbr*this->nbc,UnaryF16::TMPB_F16_ID,mgr);
  176. /* Offsets must be coherent with the sizes used in python script
  177. Matrix.py for pattern generation */
  178. offset=cholesky_offset(this->nbr);
  179. p = input1.ptr();
  180. aPtr = a.ptr();
  181. memcpy(aPtr,&p[offset],sizeof(float16_t)*this->nbr*this->nbr);
  182. p = input2.ptr();
  183. bPtr = b.ptr();
  184. memcpy(bPtr,&p[offset],sizeof(float16_t)*this->nbr*this->nbr);
  185. this->out.numRows = this->nbr;
  186. this->out.numCols = this->nbc;
  187. this->out.pData = output.ptr();
  188. this->in1.numRows = this->nbr;
  189. this->in1.numCols = this->nbc;
  190. this->in1.pData = aPtr;
  191. this->in2.numRows = this->nbr;
  192. this->in2.numCols = this->nbc;
  193. this->in2.pData = bPtr;
  194. }
  195. break;
  196. default:
  197. input1.reload(UnaryF16::INPUTA_F16_ID,mgr,this->nbr*this->nbc);
  198. output.create(this->nbr*this->nbc,UnaryF16::OUT_F16_ID,mgr);
  199. this->out.numRows = this->nbr;
  200. this->out.numCols = this->nbc;
  201. this->out.pData = output.ptr();
  202. this->in1.numRows = this->nbr;
  203. this->in1.numCols = this->nbc;
  204. this->in1.pData = input1.ptr();
  205. break;
  206. }
  207. }
  208. void UnaryF16::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
  209. {
  210. (void)id;
  211. (void)mgr;
  212. }