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.h 27 kB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  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_H__
  17. #define DNN_BASE_H__
  18. #include "cce/blas_struct.h"
  19. #include "cce/customize.h"
  20. #include "cce/dnn_base_def.hpp"
  21. namespace cce {
  22. /**
  23. * @ingroup dnn
  24. * @brief Minimum epsilon allowed to be used in the Batch Normalization formula
  25. */
  26. #define CC_BN_MIN_EPSILON (1e-7)
  27. #ifndef NULL
  28. #ifdef __cplusplus
  29. #define NULL 0
  30. #else
  31. #define NULL ((void *)0)
  32. #endif
  33. #endif
  34. /**
  35. * @ingroup dnn
  36. * @brief max number of dimensions
  37. */
  38. #define CC_DIM_MAX (8)
  39. typedef struct cCTagL2LossDescriptor * ccL2LossDescriptor_t;
  40. /**
  41. * @ingroup dnn
  42. * @brief mode of concatfive2fout
  43. */
  44. typedef enum tagTransForLossMode {
  45. CC_TRANS_FOR_BOX = 0,
  46. CC_TRANS_FOR_SCORE,
  47. } ccTransForLossMode_t;
  48. /**
  49. * @ingroup dnn
  50. * @brief descriptor of concatfive2fout
  51. */
  52. typedef struct tagCcConcatFive2Four_t *ccConcatFive2FourDescriptor_t;
  53. }; /* end cce */
  54. namespace cce {
  55. /**
  56. * @ingroup dnn
  57. * @brief create descriptor of tensor
  58. * @param [in|out] tensorDesc point to descriptor of tensor
  59. * @return ccStatus_t
  60. */
  61. ccStatus_t ccCreateTensorDescriptor(ccTensorDescriptor_t *tensorDesc);
  62. /**
  63. * @ingroup dnn
  64. * @brief destroy descriptor of tensor
  65. * @param [in] *tensorDesc descriptor of tensor
  66. * @return ccStatus_t
  67. */
  68. ccStatus_t ccDestroyTensorDescriptor(ccTensorDescriptor_t *tensorDesc);
  69. /**
  70. * @ingroup dnn
  71. * @brief init tensor to 4d tensor
  72. * @param [in|out] tensorDesc descriptor of tensor
  73. * @param [in] format format of tensor
  74. * @param [in] dataType data type in device
  75. * @param [in] n batch size
  76. * @param [in] c channels
  77. * @param [in] h height of feature map
  78. * @param [in] w width of feature map
  79. * @return ccStatus_t
  80. */
  81. ccStatus_t ccSetTensor4dDescriptor(ccTensorDescriptor_t tensorDesc,
  82. ccTensorFormat_t format,
  83. ccDataType_t dataType,
  84. int32_t n,
  85. int32_t c,
  86. int32_t h,
  87. int32_t w);
  88. /**
  89. * @ingroup dnn
  90. * @brief read 4d tensor
  91. * @param [in] tensorDesc descriptor of tensor
  92. * @param [in|out] dataType point to data type in device
  93. * @param [in|out] n point to batch size
  94. * @param [in|out] c point to channels
  95. * @param [in|out] h point to height of feature map
  96. * @param [in|out] w point to width of feature map
  97. * @param [in|out] nStride point to stride of n
  98. * @param [in|out] cStride point to stride of c
  99. * @param [in|out] hStride point to stride of h
  100. * @param [in|out] wStride point to stride of w
  101. * @return ccStatus_t
  102. */
  103. ccStatus_t ccGetTensor4dDescriptor(const ccTensorDescriptor_t tensorDesc,
  104. ccDataType_t *dataType,
  105. int32_t *n,
  106. int32_t *c,
  107. int32_t *h,
  108. int32_t *w,
  109. int32_t *nStride,
  110. int32_t *cStride,
  111. int32_t *hStride,
  112. int32_t *wStride);
  113. /**
  114. * @ingroup dnn
  115. * @brief print 4d tensor (just in debug log mode)
  116. * @param [in] tensorDesc descriptor of tensor
  117. * @return ccStatus_t
  118. */
  119. ccStatus_t ccPrintTensor4dDescriptor(const ccTensorDescriptor_t tensorDesc);
  120. /**
  121. * @ingroup dnn
  122. * @brief print Nd tensor (just in debug log mode)
  123. * @param [in] tensorDesc descriptor of tensor
  124. * @return ccStatus_t
  125. */
  126. ccStatus_t ccPrintTensorNdDescriptor(const ccTensorDescriptor_t tensorDesc);
  127. /**
  128. * @ingroup dnn
  129. * @brief init tensor to Nd tensor
  130. * @param [in|out] tensorDesc descriptor of tensor
  131. * @param [in] dataType data type in device
  132. * @param [in] dimCnt Dimension of the tensor
  133. * @param [in] dimA Array of dimension dimCnt that contain the size of the tensor for every dimension. Size along unused dimensions should be set to 1.
  134. * @return ccStatus_t
  135. */
  136. ccStatus_t ccSetTensorNdDescriptor(ccTensorDescriptor_t tensorDesc,
  137. ccDataType_t dataType,
  138. int32_t dimCnt,
  139. int32_t dimA[]);
  140. /**
  141. * @ingroup dnn
  142. * @brief read Nd tensor
  143. * @param [in] tensorDesc descriptor of tensor
  144. * @param [in] dimCntReq point to data type in device
  145. * @param [in|out] dataType point to data type in device
  146. * @param [in|out] dimCnt Dimension of the tensor
  147. * @param [in|out] dimA Array of dimension of at least dimCntReq that will be filled with the dimensions from the provided tensor descriptor.
  148. * @param [in|out] strideA Array of dimension dimCntReq that contain the stride of the tensor for every dimension
  149. * @return ccStatus_t
  150. */
  151. ccStatus_t ccGetTensorNdDescriptor(const ccTensorDescriptor_t tensorDesc,
  152. int32_t dimCntReq,
  153. ccDataType_t *dataType,
  154. int32_t *dimCnt,
  155. int32_t dimA[],
  156. int32_t strideA[]);
  157. /**
  158. * @ingroup dnn
  159. * @brief transform tensor between 4d(NCHW) and 5d(NC1HWC0)
  160. * @param [in] xDesc descriptor of input tensor
  161. * @param [in] x point to input data in host memory
  162. * @param [in] dataTypeTransmode mode of data type transform
  163. * @param [in] yDesc descriptor of output tensor
  164. * @param [in|out] y point to output data in host memory
  165. * @param [in] ySizeInBytes size of outputData
  166. * @return ccStatus_t
  167. */
  168. ccStatus_t ccTransTensor(const ccTensorDescriptor_t xDesc,
  169. const void *x,
  170. const ccTensorDescriptor_t yDesc,
  171. void *y,
  172. uint32_t ySizeInBytes);
  173. /**
  174. * @ingroup dnn
  175. * @brief get the format and dimcnt of Tensor
  176. * @param [in] tensorDesc descriptor of tensor
  177. * @param [in|out] format point to format
  178. * @return ccStatus_t
  179. */
  180. ccStatus_t ccGetTensorFormat(const ccTensorDescriptor_t tensorDesc,
  181. ccTensorFormat_t *format);
  182. /**
  183. * @ingroup dnn
  184. * @brief set the format and dimcnt of Tensor
  185. * @param [in] tensorDesc descriptor of tensor
  186. * @param [in|out] format point to format
  187. * @return ccStatus_t
  188. */
  189. ccStatus_t ccSetTensorFormat(ccTensorDescriptor_t tensorDesc,
  190. ccTensorFormat_t format);
  191. /**
  192. * @ingroup dnn
  193. * @brief get the RealDimCnt of Tensor
  194. * @param [in] tensorDesc descriptor of tensor
  195. * @param [in|out] RealDimCnt point to RealDimCnt
  196. * @return ccStatus_t
  197. */
  198. ccStatus_t ccGetTensorRealDimCnt(const ccTensorDescriptor_t tensorDesc,
  199. int32_t *realDimCnt);
  200. /**
  201. * @ingroup dnn
  202. * @brief set the RealDimCnt of Tensor
  203. * @param [in|out] tensorDesc descriptor of tensor
  204. * @param [in] RealDimCnt RealDimCnt to set
  205. * @return ccStatus_t
  206. */
  207. ccStatus_t ccSetTensorRealDimCnt(ccTensorDescriptor_t tensorDesc,
  208. int32_t realDimCnt);
  209. /**
  210. * @ingroup dnn
  211. * @brief get data size of 4d tensor
  212. * @param [in] tensorDesc descriptor of tensor
  213. * @param [in|out] size point to data size
  214. * @return ccStatus_t
  215. */
  216. ccStatus_t ccGetTensorSizeInBytes(const ccTensorDescriptor_t tensorDesc, uint32_t *size);
  217. /**
  218. * @ingroup dnn
  219. * @brief get data size of 4d tensor which is align to 32B
  220. * @param [in] tensorDesc descriptor of tensor
  221. * @param [in|out] size point to data size
  222. * @return ccStatus_t
  223. */
  224. ccStatus_t ccGetTensorMemorySizeInBytes(const ccTensorDescriptor_t tensorDesc, uint32_t *size);
  225. ccStatus_t ccSetTensorDataSize(ccTensorDescriptor_t xDesc, uint32_t size);
  226. /**
  227. * @ingroup dnn
  228. * @brief get data size of 4d filter
  229. * @param [in] filterDesc descriptor of filter
  230. * @param [in] groupNum number of group
  231. * @param [in|out] size point to data size
  232. * @return ccStatus_t
  233. */
  234. ccStatus_t ccGetFilterSizeInBytes(const ccFilterDescriptor_t filterDesc, uint32_t *size);
  235. /**
  236. * @ingroup dnn
  237. * @brief read 4d filter
  238. * @param [in] filterDesc descriptor of filter
  239. * @param [in|out] format point to format of filter
  240. * @param [in|out] dataType point to data type in device
  241. * @param [in|out] k point to number of output feature maps
  242. * @param [in|out] c point to number of input feature maps
  243. * @param [in|out] h point to height of filter
  244. * @param [in|out] w point to width of filter
  245. * @return ccStatus_t
  246. */
  247. ccStatus_t ccGetFilter4dDescriptor(const ccFilterDescriptor_t filterDesc,
  248. ccTensorFormat_t *format,
  249. ccDataType_t *dataType,
  250. int32_t *k,
  251. int32_t *c,
  252. int32_t *h,
  253. int32_t *w);
  254. ccStatus_t ccTransFilterFracZToNCHW(const ccFilterDescriptor_t wDesc,
  255. const void *w,
  256. ccFilterDescriptor_t yDesc,
  257. void *y,
  258. uint32_t ySizeInBytes);
  259. /**
  260. * @ingroup dnn
  261. * @brief trans weight to fractal format, and trans data type together
  262. * @param [in] wDesc descriptor of input filter
  263. * @param [in] w input data pointer
  264. * @param [in] yDesc descriptor of output filter
  265. * @param [in|out] y output data pointer
  266. * @param [in] ySizeInBytes size of outputData
  267. * @return ccStatus_t
  268. */
  269. ccStatus_t ccTransFilter(const ccFilterDescriptor_t wDesc,
  270. const void *w,
  271. const ccFilterDescriptor_t yDesc,
  272. void *y,
  273. uint32_t ySizeInBytes);
  274. /**
  275. * @ingroup dnn
  276. * @brief trans weight to fractal format, and trans data type together
  277. * @param [in] wDesc descriptor of input filter
  278. * @param [in] w input data pointer
  279. * @param [in] dataTypeTransmode mode of data type transform
  280. * @param [in] yDesc descriptor of output filter
  281. * @param [in|out] y output data pointer
  282. * @param [in] ySizeInBytes size of outputData
  283. * @return ccStatus_t
  284. */
  285. ccStatus_t ccTransFilterInt8(const ccFilterDescriptor_t wDesc,
  286. const void *w,
  287. ccFilterDescriptor_t yDesc,
  288. void *y,
  289. uint32_t ySizeInBytes,
  290. ccDataType_t outputDataType);
  291. /**
  292. * @ingroup dnn
  293. * @brief create descriptor of filter
  294. * @param [in|out] filterDesc point to descriptor of filter
  295. * @return ccStatus_t
  296. */
  297. ccStatus_t ccCreateFilterDescriptor(ccFilterDescriptor_t *filterDesc);
  298. /**
  299. * @ingroup dnn
  300. * @brief destroy descriptor of filter
  301. * @param [in] *filterDesc descriptor of filter
  302. * @return ccStatus_t
  303. */
  304. ccStatus_t ccDestroyFilterDescriptor(ccFilterDescriptor_t *filterDesc);
  305. /**
  306. * @ingroup dnn
  307. * @brief init conv descriptor to 2d conv
  308. * @param [in|out] convDesc descriptor of convolution operator
  309. * @param [in] mode mode of convolution
  310. * @param [in] padMode mode of padding
  311. * @param [in] padHHead zero padding in height head, if padMode is not CC_PADDING_DIRECTASSIGN head and tail is same value
  312. * @param [in] padHTail zero padding in height tail, need set when padMode is CC_PADDING_DIRECTASSIGN.
  313. * @param [in] padWHead zero padding in width head, if padMode is not CC_PADDING_DIRECTASSIGN head and tail is same value
  314. * @param [in] padWTail zero padding in width tail, need set when padMode is CC_PADDING_DIRECTASSIGN
  315. * @param [in] strideH stride in height
  316. * @param [in] strideW stride in width
  317. * @param [in] dilationH dilation in height
  318. * @param [in] dilationW dilation in width
  319. * @return ccStatus_t
  320. */
  321. ccStatus_t ccSetConvolution2dDescriptor(ccConvolutionDescriptor_t convDesc,
  322. ccConvolutionMode_t mode,
  323. ccPaddingMode_t padMode,
  324. int32_t padHHead,
  325. int32_t padHTail,
  326. int32_t padWHead,
  327. int32_t padWTail,
  328. int32_t group,
  329. int32_t strideH,
  330. int32_t strideW,
  331. int32_t dilationH,
  332. int32_t dilationW);
  333. /**
  334. * @ingroup dnn
  335. * @brief read 2d conv
  336. * @param [in] convDesc descriptor of convolution operator
  337. * @param [in|out] mode point to mode of convolution
  338. * @param [in] padMode mode of padding
  339. * @param [in] padHHead zero padding in height head, if padMode is not CC_PADDING_DIRECTASSIGN head and tail is same value
  340. * @param [in] padHTail zero padding in height tail, need set when padMode is CC_PADDING_DIRECTASSIGN.
  341. * @param [in] padWHead zero padding in width head, if padMode is not CC_PADDING_DIRECTASSIGN head and tail is same value
  342. * @param [in] padWTail zero padding in width tail, need set when padMode is CC_PADDING_DIRECTASSIGN
  343. * @param [in|out] strideH point to stride in height
  344. * @param [in|out] strideW point to stride in width
  345. * @param [in|out] dilationH point to dilation in height
  346. * @param [in|out] dilationW point to dilation in width
  347. * @return ccStatus_t
  348. */
  349. ccStatus_t ccGetConvolution2dDescriptor(const ccConvolutionDescriptor_t convDesc,
  350. ccConvolutionMode_t *mode,
  351. ccPaddingMode_t *padMode,
  352. int32_t *padHHead,
  353. int32_t *padHTail,
  354. int32_t *padWHead,
  355. int32_t *padWTail,
  356. int32_t *group,
  357. int32_t *strideH,
  358. int32_t *strideW,
  359. int32_t *dilationH,
  360. int32_t *dilationW);
  361. /**
  362. * @ingroup dnn
  363. * @brief get the output dimension info of 2d convolution
  364. * @param [in] convDesc descriptor of convolution operator
  365. * @param [in] xDesc descriptor of input tensor
  366. * @param [in] wDesc descriptor of filter
  367. * @param [in|out] n point to batch size
  368. * @param [in|out] c point to channels
  369. * @param [in|out] h point to height of feature map
  370. * @param [in|out] w point to width of feature map
  371. * @return ccStatus_t
  372. */
  373. ccStatus_t ccGetConvolution2dForwardOutputDim(const ccConvolutionDescriptor_t convDesc,
  374. const ccTensorDescriptor_t xDesc,
  375. const ccFilterDescriptor_t wDesc,
  376. int32_t *n,
  377. int32_t *c,
  378. int32_t *h,
  379. int32_t *w);
  380. /**
  381. * @ingroup dnn
  382. * @brief create descriptor of convolution operator
  383. * @param [in|out] filterDesc point to descriptor of convolution operator
  384. * @return ccStatus_t
  385. */
  386. ccStatus_t ccCreateConvolutionDescriptor(ccConvolutionDescriptor_t *convDesc);
  387. /**
  388. * @ingroup dnn
  389. * @brief destroy descriptor of convolution operator
  390. * @param [in] *convDesc descriptor of convolution operator
  391. * @return ccStatus_t
  392. */
  393. ccStatus_t ccDestroyConvolutionDescriptor(ccConvolutionDescriptor_t *convDesc);
  394. /**
  395. * @ingroup dnn
  396. * @brief check specific stride condition flag
  397. * @param [in] deconvDesc descriptor of Deconvolution operator
  398. * @param [in] xDesc descriptor of input tensor
  399. * @param [in] yDesc descriptor of output tensor
  400. * @param [in] biasDesc descriptor of bias tensor
  401. * @param [in] wDesc descriptor of filter
  402. * @param [in|out] transMark output condition flag
  403. * @return ccStatus_t
  404. */
  405. ccStatus_t ccDeconvSpStrideCondCheck(const ccConvolutionDescriptor_t deconvDesc,
  406. const ccTensorDescriptor_t xDesc,
  407. const ccTensorDescriptor_t yDesc,
  408. const ccTensorDescriptor_t biasDesc,
  409. const ccFilterDescriptor_t wDesc,
  410. uint32_t &transMark);
  411. /**
  412. * @ingroup dnn
  413. * @brief special deconv stride trans
  414. * @param [in] deconvDesc descriptor of Deconvolution operator
  415. * @param [in] xDesc descriptor of input tensor
  416. * @param [in] yDesc descriptor of output tensor
  417. * @param [in] biasDesc descriptor of bias tensor
  418. * @param [in] deconvStPtr descriptor of filter
  419. * @param [in|out] xStPtr descriptor of trans input tensor
  420. * @param [in|out] yStPtr descriptor of trans output tensor
  421. * @param [in|out] wStPtr descriptor of trans filter tensor
  422. * @param [in|out] wDesc descriptor of trasn filter
  423. * @param [in|out] transMark condition flag
  424. * @return ccStatus_t
  425. */
  426. ccStatus_t ccDeconvSpStrideDescTrans(const ccConvolutionDescriptor_t deconvDesc,
  427. const ccTensorDescriptor_t xDesc,
  428. const ccTensorDescriptor_t yDesc,
  429. const ccTensorDescriptor_t biasDesc __attribute__((__unused__)),
  430. const ccFilterDescriptor_t wDesc,
  431. ccConvolutionDescriptor_t deconvStPtr,
  432. ccTensorDescriptor_t xStPtr,
  433. ccTensorDescriptor_t yStPtr,
  434. ccFilterDescriptor_t wStPtr,
  435. uint32_t transMark);
  436. /**
  437. * @ingroup dnn
  438. * @brief check deconv goto aicore flag
  439. * @param [in] deconvDesc descriptor of Deconvolution operator
  440. * @param [in] xDesc descriptor of input tensor
  441. * @param [in] yDesc descriptor of output tensor
  442. * @param [in] wDesc descriptor of filter
  443. * @param [in] isGotoAicore out flag
  444. * @param [in] transMark condition flag
  445. * @return ccStatus_t
  446. */
  447. ccStatus_t ccDeconvCheckGotoAiCore(const ccConvolutionDescriptor_t deconvDesc,
  448. const ccTensorDescriptor_t xDesc,
  449. const ccTensorDescriptor_t yDesc,
  450. const ccFilterDescriptor_t wDesc,
  451. uint32_t *isGotoAicore,
  452. uint32_t transMark);
  453. /**
  454. * @ingroup dnn
  455. * @brief get the output dimension info of 2d Deconvolution
  456. * @param [in] deconvDesc descriptor of Deconvolution operator
  457. * @param [in] xDesc descriptor of input tensor
  458. * @param [in] wDesc descriptor of filter
  459. * @param [in|out] n point to batch size
  460. * @param [in|out] c point to channels
  461. * @param [in|out] h point to height of feature map
  462. * @param [in|out] w point to width of feature map
  463. * @return ccStatus_t
  464. */
  465. ccStatus_t ccGetDeconvolution2dForwardOutputDim(const ccConvolutionDescriptor_t deconvDesc,
  466. const ccTensorDescriptor_t xDesc,
  467. const ccFilterDescriptor_t wDesc,
  468. int32_t *n,
  469. int32_t *c,
  470. int32_t *h,
  471. int32_t *w);
  472. /**
  473. * @ingroup dnn
  474. * @brief create descriptor of PAD
  475. * @param [in|out] padDesc point to descriptor of pad
  476. * @return ccStatus_t
  477. */
  478. ccStatus_t ccCreatePadDescriptor(ccPadDescriptor_t *padDesc);
  479. /**
  480. * @ingroup dnn
  481. * @brief destroy descriptor of PAD
  482. * @param [in] *padDesc descriptor of PAD
  483. * @return ccStatus_t
  484. */
  485. ccStatus_t ccDestroyPadDescriptor(ccPadDescriptor_t *padDesc);
  486. /**
  487. * @ingroup dnn
  488. * @brief set PADDesc
  489. * @param [in|out] padDesc descriptor of PAD
  490. * @param [in] padMode mode of PAD
  491. * @param [in] padValue pad value of PAD
  492. * @param [in] wleft width left pad of PAD
  493. * @param [in] wright width right of PAD
  494. * @param [in] htop higth pad of PAD
  495. * @param [in] hbottom higth bottom pad of PAD
  496. * @return ccStatus_t
  497. */
  498. ccStatus_t ccSetPadDescriptor(ccPadDescriptor_t padDesc,
  499. ccPadMode_t padMode,
  500. float padValue,
  501. int32_t htop,
  502. int32_t hbottom,
  503. int32_t wleft,
  504. int32_t wright);
  505. /**
  506. * @ingroup dnn
  507. * @brief read 2d pooling
  508. * @param [in] poolingDesc descriptor of pooling operator
  509. * @param [in|out] mode point to mode of pooling
  510. * @param [in|out] maxpoolingNanOpt point to Nan propagation mode
  511. * @param [in|out] windowH point to height of pooling window
  512. * @param [in|out] windowW point to width of pooling window
  513. * @param [in|out] padHHead point to zero padding in height head, if padMode is not CC_PADDING_DIRECTASSIGN head and tail is same value.
  514. * @param [in|out] padHTail point to zero padding in height tail, need set when padMode is CC_PADDING_DIRECTASSIGN.
  515. * @param [in|out] padWHead point to zero padding in width head, if padMode is not CC_PADDING_DIRECTASSIGN head and tail is same value.
  516. * @param [in|out] padWTail point to zero padding in width tail, need set when padMode is CC_PADDING_DIRECTASSIGN.
  517. * @param [in|out] strideH point to stride in height
  518. * @param [in|out] strideW point to stride in width
  519. * @param [in|out] dataMode
  520. * @param [in|out] ceilMode 0:Ceil 1:Floor
  521. * @return ccStatus_t
  522. */
  523. ccStatus_t ccGetPooling2dDescriptor(const ccPoolingDescriptor_t poolingDesc,
  524. ccPoolingMode_t *mode,
  525. ccPaddingMode_t *padMode,
  526. ccNanPropagation_t *maxpoolingNanOpt,
  527. int32_t *windowH,
  528. int32_t *windowW,
  529. int32_t *padHHead,
  530. int32_t *padHTail,
  531. int32_t *padWHead,
  532. int32_t *padWTail,
  533. int32_t *strideH,
  534. int32_t *strideW,
  535. int32_t *dataMode,
  536. int32_t *ceilMode,
  537. ccPooingFwdAlgo_t *algo);
  538. ccStatus_t ccGetCompare5dOutputDim(const ccTensorDescriptor_t xDesc,
  539. const ccTensorDescriptor_t yDesc,
  540. int32_t* dimCnt,
  541. int32_t* dim,
  542. int32_t dimLen);
  543. ccStatus_t ccGetMaximum5dOutputDim(const ccTensorDescriptor_t xDesc,
  544. const ccTensorDescriptor_t yDesc,
  545. int32_t* dimCnt,
  546. int32_t* dim,
  547. int32_t dimLen);
  548. ccStatus_t ccGetMinimum5dOutputDim(const ccTensorDescriptor_t xDesc,
  549. const ccTensorDescriptor_t yDesc,
  550. int32_t* dimCnt,
  551. int32_t* dim,
  552. int32_t dimLen);
  553. ccStatus_t ccGetReduce5dOutputDim(const ccTensorDescriptor_t xDesc,
  554. const ccIntArray_t* axis,
  555. bool keepDims,
  556. int32_t *dimCnt,
  557. int32_t dim[],
  558. int32_t dimLen);
  559. /**
  560. * @brief get out put descrition of slice tensor.
  561. * @param [in] xDesc descriptor of input data
  562. * @param [in] begin begin position of tensor
  563. * @param [in] size size to slice
  564. * @param [in|out] dimCnt point to the output dimCnt
  565. * @param [in|out] dim arrays to save dims
  566. * @param [in| dimlen length of dim
  567. * @return ccStatus_t
  568. */
  569. ccStatus_t ccGetSliceOutputDim(
  570. const ccTensorDescriptor_t xDesc,
  571. const ccIntArray_t* begin,
  572. const ccIntArray_t* size,
  573. int32_t *dimCnt,
  574. int32_t dim[],
  575. int32_t dimLen);
  576. /**
  577. * @ingroup dnn
  578. * @brief get strided slice output dim info.
  579. * @param [in] xDesc descriptor of input tensor
  580. * @param [in] stridedSliceDesc specifies the begin, end, strides of slice
  581. * @param [in] attrDesc reserve for optional attributes.
  582. * @param [in|out] dimCnt point to the output dimCnt
  583. * @param [in|out] dim arrays to save dims
  584. * @param [in| dimlen length of dim
  585. * @return ccStatus_t
  586. */
  587. ccStatus_t ccGetStridedSliceOutputDim(const ccTensorDescriptor_t xDesc,
  588. const ccStridedSliceDescriptor_t stridedSliceDesc,
  589. const ccStridedSliceAttrsDescriptor_t attrDesc,
  590. int32_t *dimCnt, int32_t dim[], int32_t dimLen);
  591. /**
  592. * @ingroup dnn
  593. * @brief get workspace size for softmax computation
  594. * @param [in] handle cce handle
  595. * @param [in] xDesc descriptor of input tensor
  596. * @param [in] yDesc descriptor of output tensor
  597. * @param [in|out] sizeInBytes workSpace size in bytes
  598. * @return ccStatus_t
  599. */
  600. ccStatus_t ccGetSoftmaxForwardWorkspaceSize(ccHandle_t handle,
  601. const ccTensorDescriptor_t xDesc,
  602. const ccTensorDescriptor_t yDesc,
  603. uint32_t *sizeInBytes);
  604. /**
  605. * @ingroup dnn
  606. * @brief set quantize algorithm type and quantize scale type (vector or scalar)
  607. * @param [in] quantizeInfo descriptor of quantize parameters
  608. * @param [in] quantAlgo enum type for quantize algorithm type
  609. * @param [in] scaleType enum type for quantize scale type
  610. * @param [in] reluflag flag for relu
  611. * @return ccStatus_t
  612. */
  613. ccStatus_t ccSetQuantizeAlgoAndScaleType(ccQuantizeDescriptor_t quantizeInfo, ccQuantizeAlgo_t quantAlgo, ccScaleType_t scaleType);
  614. ccStatus_t ccSetQuantizeAlgoAndScaleType(ccQuantizeDescriptor_t quantizeInfo, ccQuantizeAlgo_t quantAlgo, ccScaleType_t scaleType, bool reluFlag);
  615. }; /* end cce */
  616. #endif // DNN_BASE_H__

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