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

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