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

5 years ago
4 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
4 years ago
4 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
4 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
4 years ago
4 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
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783
  1. /**
  2. * Copyright 2019 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 OPS_BUILT_IN_OP_PROTO_INC_TRANSFORMATION_OPS_H_
  21. #define OPS_BUILT_IN_OP_PROTO_INC_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.
  118. *@li group: A optional int32, default value is 1. \n
  119. *@par Outputs:
  120. *dst: A Tensor dtype of all types.
  121. */
  122. REG_OP(TransData)
  123. .INPUT(src, TensorType::BasicType())
  124. .OUTPUT(dst, TensorType::BasicType())
  125. .REQUIRED_ATTR(src_format, String)
  126. .REQUIRED_ATTR(dst_format, String)
  127. .ATTR(groups, Int, 1)
  128. .OP_END_FACTORY_REG(TransData)
  129. /**
  130. *@brief Permutes the dimensions according to order.
  131. The returned tensor's dimension i will correspond to the input dimension order[i] . \n
  132. *@par Inputs:
  133. *x: A Tensor. Must be one of the following types: float16, float32 . \n
  134. *@par Attributes:
  135. *order: A permutation of the dimensions of "x".Type is int32.support any axis transformation.Defaults to "{0}"
  136. *@par Outputs:
  137. *y: A Tensor. Has the same type as "x".
  138. */
  139. REG_OP(Permute)
  140. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  141. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  142. .ATTR(order, ListInt, {0})
  143. .OP_END_FACTORY_REG(Permute)
  144. /**
  145. *@brief Flattens the inputs. Reserves axis 0 and flattens the input tensors
  146. * along axis 1 . \n
  147. *@par Inputs:
  148. *One input:
  149. *x: A multi-dimensional Tensor. Must be one of the following types:
  150. * int8, uint8, int16, uint16, int32, uint32, int64,uint64, float16, float32 . \n
  151. *@par Outputs:
  152. *y: A 2D flattened Tensor (Reserves axis 0 and flattens the input tensors
  153. * along axis 1). Must be one of the following data types: int8, uint8, int16,
  154. * uint16, int32, uint32, int64,uint64, float16, float32 . \n
  155. *@par Third-party framework compatibility
  156. * Compatible with TensorFlow operator Flatten.
  157. */
  158. REG_OP(Flatten)
  159. .INPUT(x, TensorType({DT_INT8, DT_INT16, DT_INT32, DT_INT64,
  160. DT_UINT8, DT_UINT16, DT_UINT32, DT_UINT64,
  161. DT_FLOAT, DT_FLOAT16}))
  162. .OUTPUT(y, TensorType({DT_INT8, DT_INT16, DT_INT32, DT_INT64,
  163. DT_UINT8, DT_UINT16, DT_UINT32, DT_UINT64,
  164. DT_FLOAT, DT_FLOAT16}))
  165. .OP_END_FACTORY_REG(Flatten)
  166. /**
  167. *@brief Permutes and crops the input tensor . \n
  168. *@par Inputs:
  169. * Three inputs, including:
  170. *@li x: A 5D Tensor of type float16 or int8 or uint8, with format NC1HWC0.
  171. *@li block_shape: A 1D list or tuple of int32 or int64.
  172. *@li crops: A 2D list or tuple of int32 or int64. Specifies the amount to
  173. *crop from start and end dimensions after permutation . \n
  174. *@par Outputs:
  175. *y: A Tensor with format NC1HWC0. Has the same type as input "x" . \n
  176. *@par Third-party framework compatibility
  177. * Compatible with the TensorFlow operator BatchToSpaceND.
  178. */
  179. REG_OP(BatchToSpaceND)
  180. .INPUT(x, TensorType::BasicType())
  181. .INPUT(block_shape, TensorType::IndexNumberType())
  182. .INPUT(crops, TensorType::IndexNumberType())
  183. .OUTPUT(y, TensorType::BasicType())
  184. .OP_END_FACTORY_REG(BatchToSpaceND)
  185. /**
  186. *@brief Permutes and crops the input tensor . \n
  187. *@par Inputs:
  188. * One input:
  189. *x: A 5D Tensor of type float16 or int8 or uint8, with format NC1HWC0 . \n
  190. *@par Attributes:
  191. *@li block_shape: A required 1D list or tuple of int32 or int64.
  192. *@li crops: A required 2D list or tuple of int32 or int64. Specifies the amount to crop
  193. * from the start and end dimensions after permutation . \n
  194. *@par Outputs:
  195. *y: A Tensor with format NC1HWC0. Has the same type as input "x".
  196. *@par Third-party framework compatibility
  197. * Compatible with the TensorFlow operator BatchToSpaceND.
  198. *
  199. * @par Restrictions:
  200. * Warning: THIS FUNCTION IS DEPRECATED. Please use BatchToSpaceND instead.
  201. */
  202. REG_OP(BatchToSpaceNDD)
  203. .INPUT(x, TensorType::BasicType())
  204. .OUTPUT(y, TensorType::BasicType())
  205. .REQUIRED_ATTR(block_shape, ListInt)
  206. .REQUIRED_ATTR(crops, ListInt)
  207. .OP_END_FACTORY_REG(BatchToSpaceNDD)
  208. /**
  209. *@brief Pads and permutes the input tensor . \n
  210. *@par Inputs:
  211. * Three inputs, including:
  212. *@li x: A 5D Tensor of type float16 or float32, with format NC1HWC0.
  213. *@li block_shape: A 1D list or tuple of int32 or int64.
  214. *@li paddings: A 2D list or tuple of int32 or int64. Specifies the padding for the start and end dimensions after permutation . \n
  215. *@par Outputs:
  216. *y: A Tensor with format NC1HWC0. Has the same type as input "x" . \n
  217. *@par Third-party framework compatibility
  218. * Compatible with the TensorFlow operator SpaceToBatchND.
  219. */
  220. REG_OP(SpaceToBatchND)
  221. .INPUT(x, TensorType::BasicType())
  222. .INPUT(block_shape, TensorType::IndexNumberType())
  223. .INPUT(paddings, TensorType::IndexNumberType())
  224. .OUTPUT(y, TensorType::BasicType())
  225. .OP_END_FACTORY_REG(SpaceToBatchND)
  226. /**
  227. *@brief Pads and permutes the input tensor . \n
  228. *@par Inputs:
  229. * One input:
  230. *x: A 5D Tensor of type float16 or float32, with format NC1HWC0 . \n
  231. *@par Attributes:
  232. *@li block_shape: A required 1D list or tuple of int32 or int64.
  233. *@li paddings: A required 2D list or tuple of int32 or int64. Specifies the padding for the start and end dimensions after permutation . \n
  234. *@par Outputs:
  235. *y: A Tensor with format NC1HWC0. Has the same type as input "x" . \n
  236. *@par Third-party framework compatibility
  237. * Compatible with the TensorFlow operator SpaceToBatchND.
  238. *
  239. * @par Restrictions:
  240. * Warning: THIS FUNCTION IS DEPRECATED. Please use SpaceToBatchND instead.
  241. */
  242. REG_OP(SpaceToBatchNDD)
  243. .INPUT(x, TensorType::BasicType())
  244. .OUTPUT(y, TensorType::BasicType())
  245. .REQUIRED_ATTR(block_shape, ListInt)
  246. .REQUIRED_ATTR(paddings, ListInt)
  247. .OP_END_FACTORY_REG(SpaceToBatchNDD)
  248. /**
  249. *@brief Outputs a copy of the input tensor where values from the "height" and
  250. * "width" dimensions are moved to the "depth" dimension . \n
  251. *@par Inputs:
  252. *x: An NHWC Tensor. Must be one of the following types:
  253. * float16, float32, double, int64, int32, uint8, uint16, uint32, uint64, int8,
  254. * int16, complex64, complex128, qint8, quint8, qint16, quint16, qint32.
  255. *@par Attributes:
  256. *@li block_size: A required int, specifying the input block size.
  257. *@li data_format: An optional string, specifying the data format. Defaults to
  258. * "NHWC" . \n
  259. *@par Outputs:
  260. *y: A Tensor. Has the same type as input "x".
  261. *@par Third-party framework compatibility
  262. * Compatible with the TensorFlow operator SpaceToDepth.
  263. */
  264. REG_OP(SpaceToDepth)
  265. .INPUT(x, TensorType::BasicType())
  266. .OUTPUT(y, TensorType::BasicType())
  267. .REQUIRED_ATTR(block_size, Int)
  268. .ATTR(data_format, String, "NHWC")
  269. .OP_END_FACTORY_REG(SpaceToDepth)
  270. /**
  271. *@brief Rearranges data from depth into blocks of spatial data . \n
  272. *@par Inputs:
  273. *x: A Tensor. Must be one of the following types: float16, float32, double, int32, uint8,
  274. * int16, int8, complex64, int64, qint8, quint8, qint32, qint16, quint16, uint16,
  275. * complex128, uint32, uint64
  276. *@par Attributes:
  277. *Two attributes, including:
  278. * @li block_size: An int >= 2, specifying the size of the spatial block.
  279. * @li data_format: An optional string, specifying the data format. Defaults to "NHWC" . \n
  280. *@par Outputs:
  281. *y: A Tensor of the same type as "x" . \n
  282. *@par Third-party framework compatibility:
  283. * Compatible with TensorFlow operator DepthToSpace.
  284. */
  285. REG_OP(DepthToSpace)
  286. .INPUT(x, TensorType::BasicType())
  287. .OUTPUT(y, TensorType::BasicType())
  288. .REQUIRED_ATTR(block_size, Int)
  289. .ATTR(data_format, String, "NHWC")
  290. .OP_END_FACTORY_REG(DepthToSpace)
  291. /**
  292. *@brief Permutes data into spatial data blocks and then prunes them . \n
  293. *@par Inputs:
  294. *@li x: A 4D Tensor with format. Must set the format, supported format list ["NCHW, NHWC"]
  295. *@li crops: A 1D list or tuple of int32 or int64 . \n
  296. *Must be one of the following types: float16, float32
  297. *@par Attributes:
  298. *block_size: A required int8, int16, int32, or int64. No default value . \n
  299. *@par Outputs:
  300. *y: A 4D Tensor with format NHWC,
  301. * of type float16 or float32 . \n
  302. *@attention Constraints:
  303. *@li The size of the first dimension of input "x" must be divisible by (block_size * block_size).
  304. *@li "crops" is a 4Dshape [batch, height, width, depth], height = height_pad - crop_top - crop_bottom,
  305. *width = width_pad - crop_left - crop_right.
  306. *@li block_size > 2
  307. *@par Third-party framework compatibility
  308. * Compatible with the TensorFlow operator BatchToSpace.
  309. */
  310. REG_OP(BatchToSpace)
  311. .INPUT(x, TensorType::BasicType())
  312. .INPUT(crops, TensorType::IndexNumberType())
  313. .OUTPUT(y, TensorType::BasicType())
  314. .REQUIRED_ATTR(block_size, Int)
  315. .OP_END_FACTORY_REG(BatchToSpace)
  316. /**
  317. *@brief Rearrange the batch (permutes) data into spatial data blocks, and then crop them . \n
  318. *@par Inputs:
  319. * One input:
  320. *x: An Tensor of shape [batch*block_size*block_size, height_pad/block_size, width_pad/block_size, depth].
  321. *The batch size of the input tensor must be divisible by (block size * block size).
  322. *Must be one of the following types: float16, float32, double, int64, int32, uint8, uint16, uint32, uint64,
  323. *int8, int16, complex64, complex128, qint8, quint8, qint16, quint16, qint32 . \n
  324. *@par Attributes:
  325. *@li block_size: Must be one of the following types: `int32`, `int64`.
  326. *@li crops: An Tensor. Must be one of the following types: int32, Int64.
  327. *2D tensor with non negative integer of shape [2, 2]. It specifies how many
  328. *elements are clipped from the intermediate result of spatial dimension . \n
  329. *@par Outputs:
  330. *y: A Tensor. Has the same type and format as input "x" . \n
  331. *@attention Constraints:
  332. *@li The size of the first dimension of input "x" must be divisible by (block_size * block_size).
  333. *@li "crops" is a 2D tensor of non-negative integers with shape (2, 2).
  334. *@li block_size > 2
  335. *@par Third-party framework compatibility
  336. * Compatible with the TensorFlow operator BatchToSpace.
  337. *
  338. * @par Restrictions:
  339. * Warning: THIS FUNCTION IS DEPRECATED. Please use BatchToSpace instead.
  340. */
  341. REG_OP(BatchToSpaceD)
  342. .INPUT(x, TensorType::BasicType())
  343. .OUTPUT(y, TensorType::BasicType())
  344. .REQUIRED_ATTR(block_size, Int)
  345. .REQUIRED_ATTR(crops, ListInt)
  346. .OP_END_FACTORY_REG(BatchToSpaceD)
  347. /**
  348. *@brief Outputs a copy of the input tensor where values from the "height" and
  349. * "width" dimensions are padded and rearranged to the "batch" dimension . \n
  350. *@par Inputs:
  351. * Two inputs, including:
  352. *@li x: An 4D Tensor. Must be one of the following types:
  353. * float16, float32, double, int64, int32, uint8, uint16, uint32, uint64, int8,
  354. * int16, complex64, complex128, qint8, quint8, qint16, quint16, qint32.
  355. * Must set the format, supported format list ["NCHW, NHWC"]
  356. *@li paddings: A 2D tensor of type int, specifying the input . \n
  357. *@par Attributes:
  358. *block_size: A required int, specifying the input block size . \n
  359. *@par Outputs:
  360. *y: A Tensor. Has the same type as input "x".
  361. *@par Third-party framework compatibility
  362. * Compatible with the TensorFlow operator SpaceToBatch.
  363. */
  364. REG_OP(SpaceToBatch)
  365. .INPUT(x, TensorType::BasicType())
  366. .INPUT(paddings, TensorType::IndexNumberType())
  367. .OUTPUT(y, TensorType::BasicType())
  368. .REQUIRED_ATTR(block_size, Int)
  369. .OP_END_FACTORY_REG(SpaceToBatch)
  370. /**
  371. *@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
  372. *@par Inputs:
  373. *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.
  374. *@par Attributes:
  375. *@li block_size: A required int, specifying the input block size.
  376. *@li paddings: A 2D tensor. All data types are supported . \n
  377. *@par Outputs:
  378. *y: A Tensor. Has the same type as input "x".
  379. *@par Third-party framework compatibility
  380. *@ Compatible with the TensorFlow operator SpaceToBatch.
  381. *
  382. * @par Restrictions:
  383. * Warning: THIS FUNCTION IS DEPRECATED. Please use SpaceToBatch instead.
  384. */
  385. REG_OP(SpaceToBatchD)
  386. .INPUT(x, TensorType::BasicType())
  387. .OUTPUT(y, TensorType::BasicType())
  388. .REQUIRED_ATTR(block_size, Int)
  389. .REQUIRED_ATTR(paddings, ListInt)
  390. .OP_END_FACTORY_REG(SpaceToBatchD)
  391. /**
  392. * @brief Unpacks the given dimension of a rank-R Tensor "x" into rank-(R-1)
  393. * tensors . \n
  394. * @par Inputs:
  395. * x: A rank-R tensor (R > 0) of type BasicType, with format ND or NC1HWC0 . \n
  396. * @par Attributes:
  397. * @li num: A required int, specifying the number of tensors to be unpacked to.
  398. * Defaults to "None".
  399. * @li axis: An optional int, specifying the axis to unpack along. The value range
  400. * is [-R, R) . \n
  401. * @par Outputs:
  402. * y: Dynamic output. The list of Tensor objects unpacked from "x", of type BasicType . \n
  403. * @attention Constraints:
  404. * @li If "num" is not specified, it is inferred from the shape of "x".
  405. * @li For the ND format, "axis" is in the range [-R, R); For the NC1HWC0 format,
  406. * "axis" must not be 2, 3, -2, or -3 . \n
  407. * @par Third-party framework compatibility
  408. * Compatible with the TensorFlow operator Unpack.
  409. */
  410. REG_OP(Unpack)
  411. .INPUT(x, TensorType::BasicType())
  412. .DYNAMIC_OUTPUT(y, TensorType::BasicType())
  413. .REQUIRED_ATTR(num, Int)
  414. .ATTR(axis, Int, 0)
  415. .OP_END_FACTORY_REG(Unpack)
  416. /**
  417. * @brief Extract "patches" from "images" and stacks them in the "depth"
  418. * dimension of the output . \n
  419. * @par Inputs:
  420. * x: A 4D Tensor with shape [batch, in_rows, in_cols, depth], Must be one of the
  421. * following types:float32, double, int32, uint8, int16, int8, int64, uint16,
  422. * float16, uint32, uint64. The inputs must have data_format with one of follows:
  423. * NHWC, NCHW.
  424. * @par Attributes:
  425. * @li ksizes: A required list or tuple. The size of the sliding window for each
  426. * dimension of images.
  427. * @li strides: A required list or tuple. How far the centers of two consecutive
  428. * patches are in the images. Must be: [1, stride_rows, stride_cols, 1].
  429. * @li rates: A required list or tuple. Must be: [1, rate_rows, rate_cols, 1].
  430. * This is the input stride, specifying how far two consecutive patch
  431. * samples are in the input. Equivalent to extracting patches
  432. * with patch_sizes_eff = patch_sizes + (patch_sizes - 1) *
  433. * (rates - 1), followed by subsampling them spatially by a factor of rates.
  434. * This is equivalent to rate in dilated (a.k.a. Atrous) convolutions.
  435. * @li padding: A required string. The type of padding algorithm to use,
  436. support "SAME" or "VALID". \n
  437. * @par Outputs:
  438. * y: A 4D Tensor with shape [batch, out_rows, out_cols, ksize_rows *
  439. * ksize_cols * depth] containing image patches with size ksize_rows x ksize_cols
  440. * x depth vectorized in the "depth" dimension. Note "out_rows" and "out_cols"
  441. * are the dimensions of the output patches . \n
  442. * @attention Constraints:
  443. * "ksizes", "strides" and "rates" are lists of integers . \n
  444. * @par Third-party framework compatibility
  445. * Compatible with the TensorFlow operator ExtractImagePatches.
  446. */
  447. REG_OP(ExtractImagePatches)
  448. .INPUT(x, TensorType::RealNumberType())
  449. .OUTPUT(y, TensorType::RealNumberType())
  450. .REQUIRED_ATTR(ksizes, ListInt)
  451. .REQUIRED_ATTR(strides, ListInt)
  452. .REQUIRED_ATTR(rates, ListInt)
  453. .REQUIRED_ATTR(padding, String)
  454. .OP_END_FACTORY_REG(ExtractImagePatches)
  455. /**
  456. * @brief Extract "patches" from "input" and put them in the "depth"
  457. * dimension of the output . \n
  458. * @par Inputs:
  459. * x: A 5D Tensor with shape [batch, in_planes, in_rows, in_cols, depth] . \n
  460. * The inputs must have data_format with one of follows: NDHWC, NCDHW. \n
  461. * @par Attributes:
  462. * @li ksizes: A required list or tuple. The size of the sliding window for each
  463. * dimension of "x".
  464. * @li strides: A required list or tuple. How far the centers of two consecutive
  465. * patches are in "x". Must be: [1, stride_planes, stride_rows, stride_cols, 1].
  466. * @li padding: A required string. The type of padding algorithm to use ,
  467. * support "SAME" or "VALID" . \n
  468. * @par Outputs:
  469. * Output: A 5D Tensor with shape [batch, out_planes, out_rows, out_cols, ksize_planes *
  470. * ksize_rows * ksize_cols * depth] containing patches with size (ksize_rows * ksize_cols
  471. * * depth) vectorized in the "depth" dimension. Note "out_planes", "out_rows" and "out_cols"
  472. * are the dimensions of the output patches . \n
  473. * @attention Constraints:
  474. * "ksizes" and "strides" are lists of integers.
  475. * @par Third-party framework compatibility
  476. * Compatible with the TensorFlow operator ExtractVolumePatches.
  477. */
  478. REG_OP(ExtractVolumePatches)
  479. .INPUT(x, TensorType::REALNUMBERTYPE())
  480. .OUTPUT(y, TensorType::REALNUMBERTYPE())
  481. .REQUIRED_ATTR(ksizes, ListInt)
  482. .REQUIRED_ATTR(strides, ListInt)
  483. .REQUIRED_ATTR(padding, String)
  484. .OP_END_FACTORY_REG(ExtractVolumePatches)
  485. /**
  486. *@brief Confuse reshape and transpose . \n
  487. *@par Inputs:
  488. *x: A Tensor. Must be one of the following types: float16, float32, int8, int16, int32, int64, uint8, uint16, uint32, uint64 . \n
  489. *@par Attributes:
  490. *@li perm: A permutation of the dimensions of "x".
  491. *@li shape: The shape of the input.
  492. *@li transpose_first: If True, the transpose is first, otherwise the reshape is first . \n
  493. *@par Outputs:
  494. *y: A Tensor. Has the same type as "x".
  495. *
  496. * @par Restrictions:
  497. * Warning: THIS FUNCTION IS DEPRECATED. Please use ConfusionTranspose instead.
  498. */
  499. REG_OP(ConfusionTransposeD)
  500. .INPUT(x, TensorType({DT_INT8, DT_INT16, DT_INT32, DT_INT64, DT_UINT8,
  501. DT_UINT16, DT_UINT32, DT_UINT64, DT_FLOAT16, DT_FLOAT}))
  502. .OUTPUT(y, TensorType({DT_INT8, DT_INT16, DT_INT32, DT_INT64, DT_UINT8,
  503. DT_UINT16, DT_UINT32, DT_UINT64, DT_FLOAT16, DT_FLOAT}))
  504. .REQUIRED_ATTR(perm, ListInt)
  505. .REQUIRED_ATTR(shape, ListInt)
  506. .REQUIRED_ATTR(transpose_first, Bool)
  507. .OP_END_FACTORY_REG(ConfusionTransposeD)
  508. /**
  509. *@brief Confuse reshape and transpose . \n
  510. *@par Inputs:
  511. *@li x: A Tensor. Must be one of the following types: float16, float32, int8, int16, int32, int64, uint8, uint16, uint32, uint64.
  512. *@li shape: The shape of the input . \n
  513. *@par Attributes:
  514. *@li perm: A permutation of the dimensions of "x".
  515. *@li transpose_first: If True, the transpose is first, otherwise the reshape is first . \n
  516. *@par Outputs:
  517. *y: A Tensor. Has the same type as "x".
  518. *@par Restrictions:
  519. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  520. */
  521. REG_OP(ConfusionTranspose)
  522. .INPUT(x, TensorType::BasicType())
  523. .INPUT(shape, TensorType::IndexNumberType())
  524. .OUTPUT(y, TensorType::BasicType())
  525. .REQUIRED_ATTR(perm, ListInt)
  526. .REQUIRED_ATTR(transpose_first, Bool)
  527. .OP_END_FACTORY_REG(ConfusionTranspose)
  528. /**
  529. *@brief Flattens the input tensor to one-dimensional . \n
  530. *@par Inputs:
  531. *x: An ND tensor. All data types are supported . \n
  532. *@par Attributes:
  533. *@li axis: An optional int32, specifying the first axis to flatten. All preceding axes are retained in the output. Defaults to "1".
  534. *@li end_axis: An optional int32, specifying the last axis to flatten. All following axes are retained in the output. Defaults to "-1" . \n
  535. *@par Outputs:
  536. *y: The flattened ND tensor. All data types are supported . \n
  537. *@attention Constraints:
  538. * "axis" and "end_axis" must be within the dimension range of the input. This operator cannot be directly called by the acllopExecute API.
  539. *@par Third-party framework compatibility
  540. * Compatible with the Caffe operator Flatten.
  541. */
  542. REG_OP(FlattenV2)
  543. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT8, DT_UINT8, DT_INT16, DT_UINT16,
  544. DT_INT32, DT_UINT32, DT_INT64, DT_UINT64}))
  545. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT8, DT_UINT8, DT_INT16, DT_UINT16,
  546. DT_INT32, DT_UINT32, DT_INT64, DT_UINT64}))
  547. .ATTR(axis, Int, 1)
  548. .ATTR(end_axis, Int, -1)
  549. .OP_END_FACTORY_REG(FlattenV2)
  550. /**
  551. *@brief Compress large weight to small one. Usually inserted before Conv2d.
  552. *
  553. *@par Inputs:
  554. *weight: A tensor before compress. Must be one of the following types: DT_INT8, DT_FLOAT16
  555. *
  556. *@par Outputs:
  557. *@li weight_compress: A tensor after compress. Must be one of the following types: DT_INT8, DT_FLOAT16
  558. *@li compress_index: A tensor. Must be one of the following types: DT_INT8
  559. *
  560. *@par Attributes:
  561. *compress_parameters: A required int8, specifying the compressing block.
  562. *
  563. *@par Restrictions:
  564. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  565. */
  566. REG_OP(Compress)
  567. .INPUT(weight, TensorType({DT_INT8, DT_FLOAT16}))
  568. .OUTPUT(weight_compress, TensorType({DT_INT8, DT_FLOAT16}))
  569. .OUTPUT(compress_index, TensorType({DT_INT8}))
  570. .REQUIRED_ATTR(compress_parameters, ListInt)
  571. .OP_END_FACTORY_REG(Compress)
  572. /**
  573. *@brief Compress large weight to small one. Usually inserted before FullyConnection.
  574. *
  575. *@par Inputs:
  576. *weight: A tensor before compress. Must be one of the following types: DT_INT8, DT_FLOAT16
  577. *
  578. *@par Outputs:
  579. *@li weight_compress: A tensor after compress. Must be one of the following types: DT_INT8, DT_FLOAT16
  580. *@li compress_index: A tensor. Must be one of the following types: DT_INT8
  581. *
  582. *@par Attributes:
  583. *compress_parameters: A required int8, specifying the compressing block.
  584. *
  585. *@par Restrictions:
  586. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  587. */
  588. REG_OP(CompressFcOp)
  589. .INPUT(weight, TensorType({DT_INT8}))
  590. .OUTPUT(weight_compress, TensorType({DT_INT8}))
  591. .OUTPUT(compress_index, TensorType({DT_INT8}))
  592. .REQUIRED_ATTR(compress_parameters, ListInt)
  593. .OP_END_FACTORY_REG(CompressFcOp)
  594. /**
  595. *@brief Performs Col2im for each batch entry. \n
  596. *@par Inputs:
  597. *@li input_x: The Col Tensor. 5-D, shape: `(n, c1, kernel_h*kernel_w, ho*wo, c0)`.
  598. where ho/wo is do = (output_d + 2*padding_d - dilation_d*(kernel_d - 1) - 1)//stride_d + 1 \n
  599. *@par Outputs:
  600. *@li output_y: The img Tensor. 5-D, shape: `(n, c1, output_h, output_w, c0)`. \n
  601. *@par Attributes:
  602. *@li kernel_shape: ListInt, value: `(kernel_h, kernel_w)`, the shape of kernel in convolution.
  603. *@li dilation: ListInt, value: `(dilation_h, dilation_w)`, the dilation in convolution.
  604. *@li padding: ListInt, value: `(padding_h, padding_w)`, the dilation in convolution.
  605. *@li stride: ListInt, value: `(stride_h, stride_w)`, the dilation in convolution. \n
  606. *@par Third-party framework compatibility
  607. * Compatible with Pytorch col2im/im2col_backward operator.
  608. */
  609. REG_OP(Col2im)
  610. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16}))
  611. .INPUT(output_size, TensorType({DT_INT32, DT_INT32}))
  612. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16}))
  613. .REQUIRED_ATTR(kernel_size, ListInt)
  614. .REQUIRED_ATTR(dilation, ListInt)
  615. .REQUIRED_ATTR(padding, ListInt)
  616. .REQUIRED_ATTR(stride, ListInt)
  617. .OP_END_FACTORY_REG(Col2im)
  618. /**
  619. *@brief Generates a 2D or 3D flow field (sampling grid), given a batch of affine
  620. matrices theta. \n
  621. *@par Inputs:
  622. *Input theta must be float16 or float, output_size must be int32 type.Inputs
  623. include:
  624. *@li theta: input batch of affine matrices with shape (N,2,3) for 2D or (N,3,4)
  625. for 3D
  626. *@li output_size: the target output image size. (N×C×H×W for 2D or N×C×D×H×W for
  627. 3D) Example: torch.Size((32, 3, 24, 24)) . \n
  628. *@par Attributes:
  629. *align_corners: if True, consider -1 and 1 to refer to the centers of the corner
  630. pixels rather than the image corners.Refer to grid_sample() for a more complete
  631. description. A grid generated by affine_grid() should be passed to grid_sample()
  632. with the same setting for this option. Default: False \n
  633. *@par Outputs:
  634. *@li y: A 2-D integer tensor of shape [M] representing the
  635. selected indices from the boxes tensor, where M <= max_output_size. \n
  636. *@attention Constraints:
  637. *Input theta must be float16 or float, output_size must be int32 type . \n
  638. *@par Third-party framework compatibility
  639. *Compatible with Pytorch affine_grid operator.
  640. */
  641. REG_OP(AffineGrid)
  642. .INPUT(theta, TensorType({DT_FLOAT16, DT_FLOAT}))
  643. .INPUT(output_size, TensorType({DT_INT32}))
  644. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  645. .ATTR(align_corners, Bool, false)
  646. .OP_END_FACTORY_REG(AffineGrid)
  647. } // namespace ge
  648. #endif // OPS_BUILT_IN_OP_PROTO_INC_TRANSFORMATION_OPS_H_

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