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

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