shl_c906.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  1. /*
  2. * Copyright (C) 2016-2022 T-Head Semiconductor Co., Ltd. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the License); you may
  7. * not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  14. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. /* CSI-NN2 version 2.0.x */
  19. #ifndef INCLUDE_SHL_C906_H_
  20. #define INCLUDE_SHL_C906_H_
  21. #include "csi_nn.h"
  22. #include "shl_gref.h"
  23. #include "shl_ref.h"
  24. #include "shl_thead_rvv.h"
  25. /************************** f32 func declaration ***************************/
  26. int shl_c906_abs_f32(struct csinn_tensor *input, struct csinn_tensor *output,
  27. struct csinn_siso_params *params);
  28. int shl_c906_add_f32(struct csinn_tensor *input0, struct csinn_tensor *input1,
  29. struct csinn_tensor *output, struct csinn_diso_params *params);
  30. int shl_c906_sub_f32(struct csinn_tensor *input0, struct csinn_tensor *input1,
  31. struct csinn_tensor *output, struct csinn_diso_params *params);
  32. int shl_c906_mul_f32(struct csinn_tensor *input0, struct csinn_tensor *input1,
  33. struct csinn_tensor *output, struct csinn_diso_params *params);
  34. int shl_c906_minimum_f32(struct csinn_tensor *input0, struct csinn_tensor *input1,
  35. struct csinn_tensor *output, struct csinn_diso_params *params);
  36. int shl_c906_broadcast_to_f32(struct csinn_tensor *input, struct csinn_tensor *output,
  37. struct csinn_broadcast_to_params *params);
  38. int shl_c906_clip_f32(struct csinn_tensor *input, struct csinn_tensor *output,
  39. struct csinn_clip_params *params);
  40. int shl_c906_concat_f32(struct csinn_tensor **input, struct csinn_tensor *output,
  41. struct csinn_concat_params *params);
  42. int shl_c906_split_f32(struct csinn_tensor *input, struct csinn_tensor **output,
  43. struct csinn_split_params *params);
  44. int shl_c906_fullyconnected_init(struct csinn_tensor *input, struct csinn_tensor *output,
  45. struct csinn_tensor *weights, struct csinn_tensor *bias,
  46. struct csinn_fc_params *params);
  47. int shl_c906_fullyconnected_f32(struct csinn_tensor *input, struct csinn_tensor *output,
  48. struct csinn_tensor *weights, struct csinn_tensor *bias,
  49. struct csinn_fc_params *params);
  50. int shl_c906_pad_f32(struct csinn_tensor *input, struct csinn_tensor *output,
  51. struct csinn_pad_params *params);
  52. int shl_c906_prelu_f32(struct csinn_tensor *input, struct csinn_tensor *alpha,
  53. struct csinn_tensor *output, struct csinn_prelu_params *params);
  54. int shl_c906_relu_f32(struct csinn_tensor *input, struct csinn_tensor *output,
  55. struct csinn_relu_params *params);
  56. int shl_c906_relu1_f32(struct csinn_tensor *input, struct csinn_tensor *output,
  57. struct csinn_relu_params *params);
  58. int shl_c906_relu6_f32(struct csinn_tensor *input, struct csinn_tensor *output,
  59. struct csinn_relu_params *params);
  60. int shl_c906_leaky_relu_f32(struct csinn_tensor *input, struct csinn_tensor *output,
  61. struct csinn_relu_params *params);
  62. int shl_c906_conv1d_init(struct csinn_tensor *input, struct csinn_tensor *output,
  63. struct csinn_tensor *kernel, struct csinn_tensor *bias,
  64. struct csinn_conv1d_params *params);
  65. int shl_c906_conv2d_init(struct csinn_tensor *input, struct csinn_tensor *output,
  66. struct csinn_tensor *kernel, struct csinn_tensor *bias,
  67. struct csinn_conv2d_params *params);
  68. int shl_c906_conv2d_relu_init(struct csinn_tensor *input, struct csinn_tensor *output,
  69. struct csinn_tensor *kernel, struct csinn_tensor *bias,
  70. struct csinn_conv2d_params *params);
  71. int shl_c906_depthwise_conv2d_init(struct csinn_tensor *input, struct csinn_tensor *output,
  72. struct csinn_tensor *kernel, struct csinn_tensor *bias,
  73. struct csinn_conv2d_params *params);
  74. int shl_c906_depthwise_conv2d_relu_init(struct csinn_tensor *input, struct csinn_tensor *output,
  75. struct csinn_tensor *kernel, struct csinn_tensor *bias,
  76. struct csinn_conv2d_params *params);
  77. int shl_c906_maxpool2d_init(struct csinn_tensor *input, struct csinn_tensor *output,
  78. struct csinn_pool_params *params);
  79. int shl_c906_global_maxpool2d_f32(struct csinn_tensor *input, struct csinn_tensor *output,
  80. struct csinn_pool_params *params);
  81. int shl_c906_avgpool2d_init(struct csinn_tensor *input, struct csinn_tensor *output,
  82. struct csinn_pool_params *params);
  83. int shl_c906_global_avgpool2d_f32(struct csinn_tensor *input, struct csinn_tensor *output,
  84. struct csinn_pool_params *params);
  85. int shl_c906_div_init(struct csinn_tensor *input0, struct csinn_tensor *input1,
  86. struct csinn_tensor *output, struct csinn_diso_params *params);
  87. /* pack */
  88. void shl_c906_reorder_kernel(float *a, float *sa, int m, int k, int ldx);
  89. void shl_c906_reorder_input(float *b, float *sb, int k, int n, int ldx);
  90. void shl_c906_reorder_input_1(float *b, float *sb, int k, int n, int ldx);
  91. /* gemm */
  92. void shl_c906_sgemm_kernel_f32(float *dst, const float *sa, const float *sb, int m, int k, int n,
  93. int ldc, float *bias, bool fuse_relu);
  94. /* kernel transform */
  95. void shl_c906_conv1x1s1_sgemm_transform_kernel(struct csinn_tensor *kernel,
  96. struct csinn_conv2d_params *params);
  97. void shl_c906_conv_im2col_sgemm_transform_kernel(struct csinn_tensor *kernel,
  98. struct csinn_conv2d_params *params);
  99. void shl_c906_conv3x3s1_winograd23_transform_kernel(struct csinn_tensor *o_kernel,
  100. struct csinn_tensor *t_kernel);
  101. void shl_c906_conv3x3s1_winograd43_transform_kernel(struct csinn_tensor *o_kernel,
  102. struct csinn_tensor *t_kernel);
  103. void shl_c906_conv3x3s1_winograd64_transform_kernel(struct csinn_tensor *o_kernel,
  104. struct csinn_tensor *t_kernel);
  105. void shl_c906_conv3x3s1_winograd64_transform_kernel_1(struct csinn_tensor *o_kernel,
  106. struct csinn_tensor *t_kernel);
  107. void shl_c906_conv3x3s1_winograd64_transform_kernel_pack4(struct csinn_tensor *o_kernel,
  108. struct csinn_tensor *t_kernel);
  109. void shl_c906_conv3x3s1_winograd43_transform_kernel_pack4(struct csinn_tensor *o_kernel,
  110. struct csinn_tensor *t_kernel);
  111. /* convolution optimization */
  112. int shl_c906_conv1x1s1_sgemm(struct csinn_tensor *input, struct csinn_tensor *output,
  113. struct csinn_tensor *kernel, struct csinn_tensor *bias,
  114. struct csinn_conv2d_params *params);
  115. int shl_c906_conv1x1s1_sgemm_fuse_relu(struct csinn_tensor *input, struct csinn_tensor *output,
  116. struct csinn_tensor *kernel, struct csinn_tensor *bias,
  117. struct csinn_conv2d_params *params);
  118. int shl_c906_conv_im2col_sgemm(struct csinn_tensor *input, struct csinn_tensor *output,
  119. struct csinn_tensor *kernel, struct csinn_tensor *bias,
  120. struct csinn_conv2d_params *params);
  121. int shl_c906_conv_im2col_sgemm_fuse_relu(struct csinn_tensor *input, struct csinn_tensor *output,
  122. struct csinn_tensor *kernel, struct csinn_tensor *bias,
  123. struct csinn_conv2d_params *params);
  124. int shl_c906_conv3x3s1_winograd23(struct csinn_tensor *input, struct csinn_tensor *output,
  125. struct csinn_tensor *kernel, struct csinn_tensor *bias,
  126. struct csinn_conv2d_params *params);
  127. int shl_c906_conv3x3s1_winograd43(struct csinn_tensor *input, struct csinn_tensor *output,
  128. struct csinn_tensor *kernel, struct csinn_tensor *bias,
  129. struct csinn_conv2d_params *params);
  130. int shl_c906_conv3x3s1_winograd64(struct csinn_tensor *input, struct csinn_tensor *output,
  131. struct csinn_tensor *kernel, struct csinn_tensor *bias,
  132. struct csinn_conv2d_params *params);
  133. int shl_c906_conv3x3s1_winograd64_1(struct csinn_tensor *input, struct csinn_tensor *output,
  134. struct csinn_tensor *kernel, struct csinn_tensor *bias,
  135. struct csinn_conv2d_params *params);
  136. int shl_c906_conv3x3s1_winograd64_pack4(struct csinn_tensor *input, struct csinn_tensor *output,
  137. struct csinn_tensor *kernel, struct csinn_tensor *bias,
  138. struct csinn_conv2d_params *params);
  139. int shl_c906_conv3x3s1_winograd43_pack4(struct csinn_tensor *input, struct csinn_tensor *output,
  140. struct csinn_tensor *kernel, struct csinn_tensor *bias,
  141. struct csinn_conv2d_params *params);
  142. void shl_c906_conv3x3s1(struct csinn_tensor *input, struct csinn_tensor *output,
  143. struct csinn_tensor *kernel, struct csinn_tensor *bias,
  144. struct csinn_conv2d_params *params);
  145. void shl_c906_conv3x3s2(struct csinn_tensor *input, struct csinn_tensor *output,
  146. struct csinn_tensor *kernel, struct csinn_tensor *bias,
  147. struct csinn_conv2d_params *params);
  148. /* depthwise convolution optimization */
  149. int shl_c906_dwconv3x3s1(struct csinn_tensor *input, struct csinn_tensor *output,
  150. struct csinn_tensor *kernel, struct csinn_tensor *bias,
  151. struct csinn_conv2d_params *params);
  152. int shl_c906_dwconv3x3s2(struct csinn_tensor *input, struct csinn_tensor *output,
  153. struct csinn_tensor *kernel, struct csinn_tensor *bias,
  154. struct csinn_conv2d_params *params);
  155. int shl_c906_dwconv5x5s1(struct csinn_tensor *input, struct csinn_tensor *output,
  156. struct csinn_tensor *kernel, struct csinn_tensor *bias,
  157. struct csinn_conv2d_params *params);
  158. int shl_c906_dwconv5x5s2(struct csinn_tensor *input, struct csinn_tensor *output,
  159. struct csinn_tensor *kernel, struct csinn_tensor *bias,
  160. struct csinn_conv2d_params *params);
  161. int shl_c906_dwconv3x3s1_pack4(struct csinn_tensor *input, struct csinn_tensor *output,
  162. struct csinn_tensor *kernel, struct csinn_tensor *bias,
  163. struct csinn_conv2d_params *params);
  164. int shl_c906_dwconv3x3s2_pack4(struct csinn_tensor *input, struct csinn_tensor *output,
  165. struct csinn_tensor *kernel, struct csinn_tensor *bias,
  166. struct csinn_conv2d_params *params);
  167. /* depthwise convolution fuse relu */
  168. int shl_c906_dwconv3x3s1_fuse_relu(struct csinn_tensor *input, struct csinn_tensor *output,
  169. struct csinn_tensor *kernel, struct csinn_tensor *bias,
  170. struct csinn_conv2d_params *params);
  171. int shl_c906_dwconv3x3s2_fuse_relu(struct csinn_tensor *input, struct csinn_tensor *output,
  172. struct csinn_tensor *kernel, struct csinn_tensor *bias,
  173. struct csinn_conv2d_params *params);
  174. int shl_c906_dwconv5x5s1_fuse_relu(struct csinn_tensor *input, struct csinn_tensor *output,
  175. struct csinn_tensor *kernel, struct csinn_tensor *bias,
  176. struct csinn_conv2d_params *params);
  177. int shl_c906_dwconv5x5s2_fuse_relu(struct csinn_tensor *input, struct csinn_tensor *output,
  178. struct csinn_tensor *kernel, struct csinn_tensor *bias,
  179. struct csinn_conv2d_params *params);
  180. int shl_c906_dwconv3x3s1_pack4_fuse_relu(struct csinn_tensor *input, struct csinn_tensor *output,
  181. struct csinn_tensor *kernel, struct csinn_tensor *bias,
  182. struct csinn_conv2d_params *params);
  183. int shl_c906_dwconv3x3s2_pack4_fuse_relu(struct csinn_tensor *input, struct csinn_tensor *output,
  184. struct csinn_tensor *kernel, struct csinn_tensor *bias,
  185. struct csinn_conv2d_params *params);
  186. int shl_c906_dwconv2d_s1_pad0_fp16(struct csinn_tensor *input, struct csinn_tensor *output,
  187. struct csinn_tensor *kernel, struct csinn_tensor *bias,
  188. struct csinn_conv2d_params *params);
  189. /************************** fp16 func declaration ***************************/
  190. int shl_c906_add_fp16(struct csinn_tensor *input0, struct csinn_tensor *input1,
  191. struct csinn_tensor *output, struct csinn_diso_params *params);
  192. int shl_c906_sub_fp16(struct csinn_tensor *input0, struct csinn_tensor *input1,
  193. struct csinn_tensor *output, struct csinn_diso_params *params);
  194. int shl_c906_mul_fp16(struct csinn_tensor *input0, struct csinn_tensor *input1,
  195. struct csinn_tensor *output, struct csinn_diso_params *params);
  196. int shl_c906_minimum_fp16(struct csinn_tensor *input0, struct csinn_tensor *input1,
  197. struct csinn_tensor *output, struct csinn_diso_params *params);
  198. int shl_c906_global_avgpool2d_fp16(struct csinn_tensor *input, struct csinn_tensor *output,
  199. struct csinn_pool_params *params);
  200. int shl_c906_global_maxpool2d_fp16(struct csinn_tensor *input, struct csinn_tensor *output,
  201. struct csinn_pool_params *params);
  202. int shl_c906_pad_fp16(struct csinn_tensor *input, struct csinn_tensor *output,
  203. struct csinn_pad_params *params);
  204. int shl_c906_relu_fp16(struct csinn_tensor *input, struct csinn_tensor *output,
  205. struct csinn_relu_params *params);
  206. int shl_c906_relu1_fp16(struct csinn_tensor *input, struct csinn_tensor *output,
  207. struct csinn_relu_params *params);
  208. int shl_c906_relu6_fp16(struct csinn_tensor *input, struct csinn_tensor *output,
  209. struct csinn_relu_params *params);
  210. int shl_c906_prelu_fp16(struct csinn_tensor *input, struct csinn_tensor *alpha,
  211. struct csinn_tensor *output, struct csinn_prelu_params *params);
  212. int shl_c906_leaky_relu_fp16(struct csinn_tensor *input, struct csinn_tensor *output,
  213. struct csinn_relu_params *params);
  214. int shl_c906_abs_fp16(struct csinn_tensor *input, struct csinn_tensor *output,
  215. struct csinn_siso_params *params);
  216. int shl_c906_clip_fp16(struct csinn_tensor *input, struct csinn_tensor *output,
  217. struct csinn_clip_params *params);
  218. int shl_c906_concat_fp16(struct csinn_tensor **input, struct csinn_tensor *output,
  219. struct csinn_concat_params *params);
  220. int shl_c906_split_fp16(struct csinn_tensor *input, struct csinn_tensor **output,
  221. struct csinn_split_params *params);
  222. int shl_c906_fullyconnected_fp16(struct csinn_tensor *input, struct csinn_tensor *output,
  223. struct csinn_tensor *weights, struct csinn_tensor *bias,
  224. struct csinn_fc_params *params);
  225. int shl_c906_fullyconnected_pack8_fp16(struct csinn_tensor *input, struct csinn_tensor *output,
  226. struct csinn_tensor *weights, struct csinn_tensor *bias,
  227. struct csinn_fc_params *params);
  228. int shl_c906_fullyconnected_pack8_fp16_1(struct csinn_tensor *input, struct csinn_tensor *output,
  229. struct csinn_tensor *weights, struct csinn_tensor *bias,
  230. struct csinn_fc_params *params);
  231. int shl_c906_fullyconnected_pack16_fp16(struct csinn_tensor *input, struct csinn_tensor *output,
  232. struct csinn_tensor *weights, struct csinn_tensor *bias,
  233. struct csinn_fc_params *params);
  234. int shl_c906_fullyconnected_pack16_output16_fp16(struct csinn_tensor *input,
  235. struct csinn_tensor *output,
  236. struct csinn_tensor *weights,
  237. struct csinn_tensor *bias,
  238. struct csinn_fc_params *params);
  239. void shl_c906_reorder_weight_n8_fp16(__fp16 *src, __fp16 *dst, int m, int k, int ldx);
  240. void shl_c906_reorder_weight_n16_fp16(__fp16 *src, __fp16 *dst, int m, int k, int ldx);
  241. /* pack fp16 */
  242. void shl_c906_reorder_kernel_fp16(__fp16 *a, __fp16 *sa, int m, int k, int ldx);
  243. void shl_c906_reorder_input_fp16(__fp16 *b, __fp16 *sb, int k, int n, int ldx);
  244. void shl_c906_reorder_input_fp16_1(__fp16 *b, __fp16 *sb, int k, int n, int ldx);
  245. void shl_c906_reorder_matrix_z8_fp16(__fp16 *src, __fp16 *dst, int k, int n, int ldx);
  246. void shl_c906_reorder_matrix_z16_fp16(__fp16 *src, __fp16 *dst, int k, int n, int ldx);
  247. /* gemm fp16 */
  248. void shl_c906_sgemm_kernel_fp16(__fp16 *dst, const __fp16 *sa, const __fp16 *sb, int m, int k,
  249. int n, int ldc, __fp16 *bias);
  250. void shl_c906_sgemm_kernel_fp16_1(__fp16 *dst, const __fp16 *sa, const __fp16 *sb, int m, int k,
  251. int n, int ldc, __fp16 *bias);
  252. /* gemv fp16 */
  253. void shl_c906_gemv_pack8_fp16(__fp16 *dst, const __fp16 *sa, const __fp16 *sb, int k, int n,
  254. int ldc, __fp16 *bias);
  255. void shl_c906_gemv_pack16_fp16(__fp16 *dst, const __fp16 *sa, const __fp16 *sb, int k, int n,
  256. int ldc, __fp16 *bias);
  257. void shl_c906_gemv_trans_pack8_fp16(__fp16 *dst, const __fp16 *sa, const __fp16 *sb, int k, int n,
  258. int ldc, __fp16 *bias);
  259. void shl_c906_gemv_trans_pack16_fp16(__fp16 *dst, const __fp16 *sa, const __fp16 *sb, int k, int n,
  260. int ldc, __fp16 *bias);
  261. /* kernel transform fp16 */
  262. void shl_c906_conv1x1s1_sgemm_transform_kernel_fp16(struct csinn_tensor *kernel,
  263. struct csinn_conv2d_params *params);
  264. void shl_c906_conv_im2col_sgemm_transform_kernel_fp16(struct csinn_tensor *kernel,
  265. struct csinn_conv2d_params *params);
  266. void shl_c906_conv3x3s1_winograd43_transform_kernel_pack8_fp16(struct csinn_tensor *o_kernel,
  267. struct csinn_tensor *t_kernel);
  268. void shl_c906_conv3x3s1_winograd64_transform_kernel_pack8_fp16(struct csinn_tensor *o_kernel,
  269. struct csinn_tensor *t_kernel);
  270. /* convolution optimization fp16 */
  271. int shl_c906_conv1x1s1_sgemm_fp16(struct csinn_tensor *input, struct csinn_tensor *output,
  272. struct csinn_tensor *kernel, struct csinn_tensor *bias,
  273. struct csinn_conv2d_params *params);
  274. int shl_c906_conv1x1s1_batch_gemv_fp16(struct csinn_tensor *input, struct csinn_tensor *output,
  275. struct csinn_tensor *kernel, struct csinn_tensor *bias,
  276. struct csinn_conv2d_params *params);
  277. int shl_c906_conv_im2col_sgemm_fp16(struct csinn_tensor *input, struct csinn_tensor *output,
  278. struct csinn_tensor *kernel, struct csinn_tensor *bias,
  279. struct csinn_conv2d_params *params);
  280. int shl_c906_conv3x3s1_winograd43_pack8_fp16(struct csinn_tensor *input,
  281. struct csinn_tensor *output,
  282. struct csinn_tensor *kernel, struct csinn_tensor *bias,
  283. struct csinn_conv2d_params *params);
  284. int shl_c906_conv3x3s1_winograd64_pack8_fp16(struct csinn_tensor *input,
  285. struct csinn_tensor *output,
  286. struct csinn_tensor *kernel, struct csinn_tensor *bias,
  287. struct csinn_conv2d_params *params);
  288. void shl_c906_conv3x3s1_fp16(struct csinn_tensor *input, struct csinn_tensor *output,
  289. struct csinn_tensor *kernel, struct csinn_tensor *bias,
  290. struct csinn_conv2d_params *params);
  291. void shl_c906_conv3x3s2_fp16(struct csinn_tensor *input, struct csinn_tensor *output,
  292. struct csinn_tensor *kernel, struct csinn_tensor *bias,
  293. struct csinn_conv2d_params *params);
  294. /* depthwise convolution optimization for fp16*/
  295. int shl_c906_dwconv3x3s1_fp16(struct csinn_tensor *input, struct csinn_tensor *output,
  296. struct csinn_tensor *kernel, struct csinn_tensor *bias,
  297. struct csinn_conv2d_params *params);
  298. int shl_c906_dwconv3x3s2_fp16(struct csinn_tensor *input, struct csinn_tensor *output,
  299. struct csinn_tensor *kernel, struct csinn_tensor *bias,
  300. struct csinn_conv2d_params *params);
  301. int shl_c906_dwconv3x3s1_pack8_fp16(struct csinn_tensor *input, struct csinn_tensor *output,
  302. struct csinn_tensor *kernel, struct csinn_tensor *bias,
  303. struct csinn_conv2d_params *params);
  304. int shl_c906_dwconv3x3s2_pack8_fp16(struct csinn_tensor *input, struct csinn_tensor *output,
  305. struct csinn_tensor *kernel, struct csinn_tensor *bias,
  306. struct csinn_conv2d_params *params);
  307. /* utils */
  308. void shl_c906_memcpy(void *dst, const void *src, size_t n);
  309. void shl_c906_pad_input(const float *input, float *input_padded, int inc, int inh, int inw,
  310. int padded_h, int padded_w, int pad_top, int pad_left);
  311. void shl_c906_crop_output(float *output_trans, float *output, int out_c, int out_h, int out_w,
  312. int wino_h, int wino_w);
  313. void shl_c906_pad_input_fp16(const __fp16 *input, __fp16 *input_padded, int inc, int inh, int inw,
  314. int padded_h, int padded_w, int pad_top, int pad_left);
  315. void shl_c906_crop_output_fp16(__fp16 *output_trans, __fp16 *output, int out_c, int out_h,
  316. int out_w, int wino_h, int wino_w);
  317. /*asr related fuctions*/
  318. int shl_c906_cache_matmul_init(struct csinn_tensor *input, struct csinn_tensor *output,
  319. struct csinn_tensor *weight, struct csinn_tensor *bias,
  320. struct csinn_cache_matmul_params *params);
  321. int shl_c906_cache_matmul_fp16(struct csinn_tensor *input, struct csinn_tensor *output,
  322. struct csinn_tensor *weight, struct csinn_tensor *bias,
  323. struct csinn_cache_matmul_params *params);
  324. int shl_c906_matmul_fp16(struct csinn_tensor *mat0, struct csinn_tensor *mat1,
  325. struct csinn_tensor *output, struct csinn_matmul_params *params);
  326. int shl_c906_layer_norm_fp16(struct csinn_tensor *input, struct csinn_tensor *output,
  327. struct csinn_tensor *gamma, struct csinn_tensor *beta,
  328. struct csinn_layer_norm_params *params);
  329. int shl_c906_reshape_fp16(struct csinn_tensor *input, struct csinn_tensor *output,
  330. struct csinn_reshape_params *params);
  331. int shl_c906_transpose_fp16(struct csinn_tensor *input, struct csinn_tensor *output,
  332. struct csinn_transpose_params *params);
  333. int shl_c906_gather_fp16(struct csinn_tensor *input, struct csinn_tensor *indices,
  334. struct csinn_tensor *output, struct csinn_gather_params *params);
  335. int shl_c906_cache_conv1d_init(struct csinn_tensor *input, struct csinn_tensor *output,
  336. struct csinn_tensor *weight, struct csinn_tensor *bias,
  337. struct csinn_cache_conv1d_params *params);
  338. int shl_c906_cache_conv1d_fp16(struct csinn_tensor *input, struct csinn_tensor *output,
  339. struct csinn_tensor *weight, struct csinn_tensor *bias,
  340. struct csinn_cache_conv1d_params *params);
  341. int shl_c906_lrn_fp16(struct csinn_tensor *input, struct csinn_tensor *output,
  342. struct csinn_lrn_params *params);
  343. void asr_buffer_init_c906(struct csinn_asr_buffer_t *buffer, size_t buffer_size, size_t data_lenth);
  344. void *asr_buffer_insert_c906_front(struct csinn_asr_buffer_t *buffer, void *input, size_t len);
  345. void *asr_buffer_insert_c906_back(struct csinn_asr_buffer_t *buffer, void *input, size_t len);
  346. void *asr_buffer_get_buffer_c906(struct csinn_asr_buffer_t *buffer);
  347. void asr_buffer_reset_c906(struct csinn_asr_buffer_t *buffer);
  348. void shl_c906_reset_fcsr();
  349. int shl_c906_get_fcsr();
  350. /* hardware performance */
  351. struct shl_c906_hpm {
  352. size_t inst;
  353. size_t cycle;
  354. size_t l1_icache_access;
  355. size_t l1_icache_miss;
  356. size_t store_inst;
  357. size_t l1_dcache_raccess;
  358. size_t l1_dcache_rmiss;
  359. size_t l1_dcache_waccess;
  360. size_t l1_dcache_wmiss;
  361. };
  362. uint64_t shl_c906_get_inst();
  363. uint64_t shl_c906_get_cycle();
  364. uint64_t shl_c906_get_l1_icache_access();
  365. uint64_t shl_c906_get_l1_icache_miss();
  366. uint64_t shl_c906_get_cb_miss();
  367. uint64_t shl_c906_get_cb_inst();
  368. uint64_t shl_c906_get_store_inst();
  369. uint64_t shl_c906_get_l1_dcache_raccess();
  370. uint64_t shl_c906_get_l1_dcache_rmiss();
  371. uint64_t shl_c906_get_l1_dcache_waccess();
  372. uint64_t shl_c906_get_l1_dcache_wmiss();
  373. struct shl_c906_hpm shl_c906_get_hw_perf();
  374. int shl_c906_sum_stride_fp16(struct csinn_tensor *input, struct csinn_tensor *output,
  375. struct csinn_reduce_params *params);
  376. void shl_c906_u8_to_f32(const uint8_t *input, float *output, int32_t offset, float *scale,
  377. uint32_t length);
  378. struct csinn_callback *shl_cb_map_c906(int op, int dtype);
  379. int shl_c906_reg_op(enum csinn_dtype_enum dtype, enum csinn_op_enum op_name, void *init,
  380. void *exec);
  381. int shl_c906_reg_op_est(enum csinn_dtype_enum dtype, enum csinn_op_enum op_name, void *est);
  382. #endif // INCLUDE_SHL_C906_H_