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

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