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.

transformation_ops.h 24 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  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 GE_OP_TRANSFORMATION_OPS_H
  17. #define GE_OP_TRANSFORMATION_OPS_H
  18. #include "graph/operator_reg.h"
  19. namespace ge {
  20. /**
  21. *@brief This operation convert output dataType and shape
  22. *@par Inputs:
  23. *The input handle must have the resource type. Inputs include: \n
  24. *@li x:A list of Tensor objects. One or more tensors from which \n
  25. the enqueued tensors should be taken.
  26. *@par Outputs:
  27. *@li y:A list of Tensor objects. One or more tensors from which \n
  28. the enqueued tensors should be taken.
  29. *@par Attributes:
  30. *@li type: An optional ge::DataType. It refers to the target data type of outputs.
  31. *@par Third-party framework compatibility
  32. *Compatible with tensorflow QueueIsClosed operator.
  33. */
  34. REG_OP(Bitcast)
  35. .INPUT(x, TensorType({DT_BOOL, DT_FLOAT16, DT_FLOAT, DT_INT8, DT_INT32, DT_UINT32, DT_UINT8,
  36. DT_INT64, DT_UINT64, DT_INT16, DT_UINT16, DT_DOUBLE, DT_COMPLEX64,
  37. DT_COMPLEX128, DT_QINT8, DT_QUINT8, DT_QINT16, DT_QUINT16, DT_QINT32}))
  38. .OUTPUT(y, TensorType({DT_BOOL, DT_FLOAT16, DT_FLOAT, DT_INT8, DT_INT32, DT_UINT32, DT_UINT8,
  39. DT_INT64, DT_UINT64, DT_INT16, DT_UINT16, DT_DOUBLE, DT_COMPLEX64,
  40. DT_COMPLEX128, DT_QINT8, DT_QUINT8, DT_QINT16, DT_QUINT16, DT_QINT32}))
  41. .REQUIRED_ATTR(type, Type)
  42. .OP_END_FACTORY_REG(Bitcast)
  43. /**
  44. *@brief Convert tensor format from HWCN to C1HWNCoC0.
  45. *@par Inputs:
  46. *x: A Tensor. Must be 4D Tensor of type float16, float32, int32, uint16, with format HWCN.
  47. *@par Outputs:
  48. *y: A 6D Tensor. Has the same type as "x", with format C1HWNCoC0.
  49. */
  50. REG_OP(DepthwiseWeight4DTo6D)
  51. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32, DT_UINT16}))
  52. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32, DT_UINT16}))
  53. .OP_END_FACTORY_REG(DepthwiseWeight4DTo6D)
  54. /**
  55. *@brief Convert tensor format from C1HWNCoC0 to HWCN.
  56. *@par Inputs:
  57. *x: A Tensor. Must be 6D Tensor of type float16, float32, int32, uint16, with format C1HWNCoC0.
  58. *@par Attributes:
  59. *channel_size: An optional int, specifying the channel size of 4D Tensor with format HWCN.
  60. *@par Outputs:
  61. *y: A 4D Tensor. Has the same type as "x", with format HWCN.
  62. */
  63. REG_OP(DepthwiseWeight6DTo4D)
  64. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32, DT_UINT16}))
  65. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32, DT_UINT16}))
  66. .ATTR(channel_size, Int, 16)
  67. .OP_END_FACTORY_REG(DepthwiseWeight6DTo4D)
  68. /**
  69. *@brief Permutes the dimensions according to perm.\n
  70. The returned tensor's dimension i will correspond to the input dimension perm[i].
  71. *@par Inputs:
  72. *x: A Tensor. Must be one of the following types: float16, float32, int8, int16, int32, int64, uint8, uint16, uint32, uint64.
  73. *@par Attributes:
  74. *perm: A permutation of the dimensions of "x".
  75. *@par Outputs:
  76. *y: A Tensor. Has the same type as "x".
  77. */
  78. REG_OP(TransposeD)
  79. .INPUT(x, TensorType({DT_INT8, DT_INT16, DT_INT32, DT_INT64, DT_UINT8,
  80. DT_UINT16, DT_UINT32, DT_UINT64, DT_FLOAT16, DT_FLOAT}))
  81. .OUTPUT(y, TensorType({DT_INT8, DT_INT16, DT_INT32, DT_INT64, DT_UINT8,
  82. DT_UINT16, DT_UINT32, DT_UINT64, DT_FLOAT16, DT_FLOAT}))
  83. .REQUIRED_ATTR(perm, ListInt)
  84. .OP_END_FACTORY_REG(TransposeD)
  85. /**
  86. *@brief Permutes the dimensions according to perm.\n
  87. The returned tensor's dimension i will correspond to the input dimension perm[i].
  88. *@par Inputs:
  89. *Two inputs, including:
  90. *@li x: A Tensor. Must be one of the following types: float16, float32, int8, int16, int32, int64, uint8, uint16, uint32, uint64.
  91. *@li perm: A Tensor of type int32 or int64. A permutation of the dimensions of "x".
  92. *@par Outputs:
  93. *y: A Tensor. Has the same type as "x".
  94. *@par Third-party framework compatibility
  95. *Compatible with the TensorFlow operator Transpose.
  96. */
  97. REG_OP(Transpose)
  98. .INPUT(x, TensorType::BasicType())
  99. .INPUT(perm, TensorType::IndexNumberType())
  100. .OUTPUT(y, TensorType::BasicType())
  101. .OP_END_FACTORY_REG(Transpose)
  102. REG_OP(TransData)
  103. .INPUT(src, TensorType::BasicType())
  104. .OUTPUT(dst, TensorType::BasicType())
  105. .REQUIRED_ATTR(src_format, String)
  106. .REQUIRED_ATTR(dst_format, String)
  107. .OP_END_FACTORY_REG(TransData)
  108. /**
  109. *@brief Permutes the dimensions according to order.\n
  110. The returned tensor's dimension i will correspond to the input dimension order[i].
  111. *@par Inputs:
  112. *x: A Tensor. Must be one of the following types: float16, float32.
  113. *@par Attributes:
  114. *order: A permutation of the dimensions of "x".Type is int32.support any axis transformation.Defaults to "{0}"
  115. *@par Outputs:
  116. *y: A Tensor. Has the same type as "x".
  117. */
  118. REG_OP(Permute)
  119. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  120. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  121. .ATTR(order, ListInt, {0})
  122. .OP_END_FACTORY_REG(Permute)
  123. /**
  124. *@brief Flattens the inputs. Reserves axis 0 and flattens the input tensors
  125. * along axis 1.
  126. *@par Inputs:
  127. *One input: \n
  128. *x: A multi-dimensional Tensor. Must be one of the following types:
  129. * int8, uint8, int16, uint16, int32, uint32, int64,uint64, float16, float32.
  130. *@par Outputs:
  131. *y: A 2D flattened Tensor (Reserves axis 0 and flattens the input tensors
  132. * along axis 1). Must be one of the following data types: int8, uint8, int16,
  133. * uint16, int32, uint32, int64,uint64, float16, float32.
  134. *@par Third-party framework compatibility
  135. * Compatible with TensorFlow operator Flatten.
  136. */
  137. REG_OP(Flatten)
  138. .INPUT(x, TensorType({DT_INT8, DT_INT16, DT_INT32, DT_INT64,
  139. DT_UINT8, DT_UINT16, DT_UINT32, DT_UINT64,
  140. DT_FLOAT, DT_FLOAT16}))
  141. .OUTPUT(y, TensorType({DT_INT8, DT_INT16, DT_INT32, DT_INT64,
  142. DT_UINT8, DT_UINT16, DT_UINT32, DT_UINT64,
  143. DT_FLOAT, DT_FLOAT16}))
  144. .OP_END_FACTORY_REG(Flatten)
  145. /**
  146. *@brief Permutes and crops the input tensor.
  147. *@par Inputs:
  148. * Three inputs, including:
  149. *@li x: A 5D Tensor of type float16 or int8 or uint8, with format NC1HWC0.
  150. *@li block_shape: A 1D list or tuple of int32 or int64.
  151. *@li crops: A 2D list or tuple of int32 or int64. Specifies the amount to
  152. *crop from start and end dimensions after permutation.
  153. *@par Outputs:
  154. *y: A Tensor with format NC1HWC0. Has the same type as input "x".
  155. *@par Third-party framework compatibility
  156. * Compatible with the TensorFlow operator BatchToSpaceND.
  157. */
  158. REG_OP(BatchToSpaceND)
  159. .INPUT(x, TensorType::BasicType())
  160. .INPUT(block_shape, TensorType::IndexNumberType())
  161. .INPUT(crops, TensorType::IndexNumberType())
  162. .OUTPUT(y, TensorType::BasicType())
  163. .OP_END_FACTORY_REG(BatchToSpaceND)
  164. /**
  165. *@brief Permutes and crops the input tensor.
  166. *@par Inputs:
  167. * One input:
  168. *x: A 5D Tensor of type float16 or int8 or uint8, with format NC1HWC0.
  169. *@par Attributes:
  170. *@li block_shape: A required 1D list or tuple of int32 or int64.
  171. *@li crops: A required 2D list or tuple of int32 or int64. Specifies the amount to crop
  172. * from the start and end dimensions after permutation.
  173. *@par Outputs:
  174. *y: A Tensor with format NC1HWC0. Has the same type as input "x".
  175. *@par Third-party framework compatibility
  176. * Compatible with the TensorFlow operator BatchToSpaceND.
  177. */
  178. REG_OP(BatchToSpaceNDD)
  179. .INPUT(x, TensorType::BasicType())
  180. .OUTPUT(y, TensorType::BasicType())
  181. .REQUIRED_ATTR(block_shape, ListInt)
  182. .REQUIRED_ATTR(crops, ListInt)
  183. .OP_END_FACTORY_REG(BatchToSpaceNDD)
  184. /**
  185. *@brief Pads and permutes the input tensor.
  186. *@par Inputs:
  187. * Three inputs, including: \n
  188. *@li x: A 5D Tensor of type float16 or float32, with format NC1HWC0.
  189. *@li block_shape: A 1D list or tuple of int32 or int64.
  190. *@li paddings: A 2D list or tuple of int32 or int64. Specifies the padding for the start and end dimensions after permutation.
  191. *@par Outputs:
  192. *y: A Tensor with format NC1HWC0. Has the same type as input "x".
  193. *@par Third-party framework compatibility
  194. * Compatible with the TensorFlow operator SpaceToBatchND.
  195. */
  196. REG_OP(SpaceToBatchND)
  197. .INPUT(x, TensorType::BasicType())
  198. .INPUT(block_shape, TensorType::IndexNumberType())
  199. .INPUT(paddings, TensorType::IndexNumberType())
  200. .OUTPUT(y, TensorType::BasicType())
  201. .OP_END_FACTORY_REG(SpaceToBatchND)
  202. /**
  203. *@brief Pads and permutes the input tensor.
  204. *@par Inputs:
  205. * One input: \n
  206. *x: A 5D Tensor of type float16 or float32, with format NC1HWC0.
  207. *@par Attributes:
  208. *@li block_shape: A required 1D list or tuple of int32 or int64.
  209. *@li paddings: A required 2D list or tuple of int32 or int64. Specifies the padding for the start and end dimensions after permutation.
  210. *@par Outputs:
  211. *y: A Tensor with format NC1HWC0. Has the same type as input "x".
  212. *@par Third-party framework compatibility
  213. * Compatible with the TensorFlow operator SpaceToBatchND.
  214. */
  215. REG_OP(SpaceToBatchNDD)
  216. .INPUT(x, TensorType::BasicType())
  217. .OUTPUT(y, TensorType::BasicType())
  218. .REQUIRED_ATTR(block_shape, ListInt)
  219. .REQUIRED_ATTR(paddings, ListInt)
  220. .OP_END_FACTORY_REG(SpaceToBatchNDD)
  221. /**
  222. *@brief Outputs a copy of the input tensor where values from the "height" and
  223. * "width" dimensions are moved to the "depth" dimension.
  224. *@par Inputs:
  225. *x: An NHWC Tensor. Must be one of the following types:
  226. * float16, float32, double, int64, int32, uint8, uint16, uint32, uint64, int8,
  227. * int16, complex64, complex128, qint8, quint8, qint16, quint16, qint32.
  228. *@par Attributes:
  229. *@li block_size: A required int, specifying the input block size.
  230. *@li data_format: An optional string, specifying the data format. Defaults to
  231. * "NHWC".
  232. *@par Outputs:
  233. *y: A Tensor. Has the same type as input "x".
  234. *@par Third-party framework compatibility
  235. * Compatible with the TensorFlow operator SpaceToDepth.
  236. */
  237. REG_OP(SpaceToDepth)
  238. .INPUT(x, TensorType::BasicType())
  239. .OUTPUT(y, TensorType::BasicType())
  240. .REQUIRED_ATTR(block_size, Int)
  241. .ATTR(data_format, String, "NHWC")
  242. .OP_END_FACTORY_REG(SpaceToDepth)
  243. /**
  244. *@brief Rearranges data from depth into blocks of spatial data.
  245. *@par Inputs:
  246. *x: A Tensor. Must be one of the following types: float16, float32, double, int32, uint8,
  247. * int16, int8, complex64, int64, qint8, quint8, qint32, qint16, quint16, uint16,
  248. * complex128, uint32, uint64
  249. *@par Attributes:
  250. *Two attributes, including:
  251. * @li block_size: An int >= 2, specifying the size of the spatial block.
  252. * @li data_format: An optional string, specifying the data format. Defaults to "NHWC".
  253. *@par Outputs:
  254. *y: A Tensor of the same type as "x".
  255. *@par Third-party framework compatibility:
  256. * Compatible with TensorFlow operator DepthToSpace.
  257. */
  258. REG_OP(DepthToSpace)
  259. .INPUT(x, TensorType::BasicType())
  260. .OUTPUT(y, TensorType::BasicType())
  261. .REQUIRED_ATTR(block_size, Int)
  262. .ATTR(data_format, String, "NHWC")
  263. .OP_END_FACTORY_REG(DepthToSpace)
  264. /**
  265. *@brief Permutes data into spatial data blocks and then prunes them.
  266. *@par Inputs:
  267. *@li x: A 4D Tensor with format NHWC.
  268. *@li crops: A 1D list or tuple of int32 or int64.
  269. *Must be one of the following types: float16, float32
  270. *@par Attributes:
  271. *block_size: A required int8, int16, int32, or int64. No default value.
  272. *@par Outputs:
  273. *y: A 4D Tensor with format NHWC,
  274. * of type float16 or float32.
  275. *@attention Constraints:
  276. *@li The size of the first dimension of input "x" must be divisible by (block_size * block_size).
  277. *@li "crops" is a 4Dshape [batch, height, width, depth], height = height_pad - crop_top - crop_bottom,
  278. *width = width_pad - crop_left - crop_right.
  279. *@li block_size > 2
  280. *@par Third-party framework compatibility
  281. * Compatible with the TensorFlow operator BatchToSpace.
  282. */
  283. REG_OP(BatchToSpace)
  284. .INPUT(x, TensorType::BasicType())
  285. .INPUT(crops, TensorType::IndexNumberType())
  286. .OUTPUT(y, TensorType::BasicType())
  287. .REQUIRED_ATTR(block_size, Int)
  288. .OP_END_FACTORY_REG(BatchToSpace)
  289. /**
  290. *@brief Rearrange the batch (permutes) data into spatial data blocks, and then crop them.
  291. *@par Inputs:
  292. * One input:
  293. *x: An Tensor of shape [batch*block_size*block_size, height_pad/block_size, width_pad/block_size, depth].
  294. *The batch size of the input tensor must be divisible by (block size * block size).
  295. *Must be one of the following types: float16, float32, double, int64, int32, uint8, uint16, uint32, uint64,
  296. *int8, int16, complex64, complex128, qint8, quint8, qint16, quint16, qint32.
  297. *@par Attributes:
  298. *@li block_size: Must be one of the following types: `int32`, `int64`.
  299. *@li crops: An Tensor. Must be one of the following types: int32, Int64.
  300. *2D tensor with non negative integer of shape [2, 2]. It specifies how many
  301. *elements are clipped from the intermediate result of spatial dimension.
  302. *@par Outputs:
  303. *y: A Tensor. Has the same type and format as input "x".
  304. *@attention Constraints:
  305. *@li The size of the first dimension of input "x" must be divisible by (block_size * block_size).
  306. *@li "crops" is a 2D tensor of non-negative integers with shape (2, 2).
  307. *@li block_size > 2
  308. *@par Third-party framework compatibility
  309. * Compatible with the TensorFlow operator BatchToSpace.
  310. */
  311. REG_OP(BatchToSpaceD)
  312. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT64, DT_INT32, DT_UINT8,
  313. DT_UINT16, DT_UINT32, DT_UINT64, DT_INT8, DT_INT16, DT_COMPLEX64,
  314. DT_COMPLEX128, DT_QINT8, DT_QUINT8, DT_QINT16, DT_QUINT16, DT_QINT32}))
  315. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT64, DT_INT32, DT_UINT8,
  316. DT_UINT16, DT_UINT32, DT_UINT64, DT_INT8, DT_INT16, DT_COMPLEX64,
  317. DT_COMPLEX128, DT_QINT8, DT_QUINT8, DT_QINT16, DT_QUINT16, DT_QINT32}))
  318. .REQUIRED_ATTR(block_size, Int)
  319. .REQUIRED_ATTR(crops, ListInt)
  320. .OP_END_FACTORY_REG(BatchToSpaceD)
  321. /**
  322. *@brief Outputs a copy of the input tensor where values from the "height" and
  323. * "width" dimensions are padded and rearranged to the "batch" dimension.
  324. *@par Inputs:
  325. * Two inputs, including:
  326. *@li x: An NHWC Tensor. Must be one of the following types:
  327. * float16, float32, double, int64, int32, uint8, uint16, uint32, uint64, int8,
  328. * int16, complex64, complex128, qint8, quint8, qint16, quint16, qint32.
  329. *@li paddings: A 2D tensor of type int, specifying the input.
  330. *@par Attributes:
  331. *block_size: A required int, specifying the input block size.
  332. *@par Outputs:
  333. *y: A Tensor. Has the same type as input "x".
  334. *@par Third-party framework compatibility
  335. * Compatible with the TensorFlow operator SpaceToBatch.
  336. */
  337. REG_OP(SpaceToBatch)
  338. .INPUT(x, TensorType::BasicType())
  339. .INPUT(paddings, TensorType::IndexNumberType())
  340. .OUTPUT(y, TensorType::BasicType())
  341. .REQUIRED_ATTR(block_size, Int)
  342. .OP_END_FACTORY_REG(SpaceToBatch)
  343. /**
  344. *@brief Outputs a copy of the input tensor where values from the "height" and "width" dimensions are padded and rearranged to the "batch" dimension.
  345. *@par Inputs:
  346. *x: An NHWC Tensor. Must be one of the following types: float16, float32, double, int64, int32, uint8, uint16, uint32, uint64, int8, int16, complex64, complex128, qint8, quint8, qint16, quint16, qint32.
  347. *@par Attributes:
  348. *@li block_size: A required int, specifying the input block size.
  349. *@li paddings: A 2D tensor. All data types are supported.
  350. *@par Outputs:
  351. *y: A Tensor. Has the same type as input "x".
  352. *@par Third-party framework compatibility
  353. *@ Compatible with the TensorFlow operator SpaceToBatch.
  354. */
  355. REG_OP(SpaceToBatchD)
  356. .INPUT(x, TensorType::BasicType())
  357. .OUTPUT(y, TensorType::BasicType())
  358. .REQUIRED_ATTR(block_size, Int)
  359. .REQUIRED_ATTR(paddings, ListInt)
  360. .OP_END_FACTORY_REG(SpaceToBatchD)
  361. /**
  362. * @brief Unpacks the given dimension of a rank-R Tensor "x" into rank-(R-1)
  363. * tensors.
  364. * @par Inputs:
  365. * x: A rank-R tensor (R > 0) of type BasicType, with format ND or NC1HWC0.
  366. * @par Attributes:
  367. * @li num: A required int, specifying the number of tensors to be unpacked to.
  368. * Defaults to "None".
  369. * @li axis: An optional int, specifying the axis to unpack along. The value range
  370. * is [-R, R).
  371. * @par Outputs:
  372. * y: Dynamic output. The list of Tensor objects unpacked from "x", of type BasicType.
  373. * @attention Constraints:
  374. * @li If "num" is not specified, it is inferred from the shape of "x".
  375. * @li For the ND format, "axis" is in the range [-R, R); For the NC1HWC0 format,
  376. * "axis" must not be 2, 3, -2, or -3.
  377. * @par Third-party framework compatibility
  378. * Compatible with the TensorFlow operator Unpack.
  379. */
  380. REG_OP(Unpack)
  381. .INPUT(x, TensorType::BasicType())
  382. .DYNAMIC_OUTPUT(y, TensorType::BasicType())
  383. .REQUIRED_ATTR(num, Int)
  384. .ATTR(axis, Int, 0)
  385. .OP_END_FACTORY_REG(Unpack)
  386. /**
  387. * @brief Extract "patches" from "images" and stacks them in the "depth"
  388. * dimension of the output.
  389. * @par Inputs:
  390. * x: A 4D Tensor with shape [batch, in_rows, in_cols, depth], Must be one of the
  391. * following types:float32, double, int32, uint8, int16, int8, int64, uint16,
  392. * float16, uint32, uint64
  393. * @par Attributes:
  394. * @li ksizes: A required list or tuple. The size of the sliding window for each
  395. * dimension of images.
  396. * @li strides: A required list or tuple. How far the centers of two consecutive
  397. * patches are in the images. Must be: [1, stride_rows, stride_cols, 1].
  398. * @li rates: A required list or tuple. Must be: [1, rate_rows, rate_cols, 1].\n
  399. * This is the input stride, specifying how far two consecutive patch\n
  400. * samples are in the input. Equivalent to extracting patches
  401. * with patch_sizes_eff = patch_sizes + (patch_sizes - 1) *\n
  402. * (rates - 1), followed by subsampling them spatially by a factor of rates.\n
  403. * This is equivalent to rate in dilated (a.k.a. Atrous) convolutions.
  404. * @li padding: A required string. The type of padding algorithm to use.
  405. * @par Outputs:
  406. * y: A 4D Tensor with shape [batch, out_rows, out_cols, ksize_rows *\n
  407. * ksize_cols * depth] containing image patches with size ksize_rows x ksize_cols\n
  408. * x depth vectorized in the "depth" dimension. Note "out_rows" and "out_cols"\n
  409. * are the dimensions of the output patches.
  410. * @attention Constraints:
  411. * "ksizes", "strides" and "rates" are lists of integers.
  412. * @par Third-party framework compatibility
  413. * Compatible with the TensorFlow operator ExtractImagePatches.
  414. */
  415. REG_OP(ExtractImagePatches)
  416. .INPUT(x, TensorType::RealNumberType())
  417. .OUTPUT(y, TensorType::RealNumberType())
  418. .REQUIRED_ATTR(ksizes, ListInt)
  419. .REQUIRED_ATTR(strides, ListInt)
  420. .REQUIRED_ATTR(rates, ListInt)
  421. .REQUIRED_ATTR(padding, String)
  422. .OP_END_FACTORY_REG(ExtractImagePatches)
  423. /**
  424. * @brief Extract "patches" from "input" and put them in the "depth"
  425. * dimension of the output.
  426. * @par Inputs:
  427. * x: A 5D Tensor with shape [batch, in_planes, in_rows, in_cols, depth].
  428. * @par Attributes:
  429. * @li ksizes: A required list or tuple. The size of the sliding window for each
  430. * dimension of "x".
  431. * @li strides: A required list or tuple. How far the centers of two consecutive
  432. * patches are in "x". Must be: [1, stride_planes, stride_rows, stride_cols, 1].
  433. * @li padding: A required string. The type of padding algorithm to use.
  434. * @par Outputs:
  435. * Output: A 5D Tensor with shape [batch, out_planes, out_rows, out_cols, ksize_planes * \n
  436. * ksize_rows * ksize_cols * depth] containing patches with size (ksize_rows * ksize_cols\n
  437. * * depth) vectorized in the "depth" dimension. Note "out_planes", "out_rows" and "out_cols"\n
  438. * are the dimensions of the output patches.
  439. * @attention Constraints:
  440. * "ksizes" and "strides" are lists of integers.
  441. * @par Third-party framework compatibility
  442. * Compatible with the TensorFlow operator ExtractVolumePatches.
  443. */
  444. REG_OP(ExtractVolumePatches)
  445. .INPUT(x, TensorType::REALNUMBERTYPE())
  446. .OUTPUT(y, TensorType::REALNUMBERTYPE())
  447. .REQUIRED_ATTR(ksizes, ListInt)
  448. .REQUIRED_ATTR(strides, ListInt)
  449. .REQUIRED_ATTR(padding, String)
  450. .OP_END_FACTORY_REG(ExtractVolumePatches)
  451. /**
  452. *@brief Confuse reshape and transpose.
  453. *@par Inputs:
  454. *x: A Tensor. Must be one of the following types: float16, float32, int8, int16, int32, int64, uint8, uint16, uint32, uint64.
  455. *@par Attributes:
  456. *@li perm: A permutation of the dimensions of "x".
  457. *@li shape: The shape of the input.
  458. *@li transpose_first: If True, the transpose is first, otherwise the reshape is first.
  459. *@par Outputs:
  460. *y: A Tensor. Has the same type as "x".
  461. */
  462. REG_OP(ConfusionTransposeD)
  463. .INPUT(x, TensorType({DT_INT8, DT_INT16, DT_INT32, DT_INT64, DT_UINT8,
  464. DT_UINT16, DT_UINT32, DT_UINT64, DT_FLOAT16, DT_FLOAT}))
  465. .OUTPUT(y, TensorType({DT_INT8, DT_INT16, DT_INT32, DT_INT64, DT_UINT8,
  466. DT_UINT16, DT_UINT32, DT_UINT64, DT_FLOAT16, DT_FLOAT}))
  467. .REQUIRED_ATTR(perm, ListInt)
  468. .REQUIRED_ATTR(shape, ListInt)
  469. .REQUIRED_ATTR(transpose_first, Bool)
  470. .OP_END_FACTORY_REG(ConfusionTransposeD)
  471. /**
  472. *@brief Confuse reshape and transpose.
  473. *@par Inputs:
  474. *@li x: A Tensor. Must be one of the following types: float16, float32, int8, int16, int32, int64, uint8, uint16, uint32, uint64.
  475. *@li shape: The shape of the input.
  476. *@par Attributes:
  477. *@li perm: A permutation of the dimensions of "x".
  478. *@li transpose_first: If True, the transpose is first, otherwise the reshape is first.
  479. *@par Outputs:
  480. *y: A Tensor. Has the same type as "x".
  481. */
  482. REG_OP(ConfusionTranspose)
  483. .INPUT(x, TensorType::BasicType())
  484. .INPUT(shape, TensorType::IndexNumberType())
  485. .OUTPUT(y, TensorType::BasicType())
  486. .REQUIRED_ATTR(perm, ListInt)
  487. .REQUIRED_ATTR(transpose_first, Bool)
  488. .OP_END_FACTORY_REG(ConfusionTranspose)
  489. /**
  490. *@brief Flattens the input tensor to one-dimensional.
  491. *@par Inputs:
  492. *x: An ND tensor. All data types are supported.
  493. *@par Attributes:
  494. *@li axis: An optional int32, specifying the first axis to flatten. All preceding axes are retained in the output. Defaults to "1".
  495. *@li end_axis: An optional int32, specifying the last axis to flatten. All following axes are retained in the output. Defaults to "-1".
  496. *@par Outputs:
  497. *y: The flattened ND tensor. All data types are supported.
  498. *@attention Constraints:
  499. * "axis" and "end_axis" must be within the dimension range of the input. This operator cannot be directly called by the acllopExecute API.
  500. *@par Third-party framework compatibility
  501. * Compatible with the Caffe operator Flatten.
  502. */
  503. REG_OP(FlattenV2)
  504. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT8, DT_UINT8, DT_INT16, DT_UINT16,
  505. DT_INT32, DT_UINT32, DT_INT64, DT_UINT64}))
  506. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT8, DT_UINT8, DT_INT16, DT_UINT16,
  507. DT_INT32, DT_UINT32, DT_INT64, DT_UINT64}))
  508. .ATTR(axis, Int, 1)
  509. .ATTR(end_axis, Int, -1)
  510. .OP_END_FACTORY_REG(FlattenV2)
  511. REG_OP(DeConvTrans)
  512. .INPUT(x, TensorType({DT_INT8}))
  513. .OUTPUT(y, TensorType({DT_INT8}))
  514. .OP_END_FACTORY_REG(DeConvTrans)
  515. REG_OP(Compress)
  516. .INPUT(weight, TensorType({DT_INT8, DT_FLOAT16}))
  517. .OUTPUT(weight_compress, TensorType({DT_INT8, DT_FLOAT16}))
  518. .OUTPUT(compress_index, TensorType({DT_INT8}))
  519. .REQUIRED_ATTR(compress_parameters, ListInt)
  520. .OP_END_FACTORY_REG(Compress)
  521. REG_OP(CompressFcOp)
  522. .INPUT(weight, TensorType({DT_INT8}))
  523. .OUTPUT(weight_compress, TensorType({DT_INT8}))
  524. .OUTPUT(compress_index, TensorType({DT_INT8}))
  525. .REQUIRED_ATTR(compress_parameters, ListInt)
  526. .OP_END_FACTORY_REG(CompressFcOp)
  527. } // namespace ge
  528. #endif // GE_OP_TRANSFORMATION_OPS_H

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