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.

array_ops.h 30 kB

5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882
  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_ARRAY_OPS_H_
  17. #define GE_OP_ARRAY_OPS_H_
  18. #include "graph/operator_reg.h"
  19. #include "graph/operator.h"
  20. namespace ge {
  21. /**
  22. *@brief Applies lower_bound(sorted_search_values, values) along each row.
  23. *@par Inputs:
  24. *The input sorted_x and values can be one-dimensional vector. Inputs include: \n
  25. * @li sorted_x:A `Tensor`. 2-D Tensor where each row is ordered.
  26. * @li values:A `Tensor`. Must have the same type as `sorted_x`.
  27. *@par Attributes:
  28. *@li out_type:An optional `DType` from: `int32, int64`. Defaults to `int32`.
  29. *@par Outputs:
  30. *y: A `Tensor` of type `out_type`.
  31. *@attention Constraints: \n
  32. *-The implementation for LowerBound on Ascend uses AI CPU, with bad performance. \n
  33. *@par Quantization supported or not
  34. *Not supported
  35. *@par Quantized inference supported or not
  36. *Supported
  37. *@par L2 convergence supported or not
  38. *@par Multiple batches supported or not
  39. */
  40. REG_OP(LowerBound)
  41. .INPUT(sorted_x, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, \
  42. DT_INT16, DT_UINT16, DT_UINT8, DT_INT32, DT_INT64, DT_DOUBLE}))
  43. .INPUT(values, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, \
  44. DT_INT16, DT_UINT16, DT_UINT8, DT_INT32, DT_INT64, DT_DOUBLE}))
  45. .OUTPUT(y, TensorType({DT_INT32, DT_INT64}))
  46. .ATTR(out_type, Type, DT_INT32)
  47. .OP_END_FACTORY_REG(LowerBound)
  48. /**
  49. *@brief Reverses variable length slices.
  50. *@par Inputs:
  51. *The input x can be k-dimensional tensor, num_lower and num_upper can be zero-dimensional scalar. Inputs include: \n
  52. * @li x:A Tensor. The input to reverse.
  53. * @li seq_lengths:A Tensor. Must be one of the following types: int32, int64. 1-D.
  54. *@par Attributes:
  55. *@li seq_dim:An optional int. Defaults to 0. The dimension along which reversal is performed.
  56. *@li batch_dim:An optional int. Defaults to 0. The dimension along which reversal is performed.
  57. *@par Outputs:
  58. *y: Rank k tensor of the same shape as input. The extracted banded tensor.
  59. *@attention Constraints: \n
  60. *-The implementation for ReverseSequence on Ascend uses AI CPU, with bad performance.
  61. *@par Quantization supported or not
  62. *Not supported
  63. *@par Quantized inference supported or not
  64. *Supported
  65. *@par L2 convergence supported or not
  66. *@par Multiple batches supported or not
  67. */
  68. REG_OP(ReverseSequence)
  69. .INPUT(x,
  70. TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, DT_UINT16, \
  71. DT_UINT8, DT_INT32, DT_INT64, DT_BOOL, DT_DOUBLE}))
  72. .INPUT(seq_lengths, TensorType({DT_INT32, DT_INT64}))
  73. .OUTPUT(y,
  74. TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, DT_UINT16, \
  75. DT_UINT8, DT_INT32, DT_INT64, DT_BOOL, DT_DOUBLE}))
  76. .REQUIRED_ATTR(seq_dim, Int)
  77. .ATTR(batch_dim, Int, 0)
  78. .OP_END_FACTORY_REG(ReverseSequence)
  79. /**
  80. *@brief Copy a tensor setting everything outside a central band in each innermost matrix.
  81. *@par Inputs:
  82. *The input x can be k-dimensional tensor, num_lower and num_upper can be zero-dimensional scalar. Inputs include: \n
  83. * @li x:Rank `k` tensor.
  84. * @li num_lower:0-D tensor. Number of superdiagonals to keep. If negative, keep entire upper triangle.
  85. * @li num_upper:0-D tensor. Number of superdiagonals to keep. If negative, keep entire upper triangle.
  86. *@par Outputs:
  87. *y: Rank k tensor of the same shape as input. The extracted banded tensor.
  88. *@attention Constraints: \n
  89. *-The implementation for MatrixBandPart on Ascend uses AI CPU, with bad performance. \n
  90. *@par Quantization supported or not
  91. *Not supported
  92. *@par Quantized inference supported or not
  93. *Supported
  94. *@par L2 convergence supported or not
  95. *@par Multiple batches supported or not
  96. */
  97. REG_OP(MatrixBandPart)
  98. .INPUT(x, TensorType({ DT_INT8, DT_UINT8, \
  99. DT_INT16, DT_UINT16, DT_INT32, DT_INT64,
  100. DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_BOOL }))
  101. .INPUT(num_lower, TensorType({ DT_INT32, DT_INT64 }))
  102. .INPUT(num_upper, TensorType({ DT_INT32, DT_INT64 }))
  103. .OUTPUT(y, TensorType({ DT_INT8, DT_UINT8, DT_INT16, DT_UINT16, \
  104. DT_INT32, DT_INT64, DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_BOOL }))
  105. .OP_END_FACTORY_REG(MatrixBandPart)
  106. /**
  107. *@brief Finds unique elements in a 1-D tensor.
  108. *@par Inputs:
  109. *The input x can be k-dimensional tensor, num_lower and num_upper can be zero-dimensional scalar. Inputs include: \n
  110. *x:1-D tensor.
  111. *@par Attributes:
  112. *out_idx:An optional DType from: int32, int64. Defaults to int32. \n
  113. *@par Outputs:
  114. *@li y:A Tensor. Has the same type as x.
  115. *@li idx:A Tensor of type out_idx.
  116. *@li count:A Tensor of type out_idx.
  117. *@attention Constraints: \n
  118. *-The implementation for UniqueWithCounts on Ascend uses AI CPU, with bad performance. \n
  119. *@par Quantization supported or not
  120. *Not supported
  121. *@par Quantized inference supported or not
  122. *Supported
  123. *@par L2 convergence supported or not
  124. *@par Multiple batches supported or not
  125. */
  126. REG_OP(UniqueWithCounts)
  127. .INPUT(x, TensorType({ DT_INT8, DT_UINT8, DT_INT16, DT_UINT16, \
  128. DT_INT32, DT_INT64, DT_FLOAT16, DT_FLOAT, DT_DOUBLE }))
  129. .OUTPUT(y, TensorType({ DT_INT8, DT_UINT8, DT_INT16, DT_UINT16, \
  130. DT_INT32, DT_INT64, DT_FLOAT16, DT_FLOAT, DT_DOUBLE }))
  131. .OUTPUT(idx, TensorType({ DT_INT32, DT_INT64 }))
  132. .OUTPUT(count, TensorType({ DT_INT32, DT_INT64 }))
  133. .REQUIRED_ATTR(out_idx, Type)
  134. .OP_END_FACTORY_REG(UniqueWithCounts)
  135. /**
  136. *@brief Finds unique elements in a 1-D tensor.
  137. *@par Inputs:
  138. *The input x can be k-dimensional tensor, num_lower and num_upper can be zero-dimensional scalar. Inputs include: \n
  139. *x:1-D tensor.
  140. *@par Attributes:
  141. *out_idx:An optional DType from: int32, int64. Defaults to int32.
  142. *@par Outputs:
  143. *@li y:x in the unique output y.
  144. *@li idx:A tensor idx the same size as x that contains the index of each value of x.
  145. *@attention Constraints: \n
  146. *-The implementation for Unique on Ascend uses AI CPU, with bad performance. \n
  147. *@par Quantization supported or not
  148. *Not supported
  149. *@par Quantized inference supported or not
  150. *Supported
  151. *@par L2 convergence supported or not
  152. *@par Multiple batches supported or not
  153. */
  154. REG_OP(Unique)
  155. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, \
  156. DT_UINT16, DT_UINT8, DT_INT32, DT_INT64, DT_DOUBLE}))
  157. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, \
  158. DT_UINT16, DT_UINT8, DT_INT32, DT_INT64, DT_DOUBLE}))
  159. .OUTPUT(idx, TensorType({DT_INT32, DT_INT64}))
  160. .ATTR(out_idx, Type, DT_INT32)
  161. .OP_END_FACTORY_REG(Unique)
  162. /**
  163. *@brief Finds unique elements in a 1-D tensor.
  164. *@par Inputs:
  165. *The input x can be k-dimensional tensor, num_lower and num_upper can be zero-dimensional scalar. Inputs include: \n
  166. * @li x:1-D tensor.
  167. * @li axis:A `Tensor` of type `int32` (default: None). The axis of the Tensor to.
  168. *@par Attributes:
  169. *out_idx:An optional DType from: int32, int64. Defaults to int32.
  170. *@par Outputs:
  171. *@li y:x in the unique output y.
  172. *@li idx:A tensor idx the same size as x that contains the index of each value of x.
  173. *@attention Constraints: \n
  174. *-The implementation for UniqueExt2 on Ascend uses AI CPU, with bad performance. \n
  175. *@par Quantization supported or not
  176. *Not supported
  177. *@par Quantized inference supported or not
  178. *Supported
  179. *@par L2 convergence supported or not
  180. *@par Multiple batches supported or not
  181. */
  182. REG_OP(UniqueExt2)
  183. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, \
  184. DT_UINT16, DT_UINT8, DT_INT32, DT_INT64, DT_DOUBLE}))
  185. .INPUT(axis, TensorType({DT_INT32, DT_INT64}))
  186. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, \
  187. DT_UINT16, DT_UINT8, DT_INT32, DT_INT64, DT_DOUBLE}))
  188. .OUTPUT(idx, TensorType({DT_INT32, DT_INT64}))
  189. .ATTR(out_idx, Type, DT_INT32)
  190. .OP_END_FACTORY_REG(UniqueExt2)
  191. /**
  192. *@brief Computes the inverse permutation of a tensor.
  193. *@par Inputs:
  194. *The input x can be k-dimensional tensor. Inputs include: \n
  195. *x:K-D tensor.
  196. *@par Outputs:
  197. *y:1-D tensor.
  198. *@attention Constraints:\n
  199. *-The implementation for InvertPermutation on Ascend uses AI CPU, with bad performance. \n
  200. *@par Quantization supported or not
  201. *Not supported
  202. *@par Quantized inference supported or not
  203. *Supported
  204. *@par L2 convergence supported or not
  205. *@par Multiple batches supported or not
  206. */
  207. REG_OP(InvertPermutation)
  208. .INPUT(x, TensorType({DT_INT32, DT_INT64}))
  209. .OUTPUT(y, TensorType({DT_INT32, DT_INT64}))
  210. .OP_END_FACTORY_REG(InvertPermutation)
  211. /**
  212. *@brief Checks a tensor for NaN and Inf values.
  213. *@par Inputs:
  214. *The input x can be k-dimensional tensor. Inputs include: \n
  215. *x:The input tensor.
  216. *@par Attributes:
  217. *message:Prefix of the error message.
  218. *@par Outputs:
  219. *y:The output tensor.
  220. *@attention Constraints: \n
  221. *-The implementation for CheckNumerics on Ascend uses AI CPU, with bad performance. \n
  222. *@par Quantization supported or not
  223. *Not supported
  224. *@par Quantized inference supported or not
  225. *Supported
  226. *@par L2 convergence supported or not
  227. *@par Multiple batches supported or not
  228. */
  229. REG_OP(CheckNumerics)
  230. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  231. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  232. .REQUIRED_ATTR(message, String)
  233. .OP_END_FACTORY_REG(CheckNumerics)
  234. /**
  235. *@brief Converts an array of flat indices into a tuple of coordinate arrays.
  236. *@par Inputs:
  237. *The input indices can be 0-D or 1-D tensor, dims can be 1-D. Inputs include: \n
  238. * @li indices: A 0-D or 1-D int Tensor whose elements are indices into the flattened version of an array of dimensions dims.
  239. * @li dims:A Tensor. Must have the same type as indices. An 1-D int Tensor. The shape of the array to use for unraveling indices.
  240. *@par Outputs:
  241. *y:A Tensor. Has the same type as indices.
  242. *@attention Constraints: \n
  243. *-The implementation for UnravelIndex on Ascend uses AI CPU, with bad performance. \n
  244. *@par Quantization supported or not
  245. *Not supported
  246. *@par Quantized inference supported or not
  247. *Supported
  248. *@par L2 convergence supported or not
  249. *@par Multiple batches supported or not
  250. */
  251. REG_OP(UnravelIndex)
  252. .INPUT(indices, TensorType({DT_INT32, DT_INT64}))
  253. .INPUT(dims, TensorType({DT_INT32, DT_INT64}))
  254. .OUTPUT(y, TensorType({DT_INT32, DT_INT64}))
  255. .OP_END_FACTORY_REG(UnravelIndex)
  256. /**
  257. *@brief Applies upper_bound(sorted_search_values, values) along each row.
  258. *@par Inputs:
  259. *The input sorted_x can be 2-D tensor, values can be 2-D. Inputs include:
  260. * @li sorted_x: 2-D Tensor where each row is ordered.
  261. * @li values:2-D Tensor with the same numbers of rows as `sorted_x.
  262. *@par Attributes:
  263. *out_type:sets the optional out_type attribute to value.
  264. *@par Outputs:
  265. *y:A `Tensor` with the same shape as `values`.
  266. *@attention Constraints: \n
  267. *-The implementation for UpperBound on Ascend uses AI CPU, with bad performance. \n
  268. *@par Quantization supported or not
  269. *Not supported
  270. *@par Quantized inference supported or not
  271. *Supported
  272. *@par L2 convergence supported or not
  273. *@par Multiple batches supported or not
  274. */
  275. REG_OP(UpperBound)
  276. .INPUT(sorted_x, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, \
  277. DT_UINT16, DT_UINT8, DT_INT32, DT_INT64, DT_DOUBLE}))
  278. .INPUT(values, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, \
  279. DT_UINT16, DT_UINT8, DT_INT32, DT_INT64, DT_DOUBLE}))
  280. .OUTPUT(y, TensorType({DT_INT32, DT_INT64}))
  281. .REQUIRED_ATTR(out_type, Type)
  282. .OP_END_FACTORY_REG(UpperBound)
  283. /**
  284. *@brief Finds unique elements in a 1-D tensor.
  285. *@par Inputs:
  286. *The input x can be 1-D vector, axis can be 1-D vector. Inputs include: \n
  287. * @li x:1-D tensor.
  288. * @li axis:1-D tensor.
  289. *@par Attributes:
  290. *out_idx:An optional DType from: int32, int64. Defaults to int32.
  291. *@par Outputs:
  292. *@li y:x in the unique output y.
  293. *@li idx:A tensor idx the same size as x that contains the index of each value of x.
  294. *@li count:A tensor idx the same size as x that contains the index of each value of x.
  295. *@attention Constraints: \n
  296. *-The implementation for UniqueWithCountsExt2 on Ascend uses AI CPU, with bad performance. \n
  297. *@par Quantization supported or not
  298. *Not supported
  299. *@par Quantized inference supported or not
  300. *Supported
  301. *@par L2 convergence supported or not
  302. *@par Multiple batches supported or not
  303. */
  304. REG_OP(UniqueWithCountsExt2)
  305. .INPUT(x, TensorType({ DT_INT8, DT_UINT8, DT_INT16, DT_UINT16, \
  306. DT_INT32, DT_INT64, DT_FLOAT16, DT_FLOAT, DT_DOUBLE }))
  307. .INPUT(axis, TensorType({ DT_INT32, DT_INT64 }))
  308. .OUTPUT(y, TensorType({ DT_INT8, DT_UINT8, DT_INT16, DT_UINT16, \
  309. DT_INT32, DT_INT64, DT_FLOAT16, DT_FLOAT, DT_DOUBLE }))
  310. .OUTPUT(idx, TensorType({ DT_INT32, DT_INT64 }))
  311. .OUTPUT(count, TensorType({ DT_INT32, DT_INT64 }))
  312. .REQUIRED_ATTR(out_idx, Type)
  313. .OP_END_FACTORY_REG(UniqueWithCountsExt2)
  314. /**
  315. *@brief Fill the tensor with the mirror value.
  316. *@par Inputs:
  317. *The input x and paddings can be one-dimensional scalar. Inputs include: \n
  318. * @li x: input tensor to be padded.
  319. * @li paddings: A two-column matrix specifying the padding sizes. The number of rows must be the same as the rank of `input`.
  320. *@par Attributes:
  321. *mode:Either `REFLECT` or `SYMMETRIC`. In reflect mode the padded regions do not include the borders, while in symmetric mode the padded regions do include the borders.
  322. *@par Outputs:
  323. *y: The padded tensor.
  324. *@attention Constraints: \n
  325. -The implementation for MirrorPad on Ascend uses AI CPU, with bad performance. \n
  326. *@par Quantization supported or not
  327. *Not supported
  328. *@par Quantized inference supported or not
  329. *Supported
  330. *@par L2 convergence supported or not
  331. *@par Multiple batches supported or not
  332. */
  333. REG_OP(MirrorPad)
  334. .INPUT(x, TensorType({ DT_INT8, DT_UINT8, DT_INT16, DT_UINT16, \
  335. DT_INT32, DT_INT64, DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_BOOL }))
  336. .INPUT(paddings, TensorType({ DT_INT32, DT_INT64 }))
  337. .OUTPUT(y, TensorType({ DT_INT8, DT_UINT8, DT_INT16, DT_UINT16, \
  338. DT_INT32, DT_INT64, DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_BOOL }))
  339. .REQUIRED_ATTR(mode, String)
  340. .OP_END_FACTORY_REG(MirrorPad)
  341. /**
  342. *@brief Calculate the difference between two numbers or a list of strings.
  343. *@par Inputs:
  344. *The input x and y can be one-dimensional vector. Inputs include: \n
  345. * @li x:A Tensor. 1-D. Values to keep.
  346. * @li y:A Tensor. Must have the same type as x. 1-D. Values to remove.
  347. *@par Attributes:
  348. *out_idx:An optional DType from: int32, int64. Defaults to int32.
  349. *@par Outputs:
  350. *@li out:A Tensor. Has the same type as x.
  351. *@li idx:A Tensor of type out_idx.
  352. *@attention Constraints:\n
  353. -The implementation for ListDiff on Ascend uses AI CPU, with bad performance. \n
  354. *@par Quantization supported or not
  355. *Not supported
  356. *@par Quantized inference supported or not
  357. *Supported
  358. *@par L2 convergence supported or not
  359. *@par Multiple batches supported or not
  360. */
  361. REG_OP(ListDiff)
  362. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16, DT_DOUBLE, DT_UINT8, DT_INT8,
  363. DT_INT16, DT_UINT16, DT_INT32, DT_INT64}))
  364. .INPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_DOUBLE, DT_UINT8, DT_INT8,
  365. DT_INT16, DT_UINT16, DT_INT32, DT_INT64}))
  366. .OUTPUT(out, TensorType({DT_FLOAT, DT_FLOAT16, DT_DOUBLE, DT_UINT8, DT_INT8,
  367. DT_INT16, DT_UINT16, DT_INT32, DT_INT64}))
  368. .OUTPUT(idx, TensorType({DT_INT32, DT_INT64}))
  369. .ATTR(out_idx, Type, DT_INT32)
  370. .OP_END_FACTORY_REG(ListDiff)
  371. /**
  372. *@brief Creates a constant tensor from a tensor-like object. This operator is used for inference. \n
  373. Operator Const has the same definition as operator Constant.
  374. *@par Attributes:
  375. *@li value: Required. The value and type of the resulting tensor.
  376. *@li dtype: Optional. The type of the elements of the resulting tensor. \n
  377. The data type specified by this parameter must be the same as that of the "value" attribute.
  378. *@par Outputs:
  379. *y: A constant tensor.
  380. */
  381. REG_OP(Const)
  382. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, DT_UINT16, \
  383. DT_UINT8, DT_INT32, DT_INT64, DT_UINT32, DT_UINT64, DT_BOOL, DT_DOUBLE}))
  384. .ATTR(value, Tensor, Tensor()) // This is the value of the const op
  385. .ATTR(dtype, Int, 0)
  386. .OP_END_FACTORY_REG(Const)
  387. /**
  388. *@brief Creates a constant tensor for training.
  389. *@par Attributes:
  390. *@li value: Required. The value and type of the resulting tensor.
  391. *@li dtype: Optional. The type of the elements of the resulting tensor. \n
  392. The data type specified by this parameter must be the same as that of the "value" attribute.
  393. *@par Outputs:
  394. *y: The constant tensor.
  395. */
  396. REG_OP(Constant)
  397. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, DT_UINT16, \
  398. DT_UINT8, DT_INT32, DT_INT64, DT_UINT32, DT_UINT64, DT_BOOL, DT_DOUBLE}))
  399. .ATTR(value, Tensor, Tensor()) // This is the value of the constant op
  400. .ATTR(dtype, Int, 0)
  401. .OP_END_FACTORY_REG(Constant)
  402. /**
  403. *@brief Returns a copy of the input tensor.
  404. *@par Inputs:
  405. *x: A tensor.
  406. *@par Outputs:
  407. *y: A tensor.
  408. */
  409. REG_OP(Snapshot)
  410. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, DT_UINT16, \
  411. DT_UINT8, DT_INT32, DT_INT64, DT_UINT32, DT_UINT64, DT_BOOL, DT_DOUBLE}))
  412. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, DT_UINT16, \
  413. DT_UINT8, DT_INT32, DT_INT64, DT_UINT32, DT_UINT64, DT_BOOL, DT_DOUBLE}))
  414. .OP_END_FACTORY_REG(Snapshot)
  415. /**
  416. *@brief Gives a guarantee to the runtime that the input tensor is a constant.
  417. *@par Inputs:
  418. *x: A tensor.
  419. *@par Outputs:
  420. *y: The input tensor.
  421. */
  422. REG_OP(GuaranteeConst)
  423. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, DT_UINT16, DT_UINT8,
  424. DT_INT32, DT_INT64, DT_UINT32, DT_UINT64, DT_BOOL, DT_DOUBLE}))
  425. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, DT_UINT16, DT_UINT8,
  426. DT_INT32, DT_INT64, DT_UINT32, DT_UINT64, DT_BOOL, DT_DOUBLE}))
  427. .OP_END_FACTORY_REG(GuaranteeConst)
  428. /**
  429. *@brief Returns the target shape for broadcasting shapes "x1" and "x2".
  430. *@par Inputs:
  431. *@li x1: A tensor of type int32 or int64. A shape.
  432. *@li x2: A tensor of the same type as "x1". The other shape.
  433. *@par Outputs:
  434. *y: A tensor. The broadcasted shape.
  435. */
  436. REG_OP(BroadcastArgs)
  437. .INPUT(x1, TensorType({DT_INT32, DT_INT64}))
  438. .INPUT(x2, TensorType({DT_INT32, DT_INT64}))
  439. .OUTPUT(y, TensorType({DT_INT32, DT_INT64}))
  440. .OP_END_FACTORY_REG(BroadcastArgs)
  441. /**
  442. *@brief Outputs its input tensor as is and triggers an error if a gradient is requested.
  443. *@par Inputs:
  444. *x: A tensor.
  445. *@par Attributes:
  446. *message: Will be printed in the error at the attempt to request a gradient.
  447. *@par Outputs:
  448. *y: The input tensor.
  449. */
  450. REG_OP(PreventGradient)
  451. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, DT_UINT16, DT_UINT8,
  452. DT_INT32, DT_INT64, DT_UINT32, DT_UINT64, DT_BOOL, DT_DOUBLE}))
  453. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, DT_UINT16, DT_UINT8,
  454. DT_INT32, DT_INT64, DT_UINT32, DT_UINT64, DT_BOOL, DT_DOUBLE}))
  455. .ATTR(message, String, "")
  456. .OP_END_FACTORY_REG(PreventGradient)
  457. /**
  458. *@brief Returns the reduction indices for computing gradients of "x1" and "x2" with broadcast.
  459. *@par Inputs:
  460. *@li x1: A tensor of type int32 or int64.
  461. *@li x2: A tensor of type int32 or int64. \n
  462. "x2" has the same type as "x1".
  463. *@par Outputs:
  464. *@li y1: A tensor. Reduction indices of "x1".
  465. *@li y2: A tensor. Reduction indices of "x2".
  466. */
  467. REG_OP(BroadcastGradientArgs)
  468. .INPUT(x1, TensorType({DT_INT32, DT_INT64}))
  469. .INPUT(x2, TensorType({DT_INT32, DT_INT64}))
  470. .OUTPUT(y1, TensorType({DT_INT32, DT_INT64}))
  471. .OUTPUT(y2, TensorType({DT_INT32, DT_INT64}))
  472. .OP_END_FACTORY_REG(BroadcastGradientArgs)
  473. /**
  474. *@brief Stops gradient computation. None is returned for the node where the gradient computation is stopped.
  475. *@par Inputs:
  476. *x: A tensor.
  477. *@par Outputs:
  478. *y: The input tensor.
  479. */
  480. REG_OP(StopGradient)
  481. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, DT_UINT16, DT_UINT8,
  482. DT_INT32, DT_INT64, DT_UINT32, DT_UINT64, DT_BOOL, DT_DOUBLE}))
  483. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, DT_UINT16, DT_UINT8,
  484. DT_INT32, DT_INT64, DT_UINT32, DT_UINT64, DT_BOOL, DT_DOUBLE}))
  485. .OP_END_FACTORY_REG(StopGradient)
  486. /**
  487. *@brief Return a tensor with the same shape and contents as input.
  488. *@par Inputs:
  489. *x: A tensor.
  490. *@par Outputs:
  491. *y: A tensor.
  492. */
  493. REG_OP(Identity)
  494. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, DT_UINT16, DT_UINT8,
  495. DT_INT32, DT_INT64, DT_UINT32, DT_UINT64, DT_BOOL, DT_DOUBLE}))
  496. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, DT_UINT16, DT_UINT8,
  497. DT_INT32, DT_INT64, DT_UINT32, DT_UINT64, DT_BOOL, DT_DOUBLE}))
  498. .OP_END_FACTORY_REG(Identity)
  499. /**
  500. *@brief Returns a list of tensors with the same shapes and contents as the input tensors.
  501. *@par Inputs:
  502. *x: A list of input tensors.
  503. *@par Outputs:
  504. *y: A list of Tensor objects, with the same length as the input tensor list.
  505. */
  506. REG_OP(IdentityN)
  507. .DYNAMIC_INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, DT_UINT16, DT_UINT8,
  508. DT_INT32, DT_INT64, DT_UINT32, DT_UINT64, DT_BOOL, DT_DOUBLE}))
  509. .DYNAMIC_OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, DT_UINT16, DT_UINT8,
  510. DT_INT32, DT_INT64, DT_UINT32, DT_UINT64, DT_BOOL, DT_DOUBLE}))
  511. .OP_END_FACTORY_REG(IdentityN)
  512. /**
  513. *@brief Inserts a dimension of 1 into a tensor's shape. Only the tensor shape is changed, without changing the data.
  514. *@par Inputs:
  515. *@li x: A tensor.
  516. *@li axis: The dimension index at which to expand.
  517. *@par Outputs:
  518. *y: A tensor.
  519. */
  520. REG_OP(ExpandDims)
  521. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, DT_UINT16, DT_UINT8, DT_INT32,
  522. DT_INT64, DT_UINT32, DT_UINT64, DT_BOOL, DT_DOUBLE}))
  523. .INPUT(axis, TensorType({DT_INT32, DT_INT64}))
  524. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, DT_UINT16, DT_UINT8, DT_INT32,
  525. DT_INT64, DT_UINT32, DT_UINT64, DT_BOOL, DT_DOUBLE}))
  526. .ATTR(T, Int, 0)
  527. .ATTR(Tdim, Int, 0)
  528. .OP_END_FACTORY_REG(ExpandDims)
  529. /**
  530. *@brief Reshapes a tensor. Only the tensor shape is changed, without changing the data.
  531. *@par Inputs:
  532. *@li x: A tensor.
  533. *@li shape: A tensor. Defines the shape of the output tensor.
  534. *@par Attributes:
  535. *@li axis: An optional int32 or int64. The first dimension to reshape. Defaults to "0".
  536. *@li num_axes: An optional int32 or int64. The extent of the reshape. Defaults to "-1".
  537. *@par Outputs:
  538. *y: A tensor.
  539. */
  540. REG_OP(Reshape)
  541. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, DT_UINT16, DT_UINT8, DT_INT32,
  542. DT_INT64, DT_UINT32, DT_UINT64, DT_BOOL, DT_DOUBLE}))
  543. .INPUT(shape, TensorType({DT_INT32, DT_INT64}))
  544. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, DT_UINT16, DT_UINT8, DT_INT32,
  545. DT_INT64, DT_UINT32, DT_UINT64, DT_BOOL, DT_DOUBLE}))
  546. .ATTR(axis, Int, 0)
  547. .ATTR(num_axes, Int, -1)
  548. .OP_END_FACTORY_REG(Reshape)
  549. /**
  550. *@brief Removes dimensions of size 1 from the shape of a tensor.
  551. *@par Inputs:
  552. *x: A tensor.
  553. *@par Attributes:
  554. *axis: An optional list of int32 or int64. If not specified, squeezes all dimensions of size 1. \n If specified, only squeezes the dimensions listed. It is an error to squeeze a dimension that is not 1.
  555. *@par Outputs:
  556. *y: A tensor.
  557. */
  558. REG_OP(Squeeze)
  559. .INPUT(x, TensorType::ALL())
  560. .OUTPUT(y, TensorType::ALL())
  561. .ATTR(T, Int, 0)
  562. .ATTR(squeeze_dims, ListInt, {})
  563. .ATTR(axis, ListInt, {})
  564. .OP_END_FACTORY_REG(Squeeze)
  565. /**
  566. *@brief Returns an integer representing the rank of input tensor. The rank of a tensor is the number of indices required to uniquely select each element of the tensor, that is, the dimension size of the tensor.
  567. *@par Inputs:
  568. *x: A tensor.
  569. *@par Outputs:
  570. *y: A tensor. The rank of input tensor.
  571. */
  572. REG_OP(Rank)
  573. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, DT_UINT16, DT_UINT8,
  574. DT_INT32, DT_INT64, DT_UINT32, DT_UINT64, DT_BOOL, DT_DOUBLE}))
  575. .OUTPUT(y, TensorType({DT_INT32}))
  576. .OP_END_FACTORY_REG(Rank)
  577. /**
  578. *@brief Returns the size of a tensor, that is, an integer of the number of elements of the tensor.
  579. *@par Inputs:
  580. *x: A tensor.
  581. *@par Attributes:
  582. *out_type: An optional int32 or int64. The output data type. Defaults to "int32".
  583. *@par Outputs:
  584. *y: A tensor. The size of the input tensor.
  585. */
  586. REG_OP(Size)
  587. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, DT_UINT16, DT_UINT8,
  588. DT_INT32, DT_INT64, DT_UINT32, DT_UINT64, DT_BOOL, DT_DOUBLE}))
  589. .OUTPUT(y, TensorType({DT_INT32,DT_INT64}))
  590. .ATTR(alpha, Float, 1.0)
  591. .ATTR(beta, Float, 0.0)
  592. .ATTR(out_type, Int, DT_INT32)
  593. .OP_END_FACTORY_REG(Size)
  594. REG_OP(Data)
  595. .INPUT(data, TensorType::ALL())
  596. .OUTPUT(out, TensorType::ALL())
  597. .ATTR(index, Int, 0)
  598. .OP_END_FACTORY_REG(Data)
  599. /**
  600. *@brief Inserts a placeholder for a tensor that will be always fed.
  601. *@par Inputs:
  602. *x: A tensor.
  603. *@par Attributes:
  604. *@li peerIndex: An integer type. The index of the corresponding "end" node connected to.
  605. *@li parentId: A string, used to check if the nodes are from the saved parent node.
  606. *@li parentOpType: A string. Op type of the original node.
  607. *@li anchorIndex: An integer, used to check if the node is from the saved anchor.
  608. *@par Outputs:
  609. *y: The created placeholder tensor.
  610. */
  611. REG_OP(PlaceHolder)
  612. .INPUT(x, TensorType::ALL())
  613. .OUTPUT(y, TensorType::ALL())
  614. .ATTR(peerIndex, Int, 0) // the index of the corresponding 'end' node it's connected to
  615. .ATTR(parentId, String, "") // check if these node are from save parent node
  616. .ATTR(parentOpType, String, "") // op type of original node
  617. .ATTR(anchorIndex, Int, 0) // check if these node are from save anchor
  618. .OP_END_FACTORY_REG(PlaceHolder)
  619. REG_OP(End)
  620. .INPUT(x, TensorType::ALL())
  621. .OUTPUT(y, TensorType::ALL())
  622. .ATTR(peerIndex, Int, 0) // the index of the corresponding 'placeholder' node it's connected to
  623. .ATTR(parentOpType, String, "") // op type of original node
  624. .OP_END_FACTORY_REG(End)
  625. REG_OP(Summary)
  626. .INPUT(x, TensorType::ALL())
  627. .OP_END_FACTORY_REG(Summary)
  628. /**
  629. *@brief Returns the shape of a tensor.
  630. *@par Inputs:
  631. *x: A tensor.
  632. *@par Attributes:
  633. *out_type: An optional int32 or int64. The output data type. Defaults to int32.
  634. *@par Outputs:
  635. *y: A tensor. The shape of the input tensor.
  636. */
  637. REG_OP(Shape)
  638. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, DT_UINT16, DT_UINT8,
  639. DT_INT32, DT_INT64, DT_UINT32, DT_UINT64, DT_BOOL, DT_DOUBLE}))
  640. .OUTPUT(y, TensorType({DT_INT32, DT_INT64}))
  641. .ATTR(alpha, Float, 1.0)
  642. .ATTR(beta, Float, 0.0)
  643. .ATTR(out_type, Int, DT_INT32)
  644. .OP_END_FACTORY_REG(Shape)
  645. /**
  646. *@brief Returns shape of tensors.
  647. *@par Inputs:
  648. *x: A list of input tensors.
  649. *@par Attributes:
  650. *out_type: An optional int32 or int64. The output data type. Defaults to "int32".
  651. *@par Outputs:
  652. *y: A list of tensors with the same length as the input list of tensors.
  653. */
  654. REG_OP(ShapeN)
  655. .DYNAMIC_INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, DT_UINT16, DT_UINT8,
  656. DT_INT32, DT_INT64, DT_UINT32, DT_UINT64, DT_BOOL, DT_DOUBLE}))
  657. .DYNAMIC_OUTPUT(y, TensorType({DT_INT32, DT_INT64}))
  658. .ATTR(alpha, Float, 1.0)
  659. .ATTR(beta, Float, 0.0)
  660. .ATTR(out_type, Int, DT_INT32)
  661. .OP_END_FACTORY_REG(ShapeN)
  662. /**
  663. *@brief Creates a tensor with the given "shape" and "dtype".
  664. *@par Inputs:
  665. *shape: The shape of the output tensor.
  666. *@par Attributes:
  667. *@li dtype: Optional. The data type of the output tensor. Defaults to "int32".
  668. *@li init: An optional bool. If true, initializes the returned tensor with the default value of "dtype". Defaults to "false".
  669. *@par Outputs:
  670. *y: A tensor.
  671. */
  672. REG_OP(Empty)
  673. .INPUT(shape, TensorType({DT_INT32}))
  674. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, DT_UINT16, DT_UINT8,
  675. DT_INT32, DT_INT64, DT_UINT32, DT_UINT64, DT_BOOL, DT_DOUBLE}))
  676. .ATTR(dtype, Int, DT_INT32)
  677. .ATTR(init, Bool, 0)
  678. .OP_END_FACTORY_REG(Empty)
  679. /**
  680. *@brief Gradient op for MirrorPad op. This op folds a mirror-padded tensor.
  681. *@par Inputs:
  682. *The input x and y can be one-dimensional vector. Inputs include: \n
  683. * @li x:A Tensor. The input tensor to be folded.
  684. * @li paddings:A Tensor. Must be one of the following types: int32, int64. A two-column matrix specifying the padding sizes.
  685. *@par Attributes:
  686. *mode:A string from: "REFLECT", "SYMMETRIC". The mode used in the MirrorPad op.
  687. *@par Outputs:
  688. *y:A Tensor. Has the same type as x.
  689. *@attention Constraints: \n
  690. -The implementation for MirrorPadGrad on Ascend uses AI CPU, with bad performance. \n
  691. *@par Quantization supported or not
  692. *Not supported
  693. *@par Quantized inference supported or not
  694. *Supported
  695. *@par L2 convergence supported or not
  696. *@par Multiple batches supported or not
  697. */
  698. REG_OP(MirrorPadGrad)
  699. .INPUT(x, TensorType({ DT_INT8, DT_UINT8, DT_INT16, DT_UINT16, \
  700. DT_INT32, DT_INT64, DT_FLOAT16, DT_FLOAT, DT_DOUBLE }))
  701. .INPUT(paddings, TensorType({DT_INT32, DT_INT64}))
  702. .OUTPUT(y, TensorType({ DT_INT8, DT_UINT8, DT_INT16, DT_UINT16, \
  703. DT_INT32, DT_INT64, DT_FLOAT16, DT_FLOAT, DT_DOUBLE }))
  704. .REQUIRED_ATTR(mode, String)
  705. .OP_END_FACTORY_REG(MirrorPadGrad)
  706. REG_OP(Where)
  707. .INPUT(x, TensorType({DT_DOUBLE, DT_FLOAT, DT_FLOAT16, DT_INT8, DT_UINT8, DT_INT16, \
  708. DT_UINT16, DT_INT32, DT_UINT32, DT_INT64, DT_UINT64, DT_BOOL}))
  709. .OUTPUT(y, TensorType({DT_INT64}))
  710. .OP_END_FACTORY_REG(Where)
  711. } // namespace ge
  712. #endif // GE_OP_ARRAY_OPS_H_

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

Contributors (1)