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 26 kB

5 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007
  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. // CC_SQUARE_3, /* cube */
  554. } ccSquareMode_t;
  555. /**
  556. * @ingroup dnn
  557. * @brief append operation type
  558. */
  559. typedef enum tagCcOpType {
  560. CC_OP_TYPE_NO_RELU = 0,
  561. CC_OP_TYPE_RELU = 1,
  562. CC_OP_TYPE_RELU6 = 2,
  563. CC_OP_TYPE_INVALID
  564. } ccOpType_t;
  565. /**
  566. * @ingroup dnn
  567. * @brief struct define of fill operator type.
  568. */
  569. typedef enum tagCcFillOpType {
  570. CC_CONSTANT = 0,
  571. CC_RANGE,
  572. CC_LENGTH_RANGE,
  573. CC_GIVEN_TENSOR,
  574. CC_DIAGONAL,
  575. CC_UNIFORM,
  576. CC_UNIFORM_INT,
  577. CC_UNIQUE_UNIFORM,
  578. CC_GAUSSIAN,
  579. CC_XAVIER,
  580. CC_MSRA,
  581. CC_FILL_OP_TYPE_RESERVED
  582. } ccFillOpType_t;
  583. /**
  584. * @ingroup dnn
  585. * @brief loss function reduction mode
  586. */
  587. typedef enum tagCcLossReduction {
  588. CC_LOSS_REDUCTION_NONE = 0,
  589. CC_LOSS_REDUCTION_SUM,
  590. CC_LOSS_REDUCTION_RESERVED
  591. } ccLossReduction_t;
  592. /**
  593. * @ingroup dnn
  594. * @brief max size of ccIntArray
  595. */
  596. #define CC_INT_ARRAY_MAX_SIZE (8)
  597. /**
  598. * @ingroup dnn
  599. * @brief struct define of int array less than 8.
  600. */
  601. typedef struct tagIntArray {
  602. uint32_t size;
  603. int32_t value[CC_INT_ARRAY_MAX_SIZE];
  604. } ccIntArray_t;
  605. typedef enum tagCcPadMode {
  606. CC_PAD_CONSTANT = 0, /*CONSTANT */
  607. CC_PAD_REFLECT, /*REFLECT */
  608. CC_PAD_SYMMETRIC, /*SYMMETRIC*/
  609. CC_PAD_EDGE, /*EDGE */
  610. CC_PAD_MODE_RESERVED
  611. } ccPadMode_t;
  612. /*
  613. * @ingroup dnn
  614. * @brief pad operation of extractImagePatches
  615. */
  616. typedef enum {
  617. CC_EXTRACT_IMAGE_PATCHES_PAD_VALID = 1,
  618. CC_EXTRACT_IMAGE_PATCHES_PAD_SAME,
  619. CC_EXTRACT_IMAGE_PATCHES_PAD_RESERVED
  620. } ccExtractImagePatchesPadType_t;
  621. /**
  622. * @ingroup dnn
  623. * @brief image dimensions of aipp input
  624. */
  625. #define CC_AIPP_IMG_DIM (2)
  626. /**
  627. * @ingroup dnn
  628. * @brief image channel number of aipp input
  629. */
  630. #define CC_AIPP_IMG_CHN_NUM (4)
  631. /**
  632. * @ingroup dnn
  633. * @brief element number of aipp color space convertion matrix
  634. */
  635. #define CC_AIPP_CSC_MATRIX_DIM (9)
  636. /**
  637. * @ingroup dnn
  638. * @brief element number of aipp color space convertion bias
  639. */
  640. #define CC_AIPP_CSC_BIAS_DIM (3)
  641. /**
  642. * @ingroup dnn
  643. * @brief struct define of AIPP operator
  644. */
  645. typedef struct tagCcAipp {
  646. ccAippInputFormat_t inputFormat;
  647. ccDataType_t outputFormat;
  648. int32_t srcImageSize[CC_AIPP_IMG_DIM];
  649. int32_t loadStartPos[CC_AIPP_IMG_DIM];
  650. int32_t loadSize[CC_AIPP_IMG_DIM];
  651. int32_t scfInputSize[CC_AIPP_IMG_DIM];
  652. int32_t scfOutputSize[CC_AIPP_IMG_DIM];
  653. int32_t cscMatrix[CC_AIPP_CSC_MATRIX_DIM];
  654. int32_t cscOutputBias[CC_AIPP_CSC_BIAS_DIM];
  655. int32_t cscInputBias[CC_AIPP_CSC_BIAS_DIM];
  656. int32_t dtcPixelMean[CC_AIPP_IMG_CHN_NUM];
  657. float dtcPixelMin[CC_AIPP_IMG_CHN_NUM];
  658. float dtcPixelVarReci[CC_AIPP_IMG_CHN_NUM];
  659. ccAippPaddingMode_t paddingMode;
  660. int32_t paddingSize[CC_AIPP_IMG_DIM * 2]; // up,down,left,right
  661. float cpaddingVaule;
  662. bool cscSwitch; // 0:off,1:on
  663. bool scfSwitch; // 0:off,1:on
  664. bool rbuvSwapSwitch;
  665. bool axSwapSwitch;
  666. bool singleLineMode;
  667. bool cscConfigFlag;
  668. bool dtcConfigFlag;
  669. bool padConfigFlag;
  670. bool commConfigFlag;
  671. bool aippEn;
  672. bool dyncAippFlag;
  673. const void *dyncParaAddr;
  674. bool rotationFlag;
  675. } ccConvolutionAipp_t;
  676. typedef struct tagCcQuantizePara {
  677. ccConvolutionScaleValueMode_t scaleValueMode;
  678. uint16_t *scale;
  679. uint16_t *offsetq;
  680. int32_t *offsetw;
  681. uint8_t *allOffsetw;
  682. uint8_t *offsetPad;
  683. } CcQuantizePara_t;
  684. typedef struct tagCcQuantize {
  685. ccQuantizeAlgo_t quantAlgo;
  686. ccConvolutionScaleType_t scaleWType; // show scaleRq,scaleDq type
  687. // The quantization parameter is used when input is FP16.
  688. // scalar
  689. // scaleValueMode=SCALE_NORMAL, = 1/scale_d
  690. // scaleValueMode=SCALE_SQRT, = (1/scale_d)^1/2
  691. CcQuantizePara_t scaleQ;
  692. // The requantized parameter is used when output is int8.
  693. // When scaleWType=SCALE_VEC, the dimension of the vector corresponds to the N dimension of filer; SCALE_SCALAR is
  694. // scalars. scaleValueMode=SCALE_NORMAL, = scale_d*scale_w[n]/scale_d_next*1/DEQSCALE, DEQSCALE=2^-17
  695. // scaleValueMode=SCALE_SQRT, = (scale_d*scale_w[n]/scale_d_next*1/DEQSCALE)^1/2, DEQSCALE=2^-17
  696. CcQuantizePara_t scaleRq;
  697. // The dequantization parameter is used when output is fp16.
  698. // When scaleWType=SCALE_VEC, the dimension of the vector corresponds to the N dimension of filer; SCALE_SCALAR is
  699. // scalars. scaleValueMode=SCALE_NORMAL, = scale_d*scale_w[n]*1/DEQSCALE, DEQSCALE=2^-17 scaleValueMode=SCALE_SQRT, =
  700. // (scale_d*scale_w[n]*1/DEQSCALE)^1/2, DEQSCALE=2^-17
  701. CcQuantizePara_t scaleDq;
  702. // need relu
  703. bool reluFlag;
  704. // relu6
  705. uint16_t *scaleRelu6;
  706. bool bConcat;
  707. } ccQuantize_t;
  708. typedef struct tagCcPad *ccPadDescriptor_t;
  709. /**
  710. * @ingroup dnn
  711. * @brief operation of Cum
  712. */
  713. typedef enum {
  714. CC_CUM_OP_SUM = 0, /**< sum */
  715. CC_CUM_OP_PROD, /**< product */
  716. CC_CUM_OP_INVALID
  717. } CumOpType;
  718. /**
  719. * @ingroup dnn
  720. * @brief desciptor of tensor
  721. */
  722. typedef struct tagCcTensor *ccTensorDescriptor_t;
  723. /**
  724. * @ingroup dnn
  725. * @brief desciptor of filter tensor
  726. */
  727. typedef struct tagCcFilter *ccFilterDescriptor_t;
  728. /**
  729. * @ingroup dnn
  730. * @brief desciptor of convolution operator
  731. */
  732. typedef struct tagCcConvolution *ccConvolutionDescriptor_t;
  733. /**
  734. * @ingroup dnn
  735. * @brief desciptor of correlation operator
  736. */
  737. typedef struct tagCcConvolution *ccCorrelationDescriptor_t;
  738. typedef struct tagCcFullConnection_t *ccFullConnectionDescriptor_t;
  739. /**
  740. * @ingroup dnn
  741. * @brief desciptor of pooling operator
  742. */
  743. typedef struct tagCcPooling *ccPoolingDescriptor_t;
  744. /**
  745. * @ingroup dnn
  746. * @brief desciptor of activation operator
  747. */
  748. typedef struct tagCcActivation *ccActivationDescriptor_t;
  749. /**
  750. * @ingroup dnn
  751. * @brief desciptor of batchToSpace operator
  752. */
  753. typedef struct tagCcBatchToSpace *ccBatchToSpaceDescriptor_t;
  754. /**
  755. * @ingroup dnn
  756. * @brief desciptor of spaceToBatch operator
  757. */
  758. typedef struct tagCcSpaceToBatch *ccSpaceToBatchDescriptor_t;
  759. /**
  760. * @ingroup dnn
  761. * @brief desciptor of svdf operator
  762. */
  763. typedef struct tagCcSvdf *ccSvdfDescriptor_t;
  764. /**
  765. * @ingroup dnn
  766. * @brief desciptor of crop operator
  767. */
  768. typedef struct tagCcCrop *ccCropDescriptor_t;
  769. /**
  770. * @ingroup dnn
  771. * @brief desciptor of interp operator
  772. */
  773. typedef struct tagCcInterp *ccInterpDescriptor_t;
  774. /**
  775. * @ingroup dnn
  776. * @brief desciptor of GetRegionBox operator
  777. */
  778. typedef struct tagCcGetRegionBox *ccGetRegionBoxDescriptor_t;
  779. /**
  780. * @ingroup dnn
  781. * @brief desciptor of CorrectBoxes operator
  782. */
  783. typedef struct tagCorrectBoxes *ccCorrectBoxesDescriptor_t;
  784. /**
  785. * @ingroup dnn
  786. * @brief desciptor of ClsProb operator
  787. */
  788. typedef struct tagClsProb *ccClsProbDescriptor_t;
  789. /**
  790. * @ingroup dnn
  791. * @brief desciptor of NMS operator
  792. */
  793. typedef struct tagCcNms *ccNmsDescriptor_t;
  794. /**
  795. * @ingroup dnn
  796. * @brief descriptor of MultiClassNms operator
  797. */
  798. typedef struct tagCcMultiClassNms *ccMultiClassNmsDescriptor_t;
  799. /**
  800. * @ingroup dnn
  801. * @brief desciptor of MscnnBoxOutput operator
  802. */
  803. typedef struct tagCcMscnnBoxOutput *ccMscnnBoxOutputDescriptor_t;
  804. /**
  805. * @ingroup dnn
  806. * @brief define of SoftmaxTree
  807. */
  808. typedef void *ccSoftmaxTree_t;
  809. /**
  810. * @ingroup dnn
  811. * @brief descriptor of exp operator
  812. */
  813. typedef struct tagCcExp *ccExpDescriptor_t;
  814. /**
  815. * @ingroup dnn
  816. * @brief descriptor of log operator
  817. */
  818. typedef struct tagCcLog *ccLogDescriptor_t;
  819. /**
  820. * @ingroup dnn
  821. * @brief descriptor of pow operator
  822. */
  823. typedef struct tagCcPow *ccPowDescriptor_t;
  824. /**
  825. * @ingroup dnn
  826. * @brief descriptor of padv2 operator
  827. */
  828. typedef struct tagCcPadV2 *ccPadV2Descriptor_t;
  829. /**
  830. * @ingroup dnn
  831. * @brief desciptor of ShapeClassify operator
  832. */
  833. typedef struct tagCcShapeClassify *ccShapeClassifyDescriptor_t;
  834. /**
  835. * @ingroup dnn
  836. * @brief descriptor of DetectionFull3DOutput operator
  837. */
  838. typedef struct tagCcDetectionFull3DOutput *ccDetectionFull3DOutputDescriptor_t;
  839. /**
  840. * @ingroup dnn
  841. * @brief descriptor of Quantize operator
  842. */
  843. typedef struct tagCcQuantize *ccQuantizeDescriptor_t;
  844. /**
  845. * @ingroup dnn
  846. * @brief descriptor of StridedSlice operator
  847. */
  848. typedef struct tagCcStridedSlice *ccStridedSliceDescriptor_t;
  849. /**
  850. * @ingroup dnn
  851. * @brief descriptor of StridedSliceAttrs operator
  852. */
  853. typedef struct tagCcStridedSliceAttrs *ccStridedSliceAttrsDescriptor_t;
  854. /**
  855. * @ingroup dnn
  856. * @brief descriptor of ResizeBilinear operator
  857. */
  858. typedef struct tagCcResizeBilinear *ccResizeBilinearDescriptor_t;
  859. typedef struct tagCcEltwise *ccEltwiseDescriptor_t;
  860. typedef struct tagCcBatchNorm *ccBatchNormDescriptor_t;
  861. /**
  862. * @ingroup dnn
  863. * @brief descriptor of Square operator
  864. */
  865. typedef struct tagCcSquare *ccSquareDescriptor_t;
  866. /**
  867. * @ingroup dnn
  868. * @brief descriptor of NonMaxSuppression operator
  869. */
  870. typedef struct tagNonMaxSuppression *ccNonMaxSuppressionDescriptor_t;
  871. /**
  872. * @ingroup dnn
  873. * @brief descriptor of NonMaxSuppression operator
  874. */
  875. typedef struct tagUpsamplePara *ccUpsampleParaDescriptor_t;
  876. /**
  877. * @ingroup dnn
  878. * @brief descriptor of ResizeNearestNeighbor operator
  879. */
  880. typedef struct tagCcResizeNearestNeighbor *ccResizeNearestNeighborDescriptor_t;
  881. /**
  882. * @ingroup dnn
  883. * @brief descriptor of Fill operator
  884. */
  885. typedef struct tagCcFillParam *ccFillParamDescriptor_t;
  886. /**
  887. * @ingroup dnn
  888. * @brief descriptor of Argmaxmin operator
  889. */
  890. typedef struct tagCcArgmaxmin *ccArgmaxminDescriptor_t;
  891. }; // namespace cce
  892. #endif /* __DNN_BASE_HPP__ */

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