csinn_data_structure.h 22 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013
  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_CSI_INTERNAL_H_
  20. #define INCLUDE_CSI_INTERNAL_H_
  21. #include <stdbool.h>
  22. #include <stddef.h>
  23. #include <stdint.h>
  24. /* data type */
  25. enum csinn_dtype_enum {
  26. CSINN_DTYPE_BOOL = 0,
  27. CSINN_DTYPE_INT4,
  28. CSINN_DTYPE_UINT8,
  29. CSINN_DTYPE_INT8,
  30. CSINN_DTYPE_UINT16,
  31. CSINN_DTYPE_INT16,
  32. CSINN_DTYPE_UINT32,
  33. CSINN_DTYPE_INT32,
  34. CSINN_DTYPE_FLOAT16,
  35. CSINN_DTYPE_BFLOAT16,
  36. CSINN_DTYPE_FLOAT32,
  37. CSINN_DTYPE_FLOAT64,
  38. CSINN_DTYPE_SIZE,
  39. };
  40. /* data memory type */
  41. enum csinn_mem_type_enum {
  42. CSINN_MEM_TYPE_CPU_NOT_ALIGNED = 0,
  43. CSINN_MEM_TYPE_CPU_ALIGNED,
  44. CSINN_MEM_TYPE_DMABUF,
  45. CSINN_MEM_TYPE_ASP42, /* structed sparsity 4:2 */
  46. CSINN_MEM_TYPE_ASP41, /* structed sparsity 4:1 */
  47. };
  48. /* quant type */
  49. enum csinn_quant_enum {
  50. CSINN_QUANT_UNSET = 0,
  51. CSINN_QUANT_INT4_SYM,
  52. CSINN_QUANT_UINT8_ASYM,
  53. CSINN_QUANT_UINT8_SYM,
  54. CSINN_QUANT_INT8_ASYM,
  55. CSINN_QUANT_INT8_SYM,
  56. CSINN_QUANT_INT16_SYM,
  57. CSINN_QUANT_FLOAT16,
  58. CSINN_QUANT_BFLOAT16,
  59. CSINN_QUANT_FLOAT32,
  60. CSINN_QUANT_SIZE,
  61. };
  62. /* API type */
  63. enum csinn_api_enum {
  64. CSINN_REF = 0,
  65. CSINN_GREF,
  66. CSINN_C860,
  67. CSINN_C906,
  68. CSINN_C910,
  69. CSINN_ANOLE,
  70. CSINN_CH8601,
  71. CSINN_LIGHT,
  72. CSINN_DP1K,
  73. CSINN_I805,
  74. CSINN_E804,
  75. CSINN_REF_I805,
  76. CSINN_C908,
  77. CSINN_TVMGEN,
  78. CSINN_ASP,
  79. CSINN_RVV,
  80. CSINN_API_SIZE,
  81. };
  82. /* run mode */
  83. enum csinn_rmode_enum {
  84. CSINN_RM_LAYER = 0,
  85. CSINN_RM_CPU_GRAPH,
  86. CSINN_RM_NPU_GRAPH,
  87. CSINN_RUN_MODE_SIZE,
  88. };
  89. /* model save */
  90. enum csinn_mode_save_enum {
  91. CSINN_SAVE_AND_RUN = 0,
  92. CSINN_SAVE_ONLY,
  93. CSINN_RUN_ONLY,
  94. };
  95. /* op and utils */
  96. enum csinn_op_enum {
  97. CSINN_OP_ABS = 0,
  98. CSINN_OP_ACOS,
  99. CSINN_OP_ACOSH,
  100. CSINN_OP_ADD,
  101. CSINN_OP_ALL,
  102. CSINN_OP_AND,
  103. CSINN_OP_ANY,
  104. CSINN_OP_ARANGE,
  105. CSINN_OP_ARGMAX,
  106. CSINN_OP_ARGMIN,
  107. CSINN_OP_ASIN,
  108. CSINN_OP_ASINH,
  109. CSINN_OP_ATAN,
  110. CSINN_OP_ATANH,
  111. CSINN_OP_AVGPOOL2D,
  112. CSINN_OP_AVGPOOL3D,
  113. CSINN_OP_BN,
  114. CSINN_OP_BATCH_TO_SPACE,
  115. CSINN_OP_BATCH_TO_SPACE_ND,
  116. CSINN_OP_BROADCOST,
  117. CSINN_OP_CACHE_MATMUL,
  118. CSINN_OP_CACHE_CONV1D,
  119. CSINN_OP_CEIL,
  120. CSINN_OP_CLIP,
  121. CSINN_OP_COL2IM,
  122. CSINN_OP_CONCAT,
  123. CSINN_OP_CONV1D,
  124. CSINN_OP_CONV2D,
  125. CSINN_OP_CONV2D_RELU,
  126. CSINN_OP_CONV2D_RELU6,
  127. CSINN_OP_CONV2D_CHANNEL,
  128. CSINN_OP_CONV2D_CHANNEL_RELU,
  129. CSINN_OP_CONV2D_CHANNEL_RELU6,
  130. CSINN_OP_DEPTHWISE_CONV2D,
  131. CSINN_OP_DEPTHWISE_CONV2D_RELU,
  132. CSINN_OP_DEPTHWISE_CONV2D_RELU6,
  133. CSINN_OP_DEPTHWISE_CONV2D_CHANNEL,
  134. CSINN_OP_DEPTHWISE_CONV2D_CHANNEL_RELU,
  135. CSINN_OP_DEPTHWISE_CONV2D_CHANNEL_RELU6,
  136. CSINN_OP_GROUP_CONV2D,
  137. CSINN_OP_GROUP_CONV2D_RELU,
  138. CSINN_OP_GROUP_CONV2D_RELU6,
  139. CSINN_OP_GROUP_CONV2D_CHANNEL,
  140. CSINN_OP_GROUP_CONV2D_CHANNEL_RELU,
  141. CSINN_OP_CONV3D,
  142. CSINN_OP_DATA_CONVERT,
  143. CSINN_OP_COS,
  144. CSINN_OP_COSH,
  145. CSINN_OP_CROP,
  146. CSINN_OP_CUMPROD,
  147. CSINN_OP_CUMSUM,
  148. CSINN_OP_DECONV2D,
  149. CSINN_OP_DEPTHWISE_DECONV2D,
  150. CSINN_OP_DECONV3D,
  151. CSINN_OP_DEPTH_TO_SPACE,
  152. CSINN_OP_DIV,
  153. CSINN_OP_ELU,
  154. CSINN_OP_EQUANL,
  155. CSINN_OP_ERF,
  156. CSINN_OP_EXP,
  157. CSINN_OP_EXPAND_DIMS,
  158. CSINN_OP_EXPM1,
  159. CSINN_OP_FLATTEN,
  160. CSINN_OP_FLOOR_DIVIDE,
  161. CSINN_OP_FLOOR_MOD,
  162. CSINN_OP_FLOOR,
  163. CSINN_OP_FSMN,
  164. CSINN_OP_FULLYCONNECTED,
  165. CSINN_OP_GATHER_ND,
  166. CSINN_OP_GATHER,
  167. CSINN_OP_GLOBAL_AVGPOOL2D,
  168. CSINN_OP_GLOBAL_MAXPOOL2D,
  169. CSINN_OP_GREATHER_EQUAL,
  170. CSINN_OP_GREATHER,
  171. CSINN_OP_HARD_SIGMOID,
  172. CSINN_OP_IM2COL,
  173. CSINN_OP_ISNAN,
  174. CSINN_OP_L2N,
  175. CSINN_OP_L2POOL2D,
  176. CSINN_OP_LAYER_NORM,
  177. CSINN_OP_LEAKY_RELU,
  178. CSINN_OP_LESS_EQUAL,
  179. CSINN_OP_LESS,
  180. CSINN_OP_LOG_SOFTMAX,
  181. CSINN_OP_LOG,
  182. CSINN_OP_LOG1P,
  183. CSINN_OP_LOGICAL_AND,
  184. CSINN_OP_LOGICAL_NOT,
  185. CSINN_OP_LOGICAL_OR,
  186. CSINN_OP_LOGICAL_XOR,
  187. CSINN_OP_LRN,
  188. CSINN_OP_MATMUL,
  189. CSINN_OP_MAX,
  190. CSINN_OP_MAXIMUM,
  191. CSINN_OP_MAXPOOL2D,
  192. CSINN_OP_MAXPOOL2D_LOCAT,
  193. CSINN_OP_MAXPOOL3D,
  194. CSINN_OP_MEAN,
  195. CSINN_OP_MEAN_STRIDE,
  196. CSINN_OP_MIN,
  197. CSINN_OP_MIN_STRIDE,
  198. CSINN_OP_MINIMUM,
  199. CSINN_OP_MOD,
  200. CSINN_OP_MUL,
  201. CSINN_OP_NDARRAY_SIZE,
  202. CSINN_OP_NEGATIIVE,
  203. CSINN_OP_NON_MAX_SUPPRESSION,
  204. CSINN_OP_NOT_EQUAL,
  205. CSINN_OP_NOT,
  206. CSINN_OP_ONE_HOT,
  207. CSINN_OP_OR,
  208. CSINN_OP_PAD,
  209. CSINN_OP_POWER,
  210. CSINN_OP_PRELU,
  211. CSINN_OP_PROD,
  212. CSINN_OP_PROPOSAL,
  213. CSINN_OP_PSROIPOOLING,
  214. CSINN_OP_REDUCE_LOGSUMEXP,
  215. CSINN_OP_REDUCE_MAX,
  216. CSINN_OP_REDUCE_MEAN,
  217. CSINN_OP_REDUCE_MIN,
  218. CSINN_OP_REDUCE_PROD,
  219. CSINN_OP_REDUCE_SUM,
  220. CSINN_OP_RELU,
  221. CSINN_OP_RELU1,
  222. CSINN_OP_RELU6,
  223. CSINN_OP_RELUN,
  224. CSINN_OP_REORG,
  225. CSINN_OP_RESHAPE,
  226. CSINN_OP_RESIZE,
  227. CSINN_OP_REVERSE,
  228. CSINN_OP_ROIALIGN,
  229. CSINN_OP_ROIPOOL,
  230. CSINN_OP_ROUND,
  231. CSINN_OP_RSQRT,
  232. CSINN_OP_SCATTER_ND,
  233. CSINN_OP_SEGMENT_MAX,
  234. CSINN_OP_UNSORTED_SEGMENT_MAX,
  235. CSINN_OP_SEGMENT_MEAN,
  236. CSINN_OP_UNSORTED_SEGMENT_MEAN,
  237. CSINN_OP_SEGMENT_MIN,
  238. CSINN_OP_UNSORTED_SEGMENT_MIN,
  239. CSINN_OP_SEGMENT_PROD,
  240. CSINN_OP_UNSORTED_SEGMENT_PROD,
  241. CSINN_OP_SEGMENT_SUM,
  242. CSINN_OP_UNSORTED_SEGMENT_SUM,
  243. CSINN_OP_SELECT,
  244. CSINN_OP_SEQUENCE_MASK,
  245. CSINN_OP_SHAPE,
  246. CSINN_OP_SHUFFLE_CHANNEL,
  247. CSINN_OP_SIGMOID,
  248. CSINN_OP_SIGN,
  249. CSINN_OP_SIN,
  250. CSINN_OP_SINH,
  251. CSINN_OP_SLICE,
  252. CSINN_OP_SOFTMAX,
  253. CSINN_OP_SOFTPLUS,
  254. CSINN_OP_SOFTRELU,
  255. CSINN_OP_SOFTSIGN,
  256. CSINN_OP_SPACE_TO_BATCH,
  257. CSINN_OP_SPACE_TO_BATCH_ND,
  258. CSINN_OP_SPACE_TO_DEPTH,
  259. CSINN_OP_SPLIT,
  260. CSINN_OP_SQRT,
  261. CSINN_OP_SQUARE,
  262. CSINN_OP_SQUEEZE,
  263. CSINN_OP_STACK,
  264. CSINN_OP_STRIDED_SLICE,
  265. CSINN_OP_SUB,
  266. CSINN_OP_SUM,
  267. CSINN_OP_TAN,
  268. CSINN_OP_TANH,
  269. CSINN_OP_THRESHOLD_RELU,
  270. CSINN_OP_TILE,
  271. CSINN_OP_TOPK,
  272. CSINN_OP_TRANSPOSE,
  273. CSINN_OP_TRUNC,
  274. CSINN_OP_UNPOOLING,
  275. CSINN_OP_UNSTACK,
  276. CSINN_OP_WHERE,
  277. CSINN_OP_XOR,
  278. CSINN_OP_YUV_RGB_SCALE,
  279. CSINN_OP_SIZE,
  280. /* graph */
  281. CSINN_TENSOR,
  282. CSINN_SUBGRAPH,
  283. CSINN_SUBGRAPH_RETURN,
  284. CSINN_OP_AND_UTILS_SIZE,
  285. };
  286. enum csinn_runtime_enum {
  287. CSINN_SESSION_INIT,
  288. CSINN_SESSION_DEINIT,
  289. CSINN_SESSION_SETUP,
  290. CSINN_SESSION_RUN,
  291. CSINN_UPDATE_INPUT,
  292. CSINN_UPDATE_OUTPUT,
  293. CSINN_SET_INPUT_NUMBER,
  294. CSINN_SET_OUTPUT_NUMBER,
  295. CSINN_GET_INPUT_NUMBER,
  296. CSINN_GET_OUTPUT_NUMBER,
  297. CSINN_SET_INPUT,
  298. CSINN_SET_OUTPUT,
  299. CSINN_GET_INPUT,
  300. CSINN_GET_OUTPUT,
  301. CSINN_TENSOR_ENTRY,
  302. CSINN_LOAD_BG,
  303. CSINN_RUNTIME_OP_SIZE,
  304. };
  305. /* convolution mode */
  306. enum csinn_conv_mode_enum {
  307. CSINN_DIRECT = 0x0, /* using direct optimizational convolution */
  308. CSINN_WINOGRAD = 0x1, /* using winograd fast convolution */
  309. CSINN_GEMM = 0x2, /* using im2col + gemm convolution, im2col is optional */
  310. };
  311. /* pad mode */
  312. enum csinn_pad_enum {
  313. CSINN_PAD_CONSTANT = 0x0, /* pads with constant_value pad_value */
  314. CSINN_PAD_EDGE = 0x1, /* pads using the edge values of the input array */
  315. CSINN_PAD_REFLECT = 0x2, /* pads by reflecting values with respect to the edge */
  316. };
  317. /* resize mode */
  318. enum csinn_resize_enum {
  319. CSINN_RESIZE_BILINEAR = 0x0,
  320. CSINN_RESIZE_NEAREST_NEIGHBOR = 0x1,
  321. CSINN_RESIZE_NEAREST_BICUBIC = 0x2,
  322. };
  323. /* depth2space mode */
  324. enum csinn_depth2space_enum {
  325. CSINN_DEPTHTOSPACE_DCR = 0x0,
  326. CSINN_DEPTHTOSPACE_CRD = 0x1,
  327. };
  328. /* local_response_normalization(lrn) mode */
  329. enum csinn_lrn_enum {
  330. CSINN_LRN_ACROSS_CHANNELS = 0x0,
  331. CSINN_LRN_WITHIN_CHANNEL,
  332. };
  333. enum csinn_layout_enum {
  334. CSINN_LAYOUT_NULL = 0x0,
  335. // NCHW
  336. // ACTIVITION
  337. CSINN_LAYOUT_N,
  338. CSINN_LAYOUT_NC,
  339. CSINN_LAYOUT_NCW,
  340. CSINN_LAYOUT_NCHW,
  341. CSINN_LAYOUT_NCDHW,
  342. // WEIGHT
  343. CSINN_LAYOUT_O,
  344. CSINN_LAYOUT_OI,
  345. CSINN_LAYOUT_O16I16,
  346. CSINN_LAYOUT_O32I32,
  347. CSINN_LAYOUT_OIW,
  348. CSINN_LAYOUT_OIHW,
  349. CSINN_LAYOUT_OIDHW,
  350. CSINN_LAYOUT_O1HW, // depthwise kernel
  351. // NHWC
  352. // ACTIVITION
  353. CSINN_LAYOUT_NWC,
  354. CSINN_LAYOUT_NHWC,
  355. CSINN_LAYOUT_NDHWC,
  356. // WEIGHT
  357. CSINN_LAYOUT_OWI,
  358. CSINN_LAYOUT_OHWI,
  359. CSINN_LAYOUT_O16HWI16,
  360. CSINN_LAYOUT_O32HWI32,
  361. CSINN_LAYOUT_ODHWI,
  362. CSINN_LAYOUT_1HWO, // depthwise kernel
  363. CSINN_LAYOUT_1HW16O16,
  364. CSINN_LAYOUT_1HW32O32,
  365. // NCXHWX
  366. // ACTIVITION
  367. CSINN_LAYOUT_NC1HWC0, // rvv: c0=4/8/8 for fp32/fp16/int8 when vlen=128
  368. };
  369. enum csinn_status_enum {
  370. CSINN_UNSUPPORT_LAYOUT = -3,
  371. CSINN_UNSUPPORT_DTYPE = -2,
  372. CSINN_CALLBACK_UNSET = -1,
  373. CSINN_FALSE = 0,
  374. CSINN_TRUE = 1,
  375. };
  376. enum csinn_profiler_enum {
  377. CSI_PROFILER_LEVEL_UNSET = 0,
  378. CSI_PROFILER_LEVEL_TIMER, // print time
  379. };
  380. enum csinn_debug_enum {
  381. CSINN_DEBUG_LEVEL_DEBUG = -2,
  382. CSINN_DEBUG_LEVEL_INFO,
  383. CSINN_DEBUG_LEVEL_WARNING,
  384. CSINN_DEBUG_LEVEL_ERROR,
  385. CSINN_DEBUG_LEVEL_FATAL,
  386. };
  387. struct csinn_quant_info {
  388. int32_t zero_point;
  389. float scale;
  390. int32_t multiplier;
  391. int32_t shift;
  392. float min;
  393. float max;
  394. };
  395. #define MAX_DIM 8
  396. struct csinn_tensor {
  397. void *data;
  398. enum csinn_dtype_enum dtype;
  399. enum csinn_mem_type_enum mtype;
  400. int32_t dim[MAX_DIM];
  401. int32_t dim_count;
  402. uint32_t is_const;
  403. char *name;
  404. int32_t layout;
  405. int32_t quant_channel;
  406. struct csinn_quant_info *qinfo;
  407. struct csinn_session *sess;
  408. };
  409. struct csinn_model {
  410. char *bm_path;
  411. void *bm_addr;
  412. size_t bm_size;
  413. int32_t save_mode;
  414. int32_t priority;
  415. };
  416. struct csinn_session {
  417. int32_t base_dtype;
  418. int32_t base_layout;
  419. int32_t base_api;
  420. int32_t base_run_mode;
  421. enum csinn_quant_enum base_quant_type;
  422. struct csinn_model model;
  423. int32_t debug_level;
  424. int32_t profiler_level;
  425. int32_t input_num;
  426. int32_t output_num;
  427. struct csinn_tensor **input;
  428. struct csinn_tensor **output;
  429. void *td;
  430. };
  431. struct csinn_callback {
  432. int (*init)(); // initialization
  433. int (*est)(); // establish graph
  434. int (*exec)(); // execute real compute
  435. int (*caps)(); // capabilities
  436. int (*perf)(); // profiling
  437. };
  438. struct csinn_params_base {
  439. struct csinn_callback *cb;
  440. char *name;
  441. int32_t layout;
  442. int32_t api;
  443. enum csinn_quant_enum quant_type;
  444. struct csinn_session *sess;
  445. };
  446. struct csinn_fsmn_params {
  447. struct csinn_params_base base;
  448. int32_t l_order;
  449. int32_t r_order;
  450. int32_t l_stride;
  451. int32_t r_stride;
  452. int32_t unavailable_frames;
  453. };
  454. struct csinn_conv2d_params {
  455. struct csinn_params_base base;
  456. int32_t group;
  457. int32_t stride_height;
  458. int32_t stride_width;
  459. int32_t pad_top;
  460. int32_t pad_left;
  461. int32_t pad_down;
  462. int32_t pad_right;
  463. int32_t dilation_height;
  464. int32_t dilation_width;
  465. int32_t out_pad_height;
  466. int32_t out_pad_width;
  467. struct {
  468. struct csinn_tensor *kernel_tm;
  469. enum csinn_conv_mode_enum conv_mode;
  470. int32_t fuse_zp2bias;
  471. } conv_extra;
  472. };
  473. struct csinn_conv3d_params {
  474. struct csinn_params_base base;
  475. int32_t group;
  476. int32_t stride_depth;
  477. int32_t stride_height;
  478. int32_t stride_width;
  479. int32_t pad_top;
  480. int32_t pad_left;
  481. int32_t pad_down;
  482. int32_t pad_right;
  483. int32_t pad_front;
  484. int32_t pad_back;
  485. int32_t dilation_depth;
  486. int32_t dilation_height;
  487. int32_t dilation_width;
  488. int32_t out_pad_depth;
  489. int32_t out_pad_height;
  490. int32_t out_pad_width;
  491. };
  492. struct csinn_fc_params {
  493. struct csinn_params_base base;
  494. int32_t units;
  495. struct {
  496. int32_t fuse_zp2bias;
  497. } fc_extra;
  498. };
  499. struct csinn_pool_params {
  500. struct csinn_params_base base;
  501. int32_t pool_type;
  502. int32_t filter_height;
  503. int32_t filter_width;
  504. int32_t filter_depth;
  505. int32_t stride_height;
  506. int32_t stride_width;
  507. int32_t stride_depth;
  508. int32_t pad_top;
  509. int32_t pad_left;
  510. int32_t pad_down;
  511. int32_t pad_right;
  512. int32_t pad_front;
  513. int32_t pad_back;
  514. int32_t ceil_mode;
  515. bool count_include_pad;
  516. };
  517. struct csinn_unpooling_params {
  518. struct csinn_params_base base;
  519. int32_t scale_height;
  520. int32_t scale_width;
  521. int32_t pad_out_height;
  522. int32_t pad_out_width;
  523. };
  524. struct csinn_roi_align_params {
  525. struct csinn_params_base base;
  526. int32_t pooled_size_h;
  527. int32_t pooled_size_w;
  528. float spatial_scale;
  529. int32_t spatial_scale_multiplier;
  530. int32_t spatial_scale_shift;
  531. int32_t sample_ratio;
  532. };
  533. struct csinn_roi_pool_params {
  534. struct csinn_params_base base;
  535. int32_t pooled_size_h;
  536. int32_t pooled_size_w;
  537. float spatial_scale;
  538. int32_t spatial_scale_multiplier;
  539. int32_t spatial_scale_shift;
  540. };
  541. struct csinn_siso_params {
  542. struct csinn_params_base base;
  543. };
  544. struct csinn_scatter_nd_params {
  545. struct csinn_params_base base;
  546. };
  547. struct csinn_sigmoid_params {
  548. struct csinn_params_base base;
  549. };
  550. struct csinn_relu_params {
  551. struct csinn_params_base base;
  552. /* n / alpha / threshold */
  553. float n;
  554. int32_t n_multiplier;
  555. int32_t n_shift;
  556. };
  557. struct csinn_prelu_params {
  558. struct csinn_params_base base;
  559. int32_t axis;
  560. };
  561. struct csinn_softmax_params {
  562. struct csinn_params_base base;
  563. int32_t axis;
  564. };
  565. struct csinn_bn_params {
  566. struct csinn_params_base base;
  567. float epsilon;
  568. int32_t epsilon_multiplier;
  569. int32_t epsilon_shift;
  570. };
  571. struct csinn_l2n_params {
  572. struct csinn_params_base base;
  573. float epsilon;
  574. int32_t epsilon_multiplier;
  575. int32_t epsilon_shift;
  576. int32_t *axis;
  577. int32_t n;
  578. };
  579. struct csinn_lrn_params {
  580. struct csinn_params_base base;
  581. int32_t range;
  582. double bias;
  583. int32_t bias_multiplier;
  584. int32_t bias_shift;
  585. double alpha;
  586. int32_t alpha_multiplier;
  587. int32_t alpha_shift;
  588. double beta;
  589. int32_t beta_multiplier;
  590. int32_t beta_shift;
  591. enum csinn_lrn_enum norm_region;
  592. };
  593. struct csinn_matmul_params {
  594. struct csinn_params_base base;
  595. bool trans_a;
  596. bool trans_b;
  597. };
  598. struct csinn_diso_params {
  599. struct csinn_params_base base;
  600. };
  601. struct csinn_select_params {
  602. struct csinn_params_base base;
  603. };
  604. struct csinn_pad_params {
  605. struct csinn_params_base base;
  606. int32_t *pad_before;
  607. int32_t *pad_after;
  608. int32_t pad_num;
  609. float pad_value;
  610. enum csinn_pad_enum pad_mode;
  611. };
  612. struct csinn_resize_params {
  613. struct csinn_params_base base;
  614. enum csinn_resize_enum resize_mode;
  615. bool align_corners;
  616. };
  617. struct csinn_concat_params {
  618. struct csinn_params_base base;
  619. int32_t inputs_count;
  620. int32_t axis;
  621. };
  622. struct csinn_proposal_params {
  623. struct csinn_params_base base;
  624. float *scales;
  625. int32_t *scale_multipliers;
  626. int32_t *scale_shifts;
  627. int32_t scales_num;
  628. float *ratios;
  629. int32_t *ratio_multipliers;
  630. int32_t *ratio_shifts;
  631. int32_t ratios_num;
  632. int32_t feature_stride;
  633. float threshold;
  634. int32_t threshold_multiplier;
  635. int32_t threshold_shift;
  636. int rpn_pre_nms_top_n;
  637. int rpn_post_nms_top_n;
  638. int rpn_min_size;
  639. bool iou_loss;
  640. };
  641. struct csinn_psroipooling_params {
  642. struct csinn_params_base base;
  643. int32_t output_dim;
  644. int32_t group_size;
  645. float spatial_scale;
  646. int32_t spatial_scale_multiplier;
  647. int32_t spatial_scale_shift;
  648. };
  649. struct csinn_transpose_params {
  650. struct csinn_params_base base;
  651. int32_t *permute;
  652. int32_t permute_num;
  653. };
  654. struct csinn_reshape_params {
  655. struct csinn_params_base base;
  656. int32_t *shape;
  657. int32_t shape_num;
  658. };
  659. struct csinn_shape_params {
  660. struct csinn_params_base base;
  661. };
  662. struct csinn_expand_dims_params {
  663. struct csinn_params_base base;
  664. int32_t axis;
  665. };
  666. struct csinn_reverse_params {
  667. struct csinn_params_base base;
  668. int32_t axis;
  669. };
  670. struct csinn_flatten_params {
  671. struct csinn_params_base base;
  672. };
  673. struct csinn_crop_params {
  674. struct csinn_params_base base;
  675. int32_t axis;
  676. int32_t *offset;
  677. int32_t offset_num;
  678. };
  679. struct csinn_slice_params {
  680. struct csinn_params_base base;
  681. int32_t *begin;
  682. int32_t *end;
  683. int32_t *strides;
  684. int32_t slice_num;
  685. };
  686. struct csinn_split_params {
  687. struct csinn_params_base base;
  688. int32_t *split_index;
  689. int32_t output_num;
  690. int32_t axis;
  691. };
  692. struct csinn_stack_params {
  693. struct csinn_params_base base;
  694. int32_t inputs_count;
  695. int32_t axis;
  696. };
  697. struct csinn_tile_params {
  698. struct csinn_params_base base;
  699. int32_t *reps;
  700. int32_t reps_num;
  701. };
  702. struct csinn_arange_params {
  703. struct csinn_params_base base;
  704. float start;
  705. int32_t start_multiplier;
  706. int32_t start_shift;
  707. float stop;
  708. int32_t stop_multiplier;
  709. int32_t stop_shift;
  710. float step;
  711. int32_t step_multiplier;
  712. int32_t step_shift;
  713. };
  714. struct csinn_where_params {
  715. struct csinn_params_base base;
  716. };
  717. struct csinn_unstack_params {
  718. struct csinn_params_base base;
  719. int32_t outputs_count;
  720. int32_t axis;
  721. };
  722. struct csinn_gather_params {
  723. struct csinn_params_base base;
  724. int32_t axis;
  725. };
  726. struct csinn_gather_nd_params {
  727. struct csinn_params_base base;
  728. };
  729. struct csinn_squeeze_params {
  730. struct csinn_params_base base;
  731. int32_t *axis;
  732. int32_t axis_num;
  733. };
  734. struct csinn_ndarray_size_params {
  735. struct csinn_params_base base;
  736. };
  737. struct csinn_space_to_batch_params {
  738. struct csinn_params_base base;
  739. int32_t pad_top;
  740. int32_t pad_bottom;
  741. int32_t pad_left;
  742. int32_t pad_right;
  743. int32_t block_size;
  744. };
  745. struct csinn_space_to_batch_nd_params {
  746. struct csinn_params_base base;
  747. int32_t *paddings;
  748. int32_t *block_shape;
  749. int32_t spatial_dim_cnt;
  750. };
  751. struct csinn_batch_to_space_params {
  752. struct csinn_params_base base;
  753. int32_t crop_top;
  754. int32_t crop_bottom;
  755. int32_t crop_left;
  756. int32_t crop_right;
  757. int32_t block_size;
  758. };
  759. struct csinn_batch_to_space_nd_params {
  760. struct csinn_params_base base;
  761. int32_t *crops;
  762. int32_t *block_shape;
  763. int32_t spatial_dim_cnt;
  764. };
  765. struct csinn_space_to_depth_params {
  766. struct csinn_params_base base;
  767. int32_t block_size;
  768. };
  769. struct csinn_depth_to_space_params {
  770. struct csinn_params_base base;
  771. enum csinn_depth2space_enum mode;
  772. int32_t block_size;
  773. };
  774. struct csinn_one_hot_params {
  775. struct csinn_params_base base;
  776. float f_on_value;
  777. float f_off_value;
  778. int32_t on_value;
  779. int32_t off_value;
  780. int32_t depth;
  781. int32_t axis;
  782. };
  783. struct csinn_sequence_mask_params {
  784. struct csinn_params_base base;
  785. float mask_value;
  786. int32_t mask_value_multiplier;
  787. int32_t mask_value_shift;
  788. int32_t axis;
  789. };
  790. struct csinn_im2col_params {
  791. struct csinn_params_base base;
  792. int32_t pad_top;
  793. int32_t pad_down;
  794. int32_t pad_left;
  795. int32_t pad_right;
  796. int32_t stride_h;
  797. int32_t stride_w;
  798. int32_t kernel_h;
  799. int32_t kernel_w;
  800. };
  801. struct csinn_col2im_params {
  802. struct csinn_params_base base;
  803. int32_t pad_h;
  804. int32_t pad_w;
  805. int32_t stride_h;
  806. int32_t stride_w;
  807. };
  808. struct csinn_reduce_params {
  809. struct csinn_params_base base;
  810. int32_t *out_strides;
  811. int32_t *out_extents;
  812. int32_t n;
  813. int32_t *inner_strides;
  814. int32_t *inner_extents;
  815. int32_t m;
  816. int32_t *axis;
  817. int32_t axis_count;
  818. bool keepdims;
  819. };
  820. struct csinn_reorg_params {
  821. struct csinn_params_base base;
  822. int32_t stride;
  823. };
  824. struct csinn_segment_params {
  825. struct csinn_params_base base;
  826. int32_t num_segments;
  827. bool unsorted;
  828. };
  829. struct csinn_cumsum_params {
  830. struct csinn_params_base base;
  831. int32_t axis;
  832. bool exclusive;
  833. };
  834. struct csinn_cumprod_params {
  835. struct csinn_params_base base;
  836. int32_t axis;
  837. bool exclusive;
  838. };
  839. struct csinn_broadcast_to_params {
  840. struct csinn_params_base base;
  841. int32_t *shape;
  842. int32_t shape_count;
  843. };
  844. struct csinn_clip_params {
  845. struct csinn_params_base base;
  846. float min_value;
  847. float max_value;
  848. };
  849. struct csinn_strided_slice_params {
  850. struct csinn_params_base base;
  851. int32_t *begin;
  852. int32_t *end;
  853. int32_t *stride;
  854. int32_t slice_count;
  855. };
  856. struct csinn_shuffle_channel_params {
  857. struct csinn_params_base base;
  858. int32_t group;
  859. };
  860. struct csinn_topk_params {
  861. struct csinn_params_base base;
  862. int32_t k;
  863. };
  864. struct csinn_non_max_suppression_params {
  865. struct csinn_params_base base;
  866. int32_t max_output_size;
  867. float iou_threshold;
  868. // float score_threshold;
  869. };
  870. // modyfied to use asr model
  871. struct csinn_layer_norm_params {
  872. struct csinn_params_base base;
  873. float epsilon;
  874. bool center;
  875. bool scale;
  876. int32_t axis;
  877. };
  878. struct csinn_asr_buffer_t {
  879. size_t writer_index;
  880. size_t buffer_lenth; // lenth of buffer
  881. size_t data_lenth; // lenth of data
  882. uint8_t *buffer;
  883. uint8_t flag;
  884. };
  885. struct csinn_cache_matmul_params {
  886. struct csinn_params_base base;
  887. struct csinn_asr_buffer_t asr_buffer;
  888. int32_t *cache_shape;
  889. int32_t *shape;
  890. int32_t *axes;
  891. void *data;
  892. };
  893. struct csinn_cache_conv1d_params {
  894. struct csinn_params_base base;
  895. struct csinn_asr_buffer_t asr_buffer;
  896. int32_t *cache_shape;
  897. int32_t *in_shape;
  898. int32_t group;
  899. int32_t stride_width;
  900. int32_t dilation_width;
  901. int32_t pad_left;
  902. int32_t pad_right;
  903. void *data;
  904. };
  905. struct csinn_conv1d_params {
  906. struct csinn_params_base base;
  907. int32_t group;
  908. int32_t stride_width;
  909. int32_t dilation_width;
  910. int32_t pad_left;
  911. int32_t pad_right;
  912. };
  913. #endif // INCLUDE_CSI_INTERNAL_H_