You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

dnn_base_def.hpp 25 kB

5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994
  1. /**
  2. * Copyright 2019-2020 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef DNN_BASE_HPP__
  17. #define DNN_BASE_HPP__
  18. #include "cce/cce_def.hpp"
  19. namespace cce {
  20. /**
  21. * @ingroup dnn
  22. * @brief tiling para
  23. */
  24. typedef struct tagCcWeightCompressInfo {
  25. uint32_t blockRow; /**< block row */
  26. uint32_t blockCol; /**< block col */
  27. uint32_t fractalK; /**< fractal K */
  28. uint32_t fractalN; /**< fractal N */
  29. uint32_t lastFractalK; /**< K of last fractal */
  30. uint32_t lastFractalN; /**< N of last fractal */
  31. uint32_t cubeSize; /**< cube's length */
  32. uint32_t loadDir; /**< data load directtiono 0??col load 1:row load*/
  33. } ccWeightCompressInfo_t;
  34. /**
  35. * @ingroup dnn
  36. * @brief compress table info
  37. */
  38. typedef struct tagCcWeightCompressTab {
  39. uint16_t dataLen : 14; /**< 0: data length in 128 Byte */
  40. uint16_t storeFlag : 1; /**< 0: compressed addr = original addr, 1: compressed addr = original addr + 256 Byte */
  41. uint16_t dataType : 1; /**< 0: original data, 1: compressed data */
  42. } ccWeightCompressTab_t;
  43. /**
  44. * @conv quantize dnn vector mode/scalar mode
  45. */
  46. typedef enum {
  47. QUANT_ALGO_NON_OFFSET = 0,
  48. QUANT_ALGO_HALF_OFFSET = 1,
  49. QUANT_ALGO_ALL_OFFSET = 2,
  50. QUANT_ALGO_BUTT
  51. } ccQuantizeAlgo_t;
  52. typedef enum { SCALE_VEC = 0, SCALE_SCALAR = 1, SCALE_TYPE_BUTT } ccConvolutionScaleType_t, ccScaleType_t;
  53. /**
  54. * @conv quantize dnn sqrt mode/non sqrt mode
  55. */
  56. typedef enum {
  57. SCALE_NORMAL = 0,
  58. SCALE_SQRT = 1,
  59. SCALE_VALUE_MODE_BUTT
  60. } ccConvolutionScaleValueMode_t,
  61. ccScaleValueMode_t;
  62. typedef struct {
  63. float scaleW;
  64. float scaleD;
  65. float scaleDNext;
  66. uint8_t offsetW;
  67. uint8_t offsetD;
  68. uint8_t offsetDNext;
  69. } ccQuantAllOffsetPara_t;
  70. typedef struct tagCcVecQuantizePara {
  71. float scale;
  72. uint16_t offset;
  73. uint16_t rrv; // 32byte align
  74. } ccVecQuantizePara_t;
  75. /**
  76. * @ingroup dnn
  77. * @brief format of tensor
  78. */
  79. typedef enum tagCcTensorFormat {
  80. CC_TENSOR_NCHW = 0, /**< NCHW */
  81. CC_TENSOR_NHWC, /**< NHWC */
  82. CC_TENSOR_ND, /**< Nd Tensor */
  83. CC_TENSOR_NC1HWC0, /**< NC1HWC0 */
  84. CC_TENSOR_FRACTAL_Z, /**< FRACTAL_Z */
  85. CC_TENSOR_NC1C0HWPAD,
  86. CC_TENSOR_NHWC1C0,
  87. CC_TENSOR_FSR_NCHW,
  88. CC_TENSOR_FRACTAL_DECONV,
  89. CC_TENSOR_C1HWNC0,
  90. CC_TENSOR_FRACTAL_DECONV_TRANSPOSE,
  91. CC_TENSOR_FRACTAL_DECONV_SP_STRIDE_TRANS,
  92. CC_TENSOR_NC1HWC0_C04, /**< NC1HWC0, C0 =4*/
  93. CC_TENSOR_FRACTAL_Z_C04, /**< FRACZ?????C0 =4 */
  94. CC_TENSOR_CHWN,
  95. CC_TENSOR_FRACTAL_DECONV_SP_STRIDE8_TRANS,
  96. CC_TENSOR_HWCN,
  97. CC_TENSOR_NC1KHKWHWC0, /** < KH,KW kernel h& kernel w maxpooling max output format*/
  98. CC_TENSOR_HASHTABLE_LOOKUP_LOOKUPS = 20,
  99. CC_TENSOR_HASHTABLE_LOOKUP_KEYS,
  100. CC_TENSOR_HASHTABLE_LOOKUP_VALUE,
  101. CC_TENSOR_HASHTABLE_LOOKUP_OUTPUT,
  102. CC_TENSOR_HASHTABLE_LOOKUP_HITS = 24,
  103. CC_TENSOR_C1HWNCoC0, /**< C1,H,W,N,Co,C0 6D diagonal format*/
  104. CC_TENSOR_RESERVED
  105. } ccTensorFormat_t;
  106. /**
  107. * @ingroup dnn
  108. * @brief format of compare
  109. */
  110. typedef enum tagCcCompareType {
  111. CC_COMPARE_TYPE_LESS = 0,
  112. CC_COMPARE_TYPE_LESS_EQUAL,
  113. CC_COMPARE_TYPE_NOT_EQUAL,
  114. CC_COMPARE_TYPE_EQUAL,
  115. CC_COMPARE_TYPE_GREATER,
  116. CC_COMPARE_TYPE_GREATER_EQUAL,
  117. CC_COMPARE_TYPE_RESERVED
  118. } ccCompareType_t;
  119. /**
  120. * @ingroup dnn
  121. * @brief propagate Nan
  122. */
  123. typedef enum tagCcNanPropagation {
  124. CC_NAN_NOT_PROPAGATE = 0, /**< Nan numbers are not propagated */
  125. CC_NAN_PROPAGATE, /**< Nan numbers are propagated */
  126. CC_NAN_PROPAGATE_RESERVED
  127. } ccNanPropagation_t;
  128. /**
  129. * @ingroup dnn
  130. * @brief algorithm of convolution forward
  131. */
  132. typedef enum tagCcConvolutionFwdAlgo {
  133. CC_CONVOLUTION_FWD_ALGO_GEMM = 0, /**< matrix gemm algo */
  134. CC_CONVOLUTION_FWD_ALGO_WINOGRAD, /**< Winograd Transform algo */
  135. CC_CONVOLUTION_FWD_ALGO_GEMM_ACCU_FLOAT32,
  136. CC_CONVOLUTION_FWD_ALGO_RESERVED
  137. } ccConvolutionFwdAlgo_t;
  138. #define ccCorrelationFwdAlgo_t ccConvolutionFwdAlgo_t
  139. typedef enum tagCcConvolutionBwdAlgo {
  140. CC_CONVOLUTION_BWD_ALGO_GEMM = 0, /**< matrix gemm algo */
  141. CC_CONVOLUTION_BWD_ALGO_WINOGRAD, /**< Winograd Transform algo */
  142. CC_CONVOLUTION_BWD_ALGO_GEMM_CO2IMG,
  143. CC_CONVOLUTION_BWD_FILTER_GEM_ALGO,
  144. CC_CONVOLUTION_BWD_ALGO_RESERVED
  145. } ccConvolutionBwdAlgo_t;
  146. #define ccCorrelationBwdAlgo_t ccConvolutionBwdAlgo_t
  147. /**
  148. * @ingroup dnn
  149. * @brief algorithm of FullConnect forward
  150. */
  151. typedef enum tagCcFullConnectFwdAlgo {
  152. CC_FULLCONNECT_FWD_ALGO_HALF = 0,
  153. CC_FULLCONNECT_FWD_ALGO_FLOAT32
  154. } ccFullConnectFwdAlgo_t;
  155. /**
  156. * @ingroup dnn
  157. * @brief mode of convolution
  158. */
  159. typedef enum tagCcConvolutionMode {
  160. CC_CONV_CONVOLUTION = 0, /**< math convolution */
  161. CC_CONV_CROSS_CORRELATION, /**< cross-correlation convolution */
  162. CC_CONV_DECONVOLUTION, /**< deconvolution, also named transposed convolution*/
  163. CC_CONV_MODE_DEPTHWISE, /**< depthwise convolution*/
  164. CC_CONV_MODE_RESERVED
  165. } ccConvolutionMode_t;
  166. #define ccCorrelationMode_t ccConvolutionMode_t
  167. /**
  168. * @ingroup dnn
  169. * @brief mode of pooling
  170. */
  171. typedef enum tagCcPoolingMode {
  172. CC_POOLING_MAX = 0, /**< max pooling */
  173. CC_POOLING_AVG, /**< average pooling */
  174. CC_POOLING_L2, /**< L2 pooling */
  175. CC_POOLING_AVG_FP32, /**< average pooling for training */
  176. CC_POOLING_RESERVED
  177. } ccPoolingMode_t;
  178. /**
  179. * @ingroup dnn
  180. * @brief L0C accumulate algo of AvgPooling
  181. */
  182. typedef enum tagCcPooingFwdAlgo {
  183. CC_POOLING_FWD_ALGO_HALF = 0, // accumulate in L0c with FP16
  184. CC_POOLING_FWD_ALGO_FLOAT32 // accumulate in L0c with FP32
  185. } ccPooingFwdAlgo_t;
  186. /**
  187. * @ingroup dnn
  188. * @brief mode of momentum
  189. */
  190. typedef enum tagMomentumAlgo {
  191. CC_MOMENTUM_UPDATE_FP32 = 0, /**< FP32 out */
  192. CC_MOMENTUM_UPDATE_FP32_FP16, /**< FP32 and FP16 out */
  193. CC_MOMENTUM_UPDATE_FP32_NESTEROV,
  194. CC_MOMENTUM_UPDATE_FP32_FP16_NESTEROV,
  195. CC_MOMENTUM_RESERVED
  196. } ccMomentumAlgo_t;
  197. /**
  198. * @ingroup dnn
  199. * @brief mode of partitionStrategy
  200. *attention: if need to motify this struct,please must motify dPartitionStrategy_t
  201. */
  202. typedef enum tagCcPartitionStrategy {
  203. CC_PARTITION_STRATEGY_MOD = 0, /**< mod */
  204. CC_PARTITION_STRATEGY_DIV, /**< div */
  205. CC_PARTITION_STRATEGY_RESERVED
  206. } ccPartitionStrategy_t;
  207. /**
  208. * @ingroup dnn
  209. * @brief mode of assignOp
  210. */
  211. typedef enum tagCcAssignOpMode {
  212. CC_ASSIGN_ADD = 0, /**< assign add */
  213. CC_ASSIGN_SUB, /**< assign sub */
  214. CC_ASSIGN_RESERVED
  215. } ccAssignOpMode_t;
  216. /**
  217. * @ingroup dnn
  218. * @brief mode of arcSinCos
  219. */
  220. typedef enum tagCcArcSinCosMode {
  221. CC_ARCUS_SIN = 0, /**< asin */
  222. CC_ARCUS_COS, /**< acos */
  223. CC_ARCUS_RESERVED
  224. } ccArcSinCosMode_t;
  225. /**
  226. * @ingroup dnn
  227. * @brief mode of padding
  228. */
  229. typedef enum tagCcPaddingMode {
  230. CC_PADDING_CEIL = 0,
  231. CC_PADDING_DIRECTASSIGN,
  232. CC_PADDING_VALID,
  233. CC_PADDING_SAME, /**< Padding values of 0 are always used */
  234. CC_PADDING_CEIL_NEW, /*new ceil,use for backward compatibility*/
  235. CC_PADDING_VALID_NEW, /*new valid,use for backward compatibility*/
  236. CC_PADDING_SAME_NEW, /*new same,use for backward compatibility*/
  237. CC_PADDING_RESERVED
  238. } ccPaddingMode_t;
  239. /**
  240. * @ingroup dnn
  241. * @brief mode of activation
  242. */
  243. typedef enum tagCcActivationMode {
  244. CC_ACTIVATION_SIGMOID = 0, /**< sigmoid */
  245. CC_ACTIVATION_RELU, /**< ReLU */
  246. CC_ACTIVATION_TANH, /**< tanh */
  247. CC_ACTIVATION_CLIPPED_RELU, /**< clipped ReLU */
  248. CC_ACTIVATION_ELU, /**< ELU */
  249. CC_ACTIVATION_LEAKY_RELU,
  250. CC_ACTIVATION_ABS, /**< Abs */
  251. CC_ACTIVATION_RELU1, /**< relu1 */
  252. CC_ACTIVATION_SOFTSIGN, /**< softsign */
  253. CC_ACTIVATION_SOFTPLUS, /**< softplus */
  254. CC_ACTIVATION_HARDSIGMOID, /**< hardsigmoid*/
  255. CC_ACTIVATION_THRESHOLD_RELU, /**< threshold */
  256. CC_ACTIVATION_SELU, /**< selu */
  257. CC_ACTIVATION_LINEAR, /**< linear */
  258. CC_ACTIVATION_RELU6, /**< relu6 */
  259. CC_ACTIVATION_RESERVED
  260. } ccActivationMode_t;
  261. /**
  262. * @ingroup dnn
  263. * @brief mode of logical op mode
  264. */
  265. typedef enum tagCcLogicalOpMode {
  266. CC_LOGICAL_OP_NOT = 0, /**logical not**/
  267. CC_LOGICAL_OP_AND, /**logical and**/
  268. CC_LOGICAL_OP_OR, /**logical or**/
  269. CC_LOGICAL_OP_XOR, /**logical xor**/
  270. CC_LOGICAL_OP_RESERVED
  271. } ccLogicalOpMode_t;
  272. /**
  273. * @ingroup dnn
  274. * @brief mode of batchnorm
  275. */
  276. typedef enum tagCcBatchNormMode {
  277. CC_BATCHNORM_PER_ACTIVATION = 0, /**< bnScale, bnBias tensor dims are 1xCxHxW */
  278. CC_BATCHNORM_SPATIAL, /**< bnScale, bnBias tensor dims are 1xCx1x1 */
  279. CC_BATCHNORM_RESERVED
  280. } ccBatchNormMode_t;
  281. /**
  282. * @ingroup dnn
  283. * @brief mode of instancenorm
  284. */
  285. typedef enum tagCcInstanceNormMode {
  286. CC_INSTANCENORM_PER_ACTIVATION = 0, /**< inScale, inBias tensor dims are NxCxHxW */
  287. CC_INSTANCENORM_SPATIAL, /**< inScale, inBias tensor dims are NxCx1x1 */
  288. CC_INSTANCENORM_RESERVED
  289. } ccInstanceNormMode_t;
  290. /**
  291. * @ingroup dnn
  292. * @brief mode of layernorm
  293. */
  294. typedef enum tagCcLayerNormMode {
  295. CC_LAYERNORM_PER_ACTIVATION = 0, /**< lnScale, lnBias tensor dims are 1xCxHxW */
  296. CC_LAYERNORM_SPATIAL, /**< lnScale, lnBias tensor dims are Nx1x1x1 */
  297. CC_LAYERNORM_RESERVED
  298. } ccLayerNormMode_t;
  299. /**
  300. * @ingroup dnn
  301. * @brief softmax algorithm
  302. */
  303. typedef enum tagCcSoftmaxAlgo {
  304. CC_SOFTMAX_FAST = 0, /**< straightforward implementation */
  305. CC_SOFTMAX_ACCURATE, /**< subtract max from every point to avoid overflow */
  306. CC_SOFTMAX_LOG, /**< perform the Log softmax operation to avoid overflow */
  307. CC_SOFTMAX_ACCURATE_FP32, /**< accurate mode for fp32 */
  308. CC_SOFTMAX_RESERVED
  309. } ccSoftmaxAlgo_t;
  310. /**
  311. * @ingroup dnn
  312. * @brief softmax mode
  313. */
  314. typedef enum tagCcSoftmaxMode {
  315. CC_SOFTMAX_MODE_INSTANCE = 0, /**< compute the softmax over all C, H, W for each N */
  316. CC_SOFTMAX_MODE_CHANNEL, /**< compute the softmax over all C for each H, W, N */
  317. CC_SOFTMAX_MODE_HEIGHT, /**< compute the softmax over all H for each N, C, W */
  318. CC_SOFTMAX_MODE_WIDTH, /**< compute the softmax over all W for each N, C, H */
  319. CC_SOFTMAX_MODE_CLASS, /**< special mode: compute the softmax over all class for each N, H ,W */
  320. CC_SOFTMAX_MODE_RESERVED
  321. } ccSoftmaxMode_t;
  322. /**
  323. * @ingroup dnn
  324. * @brief cross entropy mode
  325. */
  326. typedef enum tagCcCrossEntropyMode {
  327. CC_CROSS_ENTROPY_SPARSE_WITHOUT_REDUCTION = 0, /**< compute the sparse cross entropy without fused reduce mean */
  328. CC_CROSS_ENTROPY_SPARSE_WITH_REDUCTION, /**< compute the sparse cross entropy with fused reduce mean*/
  329. CC_CROSS_ENTROPY_WITHOUT_REDUCTION, /**< compute the cross entropy without fused reduce mean */
  330. CC_CROSS_ENTROPY_WITH_REDUCTION, /**< compute the cross entropy with fused reduce mean */
  331. CC_CROSS_ENTROPY_RESERVED
  332. } ccCrossEntropyMode_t;
  333. /**
  334. * @ingroup dnn
  335. * @brief concat mode
  336. */
  337. typedef enum tagCcConcatMode {
  338. CC_CONCAT_BY_BATCH = 0, /**< concat by batch */
  339. CC_CONCAT_BY_FEATURE, /**< concat by feature */
  340. CC_CONCAT_BY_HEIGHT, /**< concat by height */
  341. CC_CONCAT_BY_WIDTH, /**< concat by width */
  342. CC_CONCAT_BY_FLATTEN,
  343. CC_CONCAT_RESERVED
  344. } ccConcatMode_t;
  345. /**
  346. * @ingroup dnn
  347. * @brief eltwise mode
  348. */
  349. typedef enum tagCcEltwiseMode {
  350. CC_ELTWISE_PROD = 0, /**< prod */
  351. CC_ELTWISE_SUM, /**< sum */
  352. CC_ELTWISE_MAX, /**< max */
  353. CC_ELTWISE_RESERVED
  354. } ccEltwiseMode_t;
  355. /**
  356. * @ingroup dnn
  357. * @brief depthwise filter type
  358. */
  359. typedef enum tagCcDepthwiseFilterType {
  360. CC_Depthwise_FILTER_DEPTHWISE = 0, /**< depthwise filter */
  361. CC_Depthwise_FILTER_POINTWISE, /**< pointwise filter */
  362. CC_Depthwise_FILTER_RESERVED
  363. } ccDepthwiseFilterType_t;
  364. /**
  365. * @ingroup dnn
  366. * @brief sampler type
  367. */
  368. typedef enum tagCcSamplerType {
  369. CC_SAMPLER_BILINEAR = 0, /**< bilinear sampler algo */
  370. CC_SAMPLER_RESERVED
  371. } ccSamplerType_t;
  372. /**
  373. * @ingroup dnn
  374. * @brief NMS type
  375. */
  376. typedef enum tagCcNmsType {
  377. CC_NMS_IOU = 0, /**< nms operation type, only IOU for now */
  378. CC_NMS_RESERVED
  379. } ccNmsType_t;
  380. /**
  381. * @ingroup dnn
  382. * @brief Box Code type
  383. */
  384. typedef enum tagCcBoxCodeType {
  385. CC_BOX_CORNER = 1, /**< Box CodeType in detection nets */
  386. CC_BOX_CENTER_SIZE,
  387. CC_BOX_CORNER_SIZE,
  388. CC_BOX_RESERVED
  389. } ccBoxCodeType_t;
  390. /**
  391. * @ingroup dnn
  392. * @brief split mode
  393. */
  394. typedef enum tagSplitMode {
  395. CC_SPLIT_MODE_SLICE = 0, /**< spilt data of one dim*/
  396. CC_SPLIT_MODE_DUPLICATE, /**< copy data of one dim*/
  397. CC_SPLIT_MODE_RESERVED
  398. } ccSplitMode_t;
  399. /**
  400. * @ingroup dnn
  401. * @brief mode of LRN
  402. */
  403. typedef enum tagCcLRNMode {
  404. CC_LRN_CROSS_CHANNELS = 0, /**< CROSS_CHANNELS */
  405. CC_LRN_WITHIN_CHANNELS, /**< WITHIN_CHANNELS */
  406. CC_LRN_RESERVED
  407. } ccLRNMode_t;
  408. /**
  409. * @ingroup dnn
  410. * @brief format of AIPP input
  411. */
  412. typedef enum tagCcAippInputFormat {
  413. CC_AIPP_INPUT_YUV420SP_U8 = 1,
  414. /**< YUV420SP */ // mini,lite,tiny
  415. CC_AIPP_INPUT_XRGB8888_U8,
  416. /**< XRGB8888 */ // mini,lite,tiny
  417. CC_AIPP_INPUT_NC1HWC0DI_FP16,
  418. /**< NC1HWC0DI_FP16 */ // mini
  419. CC_AIPP_INPUT_NC1HWC0DI_S8,
  420. /**< NC1HWC0DI_S8 */ // mini
  421. CC_AIPP_INPUT_RGB888_U8,
  422. /**< RGB888 */ // mini,tiny
  423. CC_AIPP_INPUT_ARGB8888_U8,
  424. /**< ARGB8888 */ // lite
  425. CC_AIPP_INPUT_YUYV_U8,
  426. /**< YUYV */ // lite
  427. CC_AIPP_INPUT_YUV422SP_U8,
  428. /**< YUV422SP */ // lite
  429. CC_AIPP_INPUT_AYUV444_U8,
  430. /**< AYUV444 */ // lite
  431. CC_AIPP_INPUT_YUV400_U8,
  432. /**< YUV400 */ // mini,lite,tiny
  433. CC_AIPP_INPUT_RESERVED
  434. } ccAippInputFormat_t;
  435. /**
  436. * @ingroup dnn
  437. * @brief mode of AIPP padding
  438. */
  439. typedef enum tagCcAippPaddingMode {
  440. CC_AIPP_PAD_DEFAULT_VALUE = 1, /**< CONFIG_VALUE */
  441. CC_AIPP_PAD_LINE_COPY, /**< ROW_COL_COPY */
  442. CC_AIPP_PAD_BLOCK_COPY, /**< BLOCK_COPY */
  443. CC_AIPP_PAD_MIRROR_COPY, /**< MIRROR_COPY */
  444. CC_AIPP_PAD_RESERVED
  445. } ccAippPaddingMode_t;
  446. /**
  447. * @ingroup dnn
  448. * @brief format of cmp type
  449. */
  450. typedef enum tagCcccCMPType {
  451. CC_CMP_EQ = 0,
  452. CC_CMP_NE,
  453. CC_CMP_LT,
  454. CC_CMP_GT,
  455. CC_CMP_GE,
  456. CC_CMP_LE,
  457. CC_CMP_TYPE_RESERVED
  458. } ccCMPType_t;
  459. /**
  460. * @ingroup dnn
  461. * @brief mode of logical op mode
  462. */
  463. typedef enum tagCcResultType {
  464. CC_Result_AND = 0, /**logical and**/
  465. CC_Result_OR, /**logical or**/
  466. CC_Result_RESERVED
  467. } ccResultType_t;
  468. /**
  469. * @ingroup dnn
  470. * @brief method of crop_and_resize operator
  471. */
  472. typedef enum tagCcResizeMethod {
  473. CC_RESIZE_METHOD_BILINEAR = 0, /** BILINEAR */
  474. CC_RESIZE_METHOD_NEAREST, /** NEAREST */
  475. CC_RESIZE_METHOD_RESERVED
  476. } ccResizeMethod_t;
  477. /**
  478. * @ingroup dnn
  479. * @brief mode of calculating new size of the images
  480. */
  481. typedef enum tagCcResizeOutputDimMode {
  482. RESIZE_OUTPUT_DIM_BY_ZOOM_FACTOR = 0, /**< Output dimension specified by zoom factor*/
  483. RESIZE_OUTPUT_DIM_BY_SHRINK_FACTOR, /**< specified by shrink factor */
  484. RESIZE_OUTPUT_DIM_EXPLICIT, /**< specified explicitly */
  485. RESIZE_OUTPUT_DIM_RESERVED
  486. } ccResizeOutputDimMode_t;
  487. typedef enum tagCcYoloVersion {
  488. CC_YOLO_V2 = 1, /**< YOLOv2 */
  489. CC_YOLO_V3, /**< YOLOv3 */
  490. CC_YOLO_RESERVED
  491. } ccYoloVersion_t;
  492. typedef enum tagCcAttentionAlgo {
  493. // bahdanau-attention, for detail:https://pravn.wordpress.com/2017/11/14/bahdanau-attention/
  494. CC_ATTENTION_ALGO_BAHDANAU = 0,
  495. CC_ATTENTION_ALGO_NORMAL_BAHDANAU = 1,
  496. CC_ATTENTION_ALGO_LUONG = 2,
  497. CC_ATTENTION_ALGO_SCALED_LUONG = 3,
  498. CC_ATTENTION_ALGO_RESERVED
  499. } AttentionAlgo_t;
  500. /**
  501. * @ingroup dnn
  502. * @brief desc of data layout
  503. */
  504. typedef enum ccEmAttnDecoderDataLayout {
  505. CC_ATTN_5D_TX1BX, //[max_time,Xt1,1,batch_size,Xt0]
  506. CC_ATTN_5D_BTX1X, //[batch_size*max_time,Xt1,1,1,Xt0]
  507. CC_ATTN_DL_RESERVED
  508. } ccEmAttnDecoderDataLayout_t;
  509. /**
  510. * @ingroup dnn
  511. * @brief operation of Reduce
  512. */
  513. typedef enum {
  514. CC_REDUCE_OP_SUM = 0, /**< sum */
  515. CC_REDUCE_OP_MEAN, /**< mean */
  516. CC_REDUCE_OP_PROD, /**< product */
  517. CC_REDUCE_OP_ALL, /**< logical and */
  518. CC_REDUCE_OP_ABS_SUM, /**< absolute sum */
  519. CC_REDUCE_OP_SQUARE_SUM, /**< square sum */
  520. CC_REDUCE_OP_MAX, /**< max */
  521. CC_REDUCE_OP_MIN, /**< min */
  522. CC_REDUCE_OP_LOGSUMEXP, /**< logsumexp */
  523. CC_REDUCE_OP_INVALID
  524. } ccReduceOpType_t;
  525. /**
  526. * @ingroup dnn
  527. * @brief desc of tpye layout
  528. */
  529. typedef enum {
  530. LSH_PROJECTION_TYPE_UNKNOWN = 0,
  531. LSH_PROJECTION_TYPE_SPARSE = 1,
  532. LSH_PROJECTION_TYPE_DENSE = 2
  533. } LSHProjectionType;
  534. /**
  535. * @ingroup dnn
  536. * @brief activation para
  537. */
  538. typedef struct tagCcActivationRelu {
  539. double reluCoef; /* reluCoef for clipped RELU */
  540. ccNanPropagation_t reluNanOpt;
  541. } ccActivationRelu_t;
  542. typedef union tagCcActivationPara {
  543. ccActivationRelu_t actionRelu; /* relu Coef and NanOpt for clipped RELU */
  544. double eluAlpha; /* eluAlpha for ELU */
  545. float leakyReluNegativeSlope;
  546. } ccActivationPara_u;
  547. /**
  548. * @ingroup dnn
  549. * @bref mode of square
  550. */
  551. typedef enum tagCcSquareMode {
  552. CC_SQUARE_2 = 0, /* square */
  553. } ccSquareMode_t;
  554. /**
  555. * @ingroup dnn
  556. * @brief append operation type
  557. */
  558. typedef enum tagCcOpType {
  559. CC_OP_TYPE_NO_RELU = 0,
  560. CC_OP_TYPE_RELU = 1,
  561. CC_OP_TYPE_RELU6 = 2,
  562. CC_OP_TYPE_INVALID
  563. } ccOpType_t;
  564. /**
  565. * @ingroup dnn
  566. * @brief struct define of fill operator type.
  567. */
  568. typedef enum tagCcFillOpType {
  569. CC_CONSTANT = 0,
  570. CC_RANGE,
  571. CC_LENGTH_RANGE,
  572. CC_GIVEN_TENSOR,
  573. CC_DIAGONAL,
  574. CC_UNIFORM,
  575. CC_UNIFORM_INT,
  576. CC_UNIQUE_UNIFORM,
  577. CC_GAUSSIAN,
  578. CC_XAVIER,
  579. CC_MSRA,
  580. CC_FILL_OP_TYPE_RESERVED
  581. } ccFillOpType_t;
  582. /**
  583. * @ingroup dnn
  584. * @brief loss function reduction mode
  585. */
  586. typedef enum tagCcLossReduction {
  587. CC_LOSS_REDUCTION_NONE = 0,
  588. CC_LOSS_REDUCTION_SUM,
  589. CC_LOSS_REDUCTION_RESERVED
  590. } ccLossReduction_t;
  591. /**
  592. * @ingroup dnn
  593. * @brief max size of ccIntArray
  594. */
  595. #define CC_INT_ARRAY_MAX_SIZE (8)
  596. /**
  597. * @ingroup dnn
  598. * @brief struct define of int array less than 8.
  599. */
  600. typedef struct tagIntArray {
  601. uint32_t size;
  602. int32_t value[CC_INT_ARRAY_MAX_SIZE];
  603. } ccIntArray_t;
  604. typedef enum tagCcPadMode {
  605. CC_PAD_CONSTANT = 0, /*CONSTANT */
  606. CC_PAD_REFLECT, /*REFLECT */
  607. CC_PAD_SYMMETRIC, /*SYMMETRIC*/
  608. CC_PAD_EDGE, /*EDGE */
  609. CC_PAD_MODE_RESERVED
  610. } ccPadMode_t;
  611. /*
  612. * @ingroup dnn
  613. * @brief pad operation of extractImagePatches
  614. */
  615. typedef enum {
  616. CC_EXTRACT_IMAGE_PATCHES_PAD_VALID = 1,
  617. CC_EXTRACT_IMAGE_PATCHES_PAD_SAME,
  618. CC_EXTRACT_IMAGE_PATCHES_PAD_RESERVED
  619. } ccExtractImagePatchesPadType_t;
  620. /**
  621. * @ingroup dnn
  622. * @brief image dimensions of aipp input
  623. */
  624. #define CC_AIPP_IMG_DIM (2)
  625. /**
  626. * @ingroup dnn
  627. * @brief image channel number of aipp input
  628. */
  629. #define CC_AIPP_IMG_CHN_NUM (4)
  630. /**
  631. * @ingroup dnn
  632. * @brief element number of aipp color space convertion matrix
  633. */
  634. #define CC_AIPP_CSC_MATRIX_DIM (9)
  635. /**
  636. * @ingroup dnn
  637. * @brief element number of aipp color space convertion bias
  638. */
  639. #define CC_AIPP_CSC_BIAS_DIM (3)
  640. /**
  641. * @ingroup dnn
  642. * @brief struct define of AIPP operator
  643. */
  644. typedef struct tagCcAipp {
  645. ccAippInputFormat_t inputFormat;
  646. ccDataType_t outputFormat;
  647. int32_t srcImageSize[CC_AIPP_IMG_DIM];
  648. int32_t loadStartPos[CC_AIPP_IMG_DIM];
  649. int32_t loadSize[CC_AIPP_IMG_DIM];
  650. int32_t scfInputSize[CC_AIPP_IMG_DIM];
  651. int32_t scfOutputSize[CC_AIPP_IMG_DIM];
  652. int32_t cscMatrix[CC_AIPP_CSC_MATRIX_DIM];
  653. int32_t cscOutputBias[CC_AIPP_CSC_BIAS_DIM];
  654. int32_t cscInputBias[CC_AIPP_CSC_BIAS_DIM];
  655. int32_t dtcPixelMean[CC_AIPP_IMG_CHN_NUM];
  656. float dtcPixelMin[CC_AIPP_IMG_CHN_NUM];
  657. float dtcPixelVarReci[CC_AIPP_IMG_CHN_NUM];
  658. ccAippPaddingMode_t paddingMode;
  659. int32_t paddingSize[CC_AIPP_IMG_DIM * 2]; // up,down,left,right
  660. float cpaddingVaule;
  661. bool cscSwitch; // 0:off,1:on
  662. bool scfSwitch; // 0:off,1:on
  663. bool rbuvSwapSwitch;
  664. bool axSwapSwitch;
  665. bool singleLineMode;
  666. bool cscConfigFlag;
  667. bool dtcConfigFlag;
  668. bool padConfigFlag;
  669. bool commConfigFlag;
  670. bool aippEn;
  671. bool dyncAippFlag;
  672. const void *dyncParaAddr;
  673. bool rotationFlag;
  674. } ccConvolutionAipp_t;
  675. typedef struct tagCcQuantizePara {
  676. ccConvolutionScaleValueMode_t scaleValueMode;
  677. uint16_t *scale;
  678. uint16_t *offsetq;
  679. int32_t *offsetw;
  680. uint8_t *allOffsetw;
  681. uint8_t *offsetPad;
  682. } CcQuantizePara_t;
  683. typedef struct tagCcQuantize {
  684. ccQuantizeAlgo_t quantAlgo;
  685. ccConvolutionScaleType_t scaleWType; // show scaleRq,scaleDq type
  686. CcQuantizePara_t scaleQ;
  687. CcQuantizePara_t scaleRq;
  688. CcQuantizePara_t scaleDq;
  689. // need relu
  690. bool reluFlag;
  691. // relu6
  692. uint16_t *scaleRelu6;
  693. bool bConcat;
  694. } ccQuantize_t;
  695. typedef struct tagCcPad *ccPadDescriptor_t;
  696. /**
  697. * @ingroup dnn
  698. * @brief operation of Cum
  699. */
  700. typedef enum {
  701. CC_CUM_OP_SUM = 0, /**< sum */
  702. CC_CUM_OP_PROD, /**< product */
  703. CC_CUM_OP_INVALID
  704. } CumOpType;
  705. /**
  706. * @ingroup dnn
  707. * @brief desciptor of tensor
  708. */
  709. typedef struct tagCcTensor *ccTensorDescriptor_t;
  710. /**
  711. * @ingroup dnn
  712. * @brief desciptor of filter tensor
  713. */
  714. typedef struct tagCcFilter *ccFilterDescriptor_t;
  715. /**
  716. * @ingroup dnn
  717. * @brief desciptor of convolution operator
  718. */
  719. typedef struct tagCcConvolution *ccConvolutionDescriptor_t;
  720. /**
  721. * @ingroup dnn
  722. * @brief desciptor of correlation operator
  723. */
  724. typedef struct tagCcConvolution *ccCorrelationDescriptor_t;
  725. typedef struct tagCcFullConnection_t *ccFullConnectionDescriptor_t;
  726. /**
  727. * @ingroup dnn
  728. * @brief desciptor of pooling operator
  729. */
  730. typedef struct tagCcPooling *ccPoolingDescriptor_t;
  731. /**
  732. * @ingroup dnn
  733. * @brief desciptor of activation operator
  734. */
  735. typedef struct tagCcActivation *ccActivationDescriptor_t;
  736. /**
  737. * @ingroup dnn
  738. * @brief desciptor of batchToSpace operator
  739. */
  740. typedef struct tagCcBatchToSpace *ccBatchToSpaceDescriptor_t;
  741. /**
  742. * @ingroup dnn
  743. * @brief desciptor of spaceToBatch operator
  744. */
  745. typedef struct tagCcSpaceToBatch *ccSpaceToBatchDescriptor_t;
  746. /**
  747. * @ingroup dnn
  748. * @brief desciptor of svdf operator
  749. */
  750. typedef struct tagCcSvdf *ccSvdfDescriptor_t;
  751. /**
  752. * @ingroup dnn
  753. * @brief desciptor of crop operator
  754. */
  755. typedef struct tagCcCrop *ccCropDescriptor_t;
  756. /**
  757. * @ingroup dnn
  758. * @brief desciptor of interp operator
  759. */
  760. typedef struct tagCcInterp *ccInterpDescriptor_t;
  761. /**
  762. * @ingroup dnn
  763. * @brief desciptor of GetRegionBox operator
  764. */
  765. typedef struct tagCcGetRegionBox *ccGetRegionBoxDescriptor_t;
  766. /**
  767. * @ingroup dnn
  768. * @brief desciptor of CorrectBoxes operator
  769. */
  770. typedef struct tagCorrectBoxes *ccCorrectBoxesDescriptor_t;
  771. /**
  772. * @ingroup dnn
  773. * @brief desciptor of ClsProb operator
  774. */
  775. typedef struct tagClsProb *ccClsProbDescriptor_t;
  776. /**
  777. * @ingroup dnn
  778. * @brief desciptor of NMS operator
  779. */
  780. typedef struct tagCcNms *ccNmsDescriptor_t;
  781. /**
  782. * @ingroup dnn
  783. * @brief descriptor of MultiClassNms operator
  784. */
  785. typedef struct tagCcMultiClassNms *ccMultiClassNmsDescriptor_t;
  786. /**
  787. * @ingroup dnn
  788. * @brief desciptor of MscnnBoxOutput operator
  789. */
  790. typedef struct tagCcMscnnBoxOutput *ccMscnnBoxOutputDescriptor_t;
  791. /**
  792. * @ingroup dnn
  793. * @brief define of SoftmaxTree
  794. */
  795. typedef void *ccSoftmaxTree_t;
  796. /**
  797. * @ingroup dnn
  798. * @brief descriptor of exp operator
  799. */
  800. typedef struct tagCcExp *ccExpDescriptor_t;
  801. /**
  802. * @ingroup dnn
  803. * @brief descriptor of log operator
  804. */
  805. typedef struct tagCcLog *ccLogDescriptor_t;
  806. /**
  807. * @ingroup dnn
  808. * @brief descriptor of pow operator
  809. */
  810. typedef struct tagCcPow *ccPowDescriptor_t;
  811. /**
  812. * @ingroup dnn
  813. * @brief descriptor of padv2 operator
  814. */
  815. typedef struct tagCcPadV2 *ccPadV2Descriptor_t;
  816. /**
  817. * @ingroup dnn
  818. * @brief desciptor of ShapeClassify operator
  819. */
  820. typedef struct tagCcShapeClassify *ccShapeClassifyDescriptor_t;
  821. /**
  822. * @ingroup dnn
  823. * @brief descriptor of DetectionFull3DOutput operator
  824. */
  825. typedef struct tagCcDetectionFull3DOutput *ccDetectionFull3DOutputDescriptor_t;
  826. /**
  827. * @ingroup dnn
  828. * @brief descriptor of Quantize operator
  829. */
  830. typedef struct tagCcQuantize *ccQuantizeDescriptor_t;
  831. /**
  832. * @ingroup dnn
  833. * @brief descriptor of StridedSlice operator
  834. */
  835. typedef struct tagCcStridedSlice *ccStridedSliceDescriptor_t;
  836. /**
  837. * @ingroup dnn
  838. * @brief descriptor of StridedSliceAttrs operator
  839. */
  840. typedef struct tagCcStridedSliceAttrs *ccStridedSliceAttrsDescriptor_t;
  841. /**
  842. * @ingroup dnn
  843. * @brief descriptor of ResizeBilinear operator
  844. */
  845. typedef struct tagCcResizeBilinear *ccResizeBilinearDescriptor_t;
  846. typedef struct tagCcEltwise *ccEltwiseDescriptor_t;
  847. typedef struct tagCcBatchNorm *ccBatchNormDescriptor_t;
  848. /**
  849. * @ingroup dnn
  850. * @brief descriptor of Square operator
  851. */
  852. typedef struct tagCcSquare *ccSquareDescriptor_t;
  853. /**
  854. * @ingroup dnn
  855. * @brief descriptor of NonMaxSuppression operator
  856. */
  857. typedef struct tagNonMaxSuppression *ccNonMaxSuppressionDescriptor_t;
  858. /**
  859. * @ingroup dnn
  860. * @brief descriptor of NonMaxSuppression operator
  861. */
  862. typedef struct tagUpsamplePara *ccUpsampleParaDescriptor_t;
  863. /**
  864. * @ingroup dnn
  865. * @brief descriptor of ResizeNearestNeighbor operator
  866. */
  867. typedef struct tagCcResizeNearestNeighbor *ccResizeNearestNeighborDescriptor_t;
  868. /**
  869. * @ingroup dnn
  870. * @brief descriptor of Fill operator
  871. */
  872. typedef struct tagCcFillParam *ccFillParamDescriptor_t;
  873. /**
  874. * @ingroup dnn
  875. * @brief descriptor of Argmaxmin operator
  876. */
  877. typedef struct tagCcArgmaxmin *ccArgmaxminDescriptor_t;
  878. }; // namespace cce
  879. #endif // DNN_BASE_HPP__

图引擎模块(GE)是MindSpore的一个子模块,其代码由C++实现,位于前端模块ME和底层硬件之间,起到承接作用。图引擎模块以ME下发的图作为输入,然后进行一系列的深度图优化操作,最后输出一张可以在底层硬件上高效运行的图。GE针对昇腾AI处理器的硬件结构特点,做了特定的优化工作,以此来充分发挥出昇腾AI处理器的强大算力。在进行模型训练/推理时,GE会被自动调用而用户并不感知。GE主要由GE API和GE Core两部分组成,详细的架构图如下所示