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.

matrix_calculation_ops.h 39 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
4 years ago
5 years ago
5 years ago
5 years ago
4 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
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
4 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101
  1. /**
  2. * Copyright 2020 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /*!
  17. * \file matrix_calculation_ops.h
  18. * \brief
  19. */
  20. #ifndef OPS_BUILT_IN_OP_PROTO_INC_MATRIX_CALCULATION_OPS_H_
  21. #define OPS_BUILT_IN_OP_PROTO_INC_MATRIX_CALCULATION_OPS_H_
  22. #include "graph/operator_reg.h"
  23. namespace ge {
  24. /**
  25. *@brief Multiplies matrix "a" by matrix "b", producing "a * b" . \n
  26. *@par Inputs:
  27. *Three inputs, including:
  28. * @li x1: A matrix Tensor. 2D. Must be one of the following types: float16,
  29. * float32, int32. Has format [ND, NHWC, FRACTAL_NZ].
  30. * @li x2: A matrix Tensor. 2D. Must be one of the following types: float16,
  31. * float32, int32. Has format [ND, NHWC, FRACTAL_NZ].
  32. * @li bias: A optional 1D Tensor. Must be one of the following types: float16,
  33. * float32, int32. Has format [ND, NHWC] . \n
  34. *@par Attributes:
  35. *@li transpose_x1: A bool. If True, changes the shape of "x1" from [M, K] to [K, M].
  36. *@li transpose_x2: A bool. If True, changes the shape of "x2" from [M, K] to [K, M] . \n
  37. *@par Outputs:
  38. *y: The result matrix Tensor. 2D. Must be one of the following types: float16,
  39. * float32, int32. Has format [ND, NHWC, FRACTAL_NZ] . \n
  40. *@par Third-party framework compatibility
  41. * Compatible with the TensorFlow operator BatchMatmul.
  42. */
  43. REG_OP(MatMul)
  44. .INPUT(x1, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
  45. .INPUT(x2, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
  46. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
  47. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
  48. .ATTR(transpose_x1, Bool, false)
  49. .ATTR(transpose_x2, Bool, false)
  50. .OP_END_FACTORY_REG(MatMul)
  51. /**
  52. *@brief Multiplies matrix "a" by matrix "b", producing "a * b" . \n
  53. *@par Inputs:
  54. *Two inputs, including:
  55. * @li x1: A matrix Tensor. 2D. Must be one of the following types: float16,
  56. * float32, int32. Has format [ND, NHWC, FRACTAL_NZ].
  57. * @li x2: A matrix Tensor. 2D. Must be one of the following types: float16,
  58. * float32, int32. Has format [ND, NHWC, FRACTAL_NZ].
  59. * @li bias: A 1D Tensor. Must be one of the following types: float16,
  60. * float32, int32. Has format [ND, NHWC] . \n
  61. *@par Attributes:
  62. *@li transpose_x1: A bool. If True, changes the shape of "x1" from [M, K] to [K, M].
  63. *@li transpose_x2: A bool. If True, changes the shape of "x2" from [M, K] to [K, M] . \n
  64. *@par Outputs:
  65. *y: The result matrix Tensor. 2D. Must be one of the following types: float16,
  66. * float32, int32. Has format [ND, NHWC, FRACTAL_NZ] . \n
  67. *@par Third-party framework compatibility
  68. * Compatible with the TensorFlow operator BatchMatmul.
  69. */
  70. REG_OP(MatMulV2)
  71. .INPUT(x1, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32, DT_INT8}))
  72. .INPUT(x2, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32, DT_INT8}))
  73. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
  74. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
  75. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  76. .ATTR(transpose_x1, Bool, false)
  77. .ATTR(transpose_x2, Bool, false)
  78. .ATTR(offset_x, Int, 0)
  79. .OP_END_FACTORY_REG(MatMulV2)
  80. /**
  81. *@brief Performs Matrix-to-matrix Multiply, producing c=alpha[0]*a*b+beta[0]*c . \n
  82. *@attention Constraints:
  83. * For better performance, The k-axis must be aligned to 16 (input type
  84. * is float16) or 32 (input type is int8). \n
  85. *@par Inputs:
  86. *Five inputs, including:
  87. *@li a: A matrix Tensor. Must be one of the following types: float16, int8.
  88. * Has format [ND, FRACTAL_NZ]. 2D(ND) or 4D(FRACTAL_NZ).
  89. *@li b: A matrix Tensor. Must be one of the following types: float16, int8.
  90. * Has format [ND, FRACTAL_NZ, FRACTAL_Z]. 2D(ND) or 4D(FRACTAL_NZ, FRACTAL_Z).
  91. *@li c: A matrix Tensor. Must be one of the following types: float16, int32,
  92. * float32. has format [ND, FRACTAL_NZ]. 2D(ND) or 4D(FRACTAL_NZ).
  93. *@li alpha: A 1D Tensor. The shape of alpha is [1].Must be one of the following
  94. * types: float16, int32, float32. Has format [ND].
  95. *@li beta: A 1D Tensor. The shape of beta is [1]. Must be one of the following
  96. * types: float16, int32, float32. Has format [ND].
  97. * The format of a, b, c has restriction:\n
  98. * When type of a is int8 and type of c is int32, the format of a, b, c should
  99. * all be ND, or a is FRACTAL_NZ and b is FRACTAL_Z and c is ND.\n
  100. * When type of a is int8 and type of c is float32, the format of a, b, c should
  101. * all be ND or a is FRACTAL_NZ and b is FRACTAL_Z and c is FRACTAL_NZ.\n
  102. * When type of a is float16 and type of c is float16, the format of a, b, c
  103. * should all be ND or FRACTAL_NZ.\n
  104. * When type of a is float16 and type of c is float32, the format of a, b, c
  105. * should all be ND or FRACTAL_NZ . \n
  106. *@par Attributes:
  107. *Two attributes, including:
  108. *@li transpose_a: Optional. A bool. If True, changes the shape of "a" from
  109. * [M, K] to [K, M].
  110. *@li transpose_b: Optional. A bool. If True, changes the shape of "b" from
  111. * [K, N] to [N, K] . \n
  112. *@par Outputs:
  113. *y: The result matrix Tensor. Must be one of the following types: float16,
  114. * float32, int32. Has format [ND, FRACTAL_NZ], the format should be equal to a.
  115. * 2D(ND) or 4D(FRACTAL_NZ).
  116. */
  117. REG_OP(GEMM)
  118. .INPUT(a, TensorType({DT_FLOAT16, DT_INT8}))
  119. .INPUT(b, TensorType({DT_FLOAT16, DT_INT8}))
  120. .INPUT(c, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
  121. .INPUT(alpha, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
  122. .INPUT(beta, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
  123. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
  124. .ATTR(transpose_a, Bool, false)
  125. .ATTR(transpose_b, Bool, false)
  126. .OP_END_FACTORY_REG(GEMM)
  127. /**
  128. *@brief Multiplies matrix "a" by matrix "b", producing "a * b" . \n
  129. *@par Inputs:
  130. *Three inputs, including:
  131. * @li x1: A matrix Tensor. Must be one of the following types: float16,
  132. * float32, int32. 2D or higher. Has format [ND, NHWC, FRACTAL_NZ].
  133. * @li x2: A matrix Tensor. Must be one of the following types: float16,
  134. * float32, int32. 2D or higher. Has format [ND, NHWC, FRACTAL_NZ] . \n
  135. *@par Attributes:
  136. *@li adj_x1: A bool. If True, changes the shape of "x1" from [B, M, K] to [B, K, M].
  137. *@li adj_x2: A bool. If True, changes the shape of "x2" from [B, M, K] to [B, K, M] . \n
  138. *@par Outputs:
  139. *y: The result matrix Tensor. 2D or higher. Must be one of the following types: float16,
  140. * float32, int32. 2D or higher. Has format [ND, NHWC, FRACTAL_NZ]. Has the same shape length as "x1" and "x2" . \n
  141. *@par Third-party framework compatibility
  142. * Compatible with the TensorFlow operator BatchMatmul.
  143. */
  144. REG_OP(BatchMatMul)
  145. .INPUT(x1, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
  146. .INPUT(x2, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
  147. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
  148. .ATTR(adj_x1, Bool, false)
  149. .ATTR(adj_x2, Bool, false)
  150. .OP_END_FACTORY_REG(BatchMatMul)
  151. /**
  152. * @brief Multiplies matrix "a" by matrix "b", producing "a * b" . \n
  153. * @par Inputs:
  154. * Three inputs, including:
  155. * @li x1: A matrix Tensor. Must be one of the following types: float16,
  156. * float32, int32. 2D or higher. Has format [ND, NHWC, FRACTAL_NZ].
  157. * @li x2: A matrix Tensor. Must be one of the following types: float16,
  158. * float32, int32. 2D or higher. Has format [ND, NHWC, FRACTAL_NZ] . \n
  159. * @li bias: A matrix Tensor. Must be one of the following types: float16,
  160. * float32, int32. 2D or higher. Has format [ND, NHWC, FRACTAL_NZ] . \n
  161. * @par Attributes:
  162. * @li adj_x: A bool. If True, changes the shape of "x1" from [B, M, K] to [B, K, M].
  163. * @li adj_y: A bool. If True, changes the shape of "x2" from [B, M, K] to [B, K, M] . \n
  164. * @par Outputs:
  165. * y: The result matrix Tensor. 2D or higher. Must be one of the following types: float16,
  166. * float32, int32. 2D or higher. Has format [ND, NHWC, FRACTAL_NZ]. Has the same shape length as "x1" and "x2" . \n
  167. * @par Third-party framework compatibility
  168. * Compatible with the TensorFlow operator BatchMatmul.
  169. */
  170. REG_OP(BatchMatMulV2)
  171. .INPUT(x1, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
  172. .INPUT(x2, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
  173. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
  174. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
  175. .ATTR(adj_x1, Bool, false)
  176. .ATTR(adj_x2, Bool, false)
  177. .OP_END_FACTORY_REG(BatchMatMulV2)
  178. /**
  179. *@brief Computes half the L2 norm of a tensor without the sqrt . \n
  180. *@par Inputs:
  181. * x: A Tensor.
  182. * TensorType::FloatingDataType() . \n
  183. *@par Outputs:
  184. *y: A Tensor. Has the same type as "x".
  185. *@par Third-party framework compatibility
  186. *Compatible with the TensorFlow operator L2Loss.
  187. */
  188. REG_OP(L2Loss)
  189. .INPUT(x, TensorType::FloatingDataType())
  190. .OUTPUT(y, TensorType::FloatingDataType())
  191. .OP_END_FACTORY_REG(L2Loss)
  192. /**
  193. *@brief: Returns a batched diagonal tensor with a given batched diagonal values . \n
  194. *@par Inputs:
  195. *x: A Tensor. Must be one of the following types:
  196. * float16, float32, double, int32, uint8, int16, int8, complex64, int64,
  197. * qint8, quint8, qint32, uint16, complex128, uint32, uint64 . \n
  198. *@par Outputs:
  199. *y: A Tensor. Has the same type as "x" . \n
  200. *@par Third-party framework compatibility
  201. * Compatible with the TensorFlow operator MatrixDiag.
  202. */
  203. REG_OP(MatrixDiag)
  204. .INPUT(x, TensorType::BasicType())
  205. .OUTPUT(y, TensorType::BasicType())
  206. .OP_END_FACTORY_REG(MatrixDiag)
  207. /**
  208. *@brief: Returns a batched diagonal tensor with a given batched diagonal values . \n
  209. *@par Inputs:
  210. * Two inputs, including:
  211. *@li x: A Tensor. Must be one of the following types: float16, float32, int32, int8, uint8.
  212. *@li assist: A Tensor of the same type as "x" . \n
  213. *@par Outputs:
  214. *y: A Tensor. Has the same type as "x" . \n
  215. *@par Third-party framework compatibility
  216. * Compatible with the TensorFlow operator MatrixDiag.
  217. *
  218. * @par Restrictions:
  219. * Warning: THIS FUNCTION IS DEPRECATED. Please use MatrixDiag instead.
  220. */
  221. REG_OP(MatrixDiagD)
  222. .INPUT(x, TensorType::BasicType())
  223. .INPUT(assist, TensorType::BasicType())
  224. .OUTPUT(y, TensorType::BasicType())
  225. .OP_END_FACTORY_REG(MatrixDiagD)
  226. /**
  227. *@brief: Returns the batched diagonal part of a batched tensor . \n
  228. *@par Inputs:
  229. *x: A Tensor. Must be one of the following types:
  230. * float16, float32, double, int32, uint8, int16, int8, complex64, int64,
  231. * qint8, quint8, qint32, uint16, complex128, uint32, uint64 . \n
  232. *@par Outputs:
  233. *y: A Tensor. Has the same type as "x" . \n
  234. *@par Third-party framework compatibility
  235. * Compatible with the TensorFlow operator MatrixDiagPart.
  236. */
  237. REG_OP(MatrixDiagPart)
  238. .INPUT(x, TensorType::BasicType())
  239. .OUTPUT(y, TensorType::BasicType())
  240. .OP_END_FACTORY_REG(MatrixDiagPart)
  241. /**
  242. *@brief: Returns the batched diagonal part of a batched tensor . \n
  243. *@par Inputs:
  244. * Two inputs, including:
  245. *@li x: A Tensor. Must be one of the following types: float16, float32, int32, int8, uint8.
  246. *@li assist: A Tensor of the same type as "x" . \n
  247. *@par Outputs:
  248. *y: A Tensor. Has the same type as "x" . \n
  249. *@par Third-party framework compatibility
  250. * Compatible with the TensorFlow operator MatrixDiagPart.
  251. *
  252. * @par Restrictions:
  253. * Warning: THIS FUNCTION IS DEPRECATED. Please use MatrixDiagPart instead.
  254. */
  255. REG_OP(MatrixDiagPartD)
  256. .INPUT(x, TensorType::BasicType())
  257. .INPUT(assist, TensorType::BasicType())
  258. .OUTPUT(y, TensorType::BasicType())
  259. .OP_END_FACTORY_REG(MatrixDiagPartD)
  260. /**
  261. *@brief: Returns a batched matrix tensor with new batched diagonal values . \n
  262. *@par Inputs:
  263. * Two inputs, including:
  264. *@li x: A Tensor. Must be one of the following types:
  265. * float16, float32, double, int32, uint8, int16, int8, complex64, int64,
  266. * qint8, quint8, qint32, uint16, complex128, uint32, uint64.
  267. *@li diagonal: A Tensor of the same type as "x" . \n
  268. *@par Outputs:
  269. *y: A Tensor. Has the same type as "x" . \n
  270. *@par Third-party framework compatibility
  271. * Compatible with the TensorFlow operator MatrixSetDiag.
  272. */
  273. REG_OP(MatrixSetDiag)
  274. .INPUT(x, TensorType::BasicType())
  275. .INPUT(diagonal, TensorType::BasicType())
  276. .OUTPUT(y, TensorType::BasicType())
  277. .OP_END_FACTORY_REG(MatrixSetDiag)
  278. /**
  279. *@brief: Returns a batched matrix tensor with new batched diagonal values . \n
  280. *@par Inputs:
  281. * Three inputs, including:
  282. *@li x: A Tensor. Must be one of the following types: float16, float32, int32, int8, uint8.
  283. *@li diagonal: A Tensor of the same type as "x".
  284. *@li assist: A Tensor of the same type as "x" . \n
  285. *@par Outputs:
  286. *y: A Tensor. Has the same type as "x" . \n
  287. *@par Third-party framework compatibility
  288. * Compatible with the TensorFlow operator MatrixSetDiag.
  289. *
  290. * @par Restrictions:
  291. * Warning: THIS FUNCTION IS DEPRECATED. Please use MatrixSetDiag instead.
  292. */
  293. REG_OP(MatrixSetDiagD)
  294. .INPUT(x, TensorType::BasicType())
  295. .INPUT(diagonal, TensorType::BasicType())
  296. .INPUT(assist, TensorType::BasicType())
  297. .OUTPUT(y, TensorType::BasicType())
  298. .OP_END_FACTORY_REG(MatrixSetDiagD)
  299. /**
  300. *@brief Applies sparse "updates" to individual values or slices in a Variable . \n
  301. *@par Inputs:
  302. * Three inputs, including:
  303. *@li var: An ND Tensor.
  304. *Must be one of the following types: float16, float32, int8, uint8, double,
  305. * int64, complex64, qint8, quint8, qint32, uint16, complex128, half, uint32,
  306. * uint64
  307. *@li indices: An ND Tensor.
  308. *Must be one of the following types: int32, int64
  309. *@li updates: An ND Tensor.
  310. *Must be one of the following types: float16, float32, int8, uint8, double,
  311. * int64, complex64, qint8, quint8, qint32, uint16, complex128, half, uint32,
  312. * uint64
  313. *@par Attributes:
  314. *use_locking: An optional bool. Defaults to "False". If "True",
  315. * the operation will be protected by a lock . \n
  316. *@par Outputs:
  317. *var: A Tensor. Has the same type and format as input "var" . \n
  318. *@par Third-party framework compatibility
  319. * Compatible with the TensorFlow operator ScatterNdUpdate.
  320. */
  321. REG_OP(ScatterNdUpdate)
  322. .INPUT(var, TensorType::BasicType())
  323. .INPUT(indices, TensorType::IndexNumberType())
  324. .INPUT(updates, TensorType::BasicType())
  325. .OUTPUT(var, TensorType::BasicType())
  326. .ATTR(use_locking, Bool, false)
  327. .OP_END_FACTORY_REG(ScatterNdUpdate)
  328. /**
  329. *@brief Applies sparse addition to individual values or slices in a Variable . \n
  330. *@par Inputs:
  331. * Three inputs, including:
  332. *@li x: An ND Tensor. \n
  333. *Must be one of the following types: float16, float32, bool, int8, uint8
  334. *@li indices: An ND Tensor. \n
  335. *Must be one of the following types: int32
  336. *@li updates: An ND Tensor. \n
  337. *Must be one of the following types: float16, float32, bool, int8, uint8
  338. *@par Outputs:
  339. *y: A Tensor. Has the same type and format as input "x" . \n
  340. *@par Third-party framework compatibility
  341. * Compatible with the TensorFlow operator TensorScatterUpdate.
  342. */
  343. REG_OP(TensorScatterUpdate)
  344. .INPUT(x, TensorType::BasicType())
  345. .INPUT(indices, TensorType::IndexNumberType())
  346. .INPUT(updates, TensorType::BasicType())
  347. .OUTPUT(y, TensorType::BasicType())
  348. .OP_END_FACTORY_REG(TensorScatterUpdate)
  349. /**
  350. *@brief Adds sparse "updates" to a variable reference . \n
  351. *@par Inputs:
  352. * Three inputs, including:
  353. *@li var: An ND Tensor . \n
  354. *Must be one of the following types: float16, float32, int32, int8, uint8
  355. *@li indices: An ND Tensor of type int32 or int64.
  356. *@li updates: An Tensor. format:NCHW, NHWC . \n
  357. *Must be one of the following types: float16, float32, int32, int8, uint8
  358. *@par Attributes:
  359. * use_locking: An optional bool. Defaults to "False". If "True", the operation
  360. * will be protected by a lock . \n
  361. *@par Outputs:
  362. *var: A Tensor. Has the same type and format as input "var" . \n
  363. *@par Third-party framework compatibility
  364. * Compatible with the TensorFlow operator ScatterAdd.
  365. */
  366. REG_OP(ScatterAdd)
  367. .INPUT(var, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  368. .INPUT(indices, TensorType::IndexNumberType())
  369. .INPUT(updates, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  370. .OUTPUT(var, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  371. .ATTR(use_locking, Bool, false)
  372. .OP_END_FACTORY_REG(ScatterAdd)
  373. /**
  374. *@brief Divides a variable reference by sparse updates . \n
  375. *@par Inputs:
  376. * Three inputs, including:
  377. *@li var: An ND Tensor.
  378. *Must be one of the following types: float16, float, int32, int8, uint8
  379. *@li indices: An ND Tensor.
  380. *Must be one of the following types: int32
  381. *@li updates: An ND Tensor.
  382. *Must be one of the following types: float16, float, int32, int8, uint8
  383. *@par Attributes:
  384. *@li use_locking: An optional bool. Defaults to "False". If "True",
  385. * the operation will be protected by a lock . \n
  386. *@par Outputs:
  387. *var: A Tensor. Has the same type and format as input "var" . \n
  388. *@par Third-party framework compatibility
  389. * Compatible with the TensorFlow operator ScatterDiv.
  390. */
  391. REG_OP(ScatterDiv)
  392. .INPUT(var, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  393. .INPUT(indices, TensorType({DT_INT32}))
  394. .INPUT(updates, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  395. .OUTPUT(var, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  396. .ATTR(use_locking, Bool, false)
  397. .OP_END_FACTORY_REG(ScatterDiv)
  398. /**
  399. *@brief Applies sparse addition to individual values or slices in a Variable . \n
  400. *@par Inputs:
  401. * Three inputs, including:
  402. *@li var: An ND Tensor.
  403. *Must be one of the following types: float16, float, int32, int8, uint8
  404. *@li indices: An ND Tensor.
  405. *Must be one of the following types: int32
  406. *@li updates: An ND Tensor.
  407. *Must be one of the following types: float16, float, int32, int8, uint8
  408. *@par Attributes:
  409. *use_locking: An optional bool. Defaults to "False". If "True",
  410. * the operation will be protected by a lock . \n
  411. *@par Outputs:
  412. *var: A Tensor. Has the same type and format as input "var" . \n
  413. *@par Third-party framework compatibility
  414. * Compatible with the TensorFlow operator ScatterNdAdd.
  415. */
  416. REG_OP(ScatterNdAdd)
  417. .INPUT(var, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  418. .INPUT(indices, TensorType::IndexNumberType())
  419. .INPUT(updates, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  420. .OUTPUT(var, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  421. .ATTR(use_locking, Bool, false)
  422. .OP_END_FACTORY_REG(ScatterNdAdd)
  423. /**
  424. *@brief Applies sparse addition to individual values or slices in a Variable . \n
  425. *@par Inputs:
  426. * Three inputs, including:
  427. *@li x: An ND Tensor. \n
  428. *Must be one of the following types: float16, float32, int32, int8, uint8
  429. *@li indices: An ND Tensor. \n
  430. *Must be one of the following types: int32
  431. *@li updates: An ND Tensor. \n
  432. * Must be one of the following types: float16, float32, int32, int8, uint8
  433. *@par Outputs:
  434. *y: A Tensor. Has the same type and format as input "x" . \n
  435. *@par Third-party framework compatibility
  436. * Compatible with the TensorFlow operator TensorScatterAdd.
  437. */
  438. REG_OP(TensorScatterAdd)
  439. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  440. .INPUT(indices, TensorType::IndexNumberType())
  441. .INPUT(updates, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  442. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  443. .OP_END_FACTORY_REG(TensorScatterAdd)
  444. /**
  445. *@brief Applies sparse subtraction to individual values or slices in a Variable . \n
  446. *@par Inputs:
  447. * Three inputs, including:
  448. *@li var: An ND Tensor.
  449. *Must be one of the following types: float16, float, int32, int8, uint8
  450. *@li indices: An ND Tensor.
  451. *Must be one of the following types: int32, int64
  452. *@li updates: An ND Tensor.
  453. *Must be one of the following types: float16, float, int32, int8, uint8
  454. *@par Attributes:
  455. *use_locking: An optional bool. Defaults to "False". If "True",
  456. * the operation will be protected by a lock . \n
  457. *@par Outputs:
  458. * var: A Tensor. Has the same type and format as input "var" . \n
  459. *@par Third-party framework compatibility
  460. * Compatible with the TensorFlow operator ScatterNdSub.
  461. */
  462. REG_OP(ScatterNdSub)
  463. .INPUT(var, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  464. .INPUT(indices, TensorType::IndexNumberType())
  465. .INPUT(updates, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  466. .OUTPUT(var, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  467. .ATTR(use_locking, Bool, false)
  468. .OP_END_FACTORY_REG(ScatterNdSub)
  469. /**
  470. *@brief Applies sparse addition to individual values or slices in a Variable . \n
  471. *@par Inputs:
  472. * Three inputs, including:
  473. *@li x: An ND Tensor. \n
  474. *Must be one of the following types: float16, float32, int32, int8, uint8
  475. *@li indices: An ND Tensor. \n
  476. *Must be one of the following types: int32
  477. *@li updates: An ND Tensor. \n
  478. *Must be one of the following types: float16, float32, int32, int8, uint8
  479. *@par Outputs:
  480. * y: A Tensor. Has the same type and format as input "x" . \n
  481. *@par Third-party framework compatibility
  482. * Compatible with the TensorFlow operator TensorScatterSub.
  483. */
  484. REG_OP(TensorScatterSub)
  485. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  486. .INPUT(indices, TensorType::IndexNumberType())
  487. .INPUT(updates, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  488. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  489. .OP_END_FACTORY_REG(TensorScatterSub)
  490. /**
  491. *@brief Subtracts sparse updates to a variable reference . \n
  492. *@par Inputs:
  493. * Three inputs, including:
  494. *@li var: An ND Tensor.
  495. *Must be one of the following types: float16, float, int32, int8, uint8
  496. *@li indices: An ND Tensor.
  497. *Must be one of the following types: int32, int64
  498. *@li updates: An ND Tensor.
  499. *Must be one of the following types: float16, float, int32, int8, uint8
  500. *@par Attributes:
  501. *use_locking: An optional bool. Defaults to "False". If "True",
  502. * the operation will be protected by a lock . \n
  503. *@par Outputs:
  504. * var: A Tensor. Has the same type and format as input "var" . \n
  505. *@par Third-party framework compatibility
  506. * Compatible with the TensorFlow operator ScatterSub.
  507. */
  508. REG_OP(ScatterSub)
  509. .INPUT(var, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  510. .INPUT(indices, TensorType::IndexNumberType())
  511. .INPUT(updates, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  512. .OUTPUT(var, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  513. .ATTR(use_locking, Bool, false)
  514. .OP_END_FACTORY_REG(ScatterSub)
  515. /**
  516. *@brief: Returns the batched diagonal part of a batched tensor with "assist" . \n
  517. *@par Inputs:
  518. * Two inputs, including:
  519. * @li x: A Tensor of type float16, float32, or int32.
  520. * @li assist: A Tensor of the same type as "x" . \n
  521. *@par Outputs:
  522. *y: A Tensor. Has the same type as "x" . \n
  523. *@par Third-party framework compatibility
  524. * Compatible with the TensorFlow operator DiagPart.
  525. *
  526. * @par Restrictions:
  527. * Warning: THIS FUNCTION IS DEPRECATED. Please use DiagPart instead.
  528. */
  529. REG_OP(DiagPartD)
  530. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
  531. .INPUT(assist, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
  532. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
  533. .OP_END_FACTORY_REG(DiagPartD)
  534. /**
  535. *@brief: Returns the batched diagonal part of a batched tensor . \n
  536. *@par Inputs:
  537. *x: A Tensor. Must be one of the following types:
  538. * float16, float32, int32, int64, double, complex64, complex128 . \n
  539. *@par Outputs:
  540. *y: A Tensor. Has the same type as "x" . \n
  541. *@par Third-party framework compatibility
  542. * Compatible with the TensorFlow operator DiagPart.
  543. */
  544. REG_OP(DiagPart)
  545. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32, DT_INT64, DT_DOUBLE,
  546. DT_COMPLEX64, DT_COMPLEX128}))
  547. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32, DT_INT64, DT_DOUBLE,
  548. DT_COMPLEX64, DT_COMPLEX128}))
  549. .OP_END_FACTORY_REG(DiagPart)
  550. /**
  551. *@brief Also known as a "fully-connected" layer, computes an inner product with a set of learned weights, and (optionally) adds biases . \n
  552. *@par Inputs:
  553. * Four inputs, including:
  554. *@li x: A Tensor of type float16, int8.
  555. *@li w: A weight matrix of type float16, int8.
  556. *@li b: A Tensor of type float16, int32, float32.
  557. *@li offset_w: A Tensor of type int8 . \n
  558. *@par Attributes:
  559. *@li num_output: Reserved.
  560. *@li transpose: A bool, specifying weight whether to transpose, either "true" or "false". Defaults to "false".
  561. *@li axis: Optional. A int, 1 or 2, specifying which dimension the input "K" starts from. Defaults to 1.
  562. * The product of the subsequent dimensions starting form first dimension or the second dimension is "K".
  563. *@li offset_x: Reserved . \n
  564. *@par Outputs:
  565. *y: The result tensor of type float16, int32, float32 . \n
  566. *@par Third-party framework compatibility
  567. * Compatible with the Caffe operator InnerProduct . \n
  568. *@par Quantization supported or not
  569. * Yes
  570. */
  571. REG_OP(FullyConnection)
  572. .INPUT(x, TensorType({DT_FLOAT16, DT_INT8}))
  573. .INPUT(w, TensorType({DT_FLOAT16, DT_INT8}))
  574. .OPTIONAL_INPUT(b, TensorType({DT_FLOAT16, DT_INT32,DT_FLOAT32}))
  575. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  576. .OUTPUT(y, TensorType({DT_FLOAT16, DT_INT32,DT_FLOAT32}))
  577. .REQUIRED_ATTR(num_output, Int)
  578. .ATTR(transpose, Bool, false)
  579. .ATTR(axis, Int, 1)
  580. .ATTR(offset_x, Int, 0)
  581. .OP_END_FACTORY_REG(FullyConnection)
  582. /**
  583. *@brief Also known as a "fully-connected-compress" layer, computes an inner product with a set of learned weights, and (optionally) adds biases . \n
  584. *@par Inputs:
  585. * Four inputs, including:
  586. *@li x: A Tensor of type uint8, int8.
  587. *@li w: A weight matrix of type int8, int8.
  588. *@li w: A compress index matrix of type int8, int8.
  589. *@li b: A Tensor of type float16, int32, int32.
  590. *@li offset_w: A Tensor of type int8.i
  591. *@par Attributes:
  592. *@li num_output: Reserved.
  593. *@li transpose: A bool, specifying whether to transpose, either "true" or "false". Defaults to "false".
  594. *@li axis: Reserved.
  595. *@li offset_x: Reserved . \n
  596. *@par Outputs:
  597. *y: The result tensor of type int32 . \n
  598. *@par Third-party framework compatibility
  599. * Compatible with the Caffe operator InnerProduct . \n
  600. *@par Quantization supported or not
  601. * Yes
  602. */
  603. REG_OP(FullyConnectionCompress)
  604. .INPUT(x, TensorType({DT_UINT8, DT_INT8}))
  605. .INPUT(w, TensorType({DT_INT8}))
  606. .INPUT(comress_index, TensorType({DT_INT8}))
  607. .OPTIONAL_INPUT(b, TensorType({DT_INT32}))
  608. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  609. .OUTPUT(y, TensorType({DT_INT32}))
  610. .REQUIRED_ATTR(num_output, Int)
  611. .ATTR(transpose, Bool, false)
  612. .ATTR(axis, Int, 1)
  613. .ATTR(offset_x, Int, 0)
  614. .OP_END_FACTORY_REG(FullyConnectionCompress)
  615. /**
  616. *@brief Computes the confusion matrix from predictions and labels . \n
  617. *@par Inputs:
  618. * Three inputs, including:
  619. *@li labels: A Tensor. Must be one of the following types: float16, float32,
  620. * int32, int8, uint8.
  621. *@li predictions: A Tensor. Must be one of the following types: float16,
  622. * float32, int32, int8, uint8.
  623. *@li weights: A Tensor. Must be one of the following types: float16, float32,
  624. * int32, int8, uint8 . \n
  625. *@par Attributes:
  626. *@li num_classes: An integer for the shape of the output matrix.
  627. * No default value.
  628. *@li dtype: Data type of the confusion matrix. No default value . \n
  629. *@par Outputs:
  630. *y: A Tensor. Has the same type and format as input "labels"
  631. *@attention Constraints:
  632. *@li "weights", "labels", and "predictions" are 1D tensors.
  633. *@li The output is with shape (num_classes, num_classes),
  634. * where, 1 <= num_classes <= 4096 . \n
  635. *@see Region()
  636. *@par Third-party framework compatibility
  637. * Compatible with the TensorFlow operator ConfusionMatrix.
  638. */
  639. REG_OP(ConfusionMatrix)
  640. .INPUT(labels, TensorType({DT_FLOAT, DT_INT32, DT_FLOAT16, DT_INT8, DT_UINT8}))
  641. .INPUT(predictions, TensorType({DT_FLOAT, DT_INT32, DT_FLOAT16, DT_INT8, DT_UINT8}))
  642. .OPTIONAL_INPUT(weights, TensorType({DT_FLOAT, DT_INT32, DT_FLOAT16, DT_INT8, DT_UINT8}))
  643. .OUTPUT(y, TensorType({DT_FLOAT, DT_INT32, DT_FLOAT16, DT_INT8, DT_UINT8}))
  644. .REQUIRED_ATTR(num_classes, Int)
  645. .REQUIRED_ATTR(dtype, String)
  646. .OP_END_FACTORY_REG(ConfusionMatrix)
  647. /**
  648. *@brief Multiplies sparse updates into a variable reference . \n
  649. *@par Inputs:
  650. * Three inputs, including:
  651. *@li var: An ND Tensor.
  652. *Must be one of the following types: float16, float, int32, int8, uint8
  653. *@li indices: An ND Tensor.
  654. *Must be one of the following types: int32
  655. *@li updates: An ND Tensor . \n
  656. *Must be one of the following types: float16, float, int32, int8, uint8
  657. *@par Attributes:
  658. *use_locking: An optional bool. Defaults to "False". If "True", the operation
  659. * will be protected by a lock . \n
  660. *@par Outputs:
  661. *var: A Tensor. Has the same type and format as input "var" . \n
  662. *@par Third-party framework compatibility
  663. * Compatible with the TensorFlow operator ScatterMul.
  664. */
  665. REG_OP(ScatterMul)
  666. .INPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  667. .INPUT(indices, TensorType({DT_INT32}))
  668. .INPUT(updates, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  669. .OUTPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  670. .ATTR(use_locking, Bool, false)
  671. .OP_END_FACTORY_REG(ScatterMul)
  672. /**
  673. *@brief Reduces sparse updates into a variable reference using
  674. * the "min" operation . \n
  675. *@par Inputs:
  676. * Three inputs, including:
  677. *@li var: An ND Tensor.
  678. *Must be one of the following types: float16, float, int32
  679. *@li indices: An ND Tensor.
  680. *Must be one of the following types: int32
  681. *@li updates: An ND Tensor.
  682. *Must be one of the following types: float16, float, int32
  683. *@par Attributes:
  684. *use_locking: An optional bool. Defaults to "False". If "True", the operation
  685. * will be protected by a lock . \n
  686. *@par Outputs:
  687. *var: A Tensor. Has the same type and format as input "var" . \n
  688. *@par Third-party framework compatibility
  689. * Compatible with the TensorFlow operator ScatterMin.
  690. */
  691. REG_OP(ScatterMin)
  692. .INPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32}))
  693. .INPUT(indices, TensorType({DT_INT32}))
  694. .INPUT(updates, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32}))
  695. .OUTPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32}))
  696. .ATTR(use_locking, Bool, false)
  697. .OP_END_FACTORY_REG(ScatterMin)
  698. /**
  699. *@brief Reduces sparse updates into a variable reference using the "max" operation . \n
  700. *@par Inputs:
  701. * Three inputs, including:
  702. *@li var: An ND Tensor . \n
  703. *Must be one of the following types: float16, float, int32
  704. *@li indices: An NCHW, NHWC, or ND Tensor . \n
  705. *Must be one of the following types: int32
  706. *@li updates: An NCHW, NHWC, or ND Tensor . \n
  707. *Must be one of the following types: float16, float, int32
  708. *@par Attributes:
  709. *use_locking: An optional bool. Defaults to "False".
  710. * If "True", the operation will be protected by a lock . \n
  711. *@par Outputs:
  712. *var: A Tensor. Has the same type and format as input "var" . \n
  713. *@par Third-party framework compatibility
  714. * Compatible with the TensorFlow operator ScatterMax.
  715. */
  716. REG_OP(ScatterMax)
  717. .INPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32}))
  718. .INPUT(indices, TensorType({DT_INT32}))
  719. .INPUT(updates, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32}))
  720. .OUTPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32}))
  721. .ATTR(use_locking, Bool, false)
  722. .OP_END_FACTORY_REG(ScatterMax)
  723. /**
  724. *@brief Applies sparse updates to a variable reference . \n
  725. *@par Inputs:
  726. * Three inputs, including:
  727. *@li var: An ND Tensor . \n
  728. *Must be one of the following types: float16, float, int32, int8, uint8
  729. *@li indices: An ND Tensor . \n
  730. *Must be one of the following types: int32
  731. *@li updates: An ND Tensor . \n
  732. *Must be one of the following types: float16, float, int32, int8, uint8
  733. *@par Attributes:
  734. *use_locking: An optional bool. Defaults to "False". If "True",
  735. * the operation will be protected by a lock . \n
  736. *@par Outputs:
  737. *var: A Tensor. Has the same type and format as input "var" . \n
  738. *@par Third-party framework compatibility
  739. * Compatible with the TensorFlow operator ScatterUpdate.
  740. */
  741. REG_OP(ScatterUpdate)
  742. .INPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT8,DT_UINT8}))
  743. .INPUT(indices, TensorType({DT_INT32}))
  744. .INPUT(updates, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT8,DT_UINT8}))
  745. .OUTPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT8,DT_UINT8}))
  746. .ATTR(use_locking, Bool, false)
  747. .OP_END_FACTORY_REG(ScatterUpdate)
  748. /**
  749. *@brief Returns a tensor with the `k[0]`-th to `k[1]`-th diagonals of the batched `input` . \n
  750. *@par Inputs:
  751. * Three inputs, including:
  752. *@li input: Rank `r` tensor where `r >= 2`. \n
  753. *@li k: \n
  754. *Diagonal offset(s). Positive value means superdiagonal, 0 refers to the main \n
  755. *diagonal, and negative value means subdiagonals. `k` can be a single integer \n
  756. *(for a single diagonal) or a pair of integers specifying the low and high ends \n
  757. *of a matrix band. `k[0]` must not be larger than `k[1]`. \n
  758. *@li padding_value: The value to fill the area outside the specified diagonal band with. \n
  759. *@par Outputs:
  760. *diagonal: The extracted diagonal(s) . \n
  761. *@par Third-party framework compatibility
  762. * Compatible with the TensorFlow operator ScatterUpdate.
  763. */
  764. REG_OP(MatrixDiagPartV2)
  765. .INPUT(input, TensorType::BasicType())
  766. .INPUT(k, TensorType({DT_INT32}))
  767. .INPUT(padding_value, TensorType::BasicType())
  768. .OUTPUT(diagonal, TensorType::BasicType())
  769. .OP_END_FACTORY_REG(MatrixDiagPartV2)
  770. /**
  771. *@brief Returns a batched matrix tensor with new batched diagonal values . \n
  772. *@par Inputs:
  773. * Three inputs, including:
  774. *@li input: "Rank `r+1`, where `r >= 1`. \n
  775. *@li diagonal: Rank `r` when `k` is an integer or `k[0] == k[1]`. Otherwise, it has rank `r+1`. \n
  776. *@li k:
  777. *Diagonal offset(s). Positive value means superdiagonal, 0 refers to the main \n
  778. *diagonal, and negative value means subdiagonals. `k` can be a single integer \n
  779. *(for a single diagonal) or a pair of integers specifying the low and high ends \n
  780. *of a matrix band. `k[0]` must not be larger than `k[1]`. \n
  781. *@par Outputs:
  782. *output: Rank `r+1`, with `output.shape = input.shape` . \n
  783. *@par Third-party framework compatibility
  784. * Compatible with the TensorFlow operator ScatterUpdate.
  785. */
  786. REG_OP(MatrixSetDiagV2)
  787. .INPUT(input, TensorType::BasicType())
  788. .INPUT(diagonal, TensorType::BasicType())
  789. .INPUT(k, TensorType({DT_INT32}))
  790. .OUTPUT(output, TensorType::BasicType())
  791. .OP_END_FACTORY_REG(MatrixSetDiagV2)
  792. /**
  793. *@brief Returns a batched diagonal tensor with given batched diagonal values . \n
  794. *@par Inputs:
  795. * Five inputs, including:
  796. *@li diagonal: Rank `r`, where `r >= 1` \n
  797. *@li k:
  798. *Diagonal offset(s). Positive value means superdiagonal, 0 refers to the main \n
  799. *diagonal, and negative value means subdiagonals. `k` can be a single integer \n
  800. *(for a single diagonal) or a pair of integers specifying the low and high ends \n
  801. *of a matrix band. `k[0]` must not be larger than `k[1]`. \n
  802. *@li num_rows:
  803. *The number of rows of the output matrix. If it is not provided, the op assumes \n
  804. *the output matrix is a square matrix and infers the matrix size from k and the \n
  805. *innermost dimension of `diagonal`. \n
  806. *@li num_cols: An NCHW, NHWC, or ND Tensor.
  807. *The number of columns of the output matrix. If it is not provided, the op \n
  808. *assumes the output matrix is a square matrix and infers the matrix size from \n
  809. *k and the innermost dimension of `diagonal`. \n
  810. *@li padding_value: The number to fill the area outside the specified diagonal band with. \n
  811. *@par Outputs:
  812. *output: Has rank `r+1` when `k` is an integer or `k[0] == k[1]`, rank `r` otherwise . \n
  813. *@par Third-party framework compatibility
  814. * Compatible with the TensorFlow operator ScatterUpdate.
  815. */
  816. REG_OP(MatrixDiagV2)
  817. .INPUT(diagonal, TensorType::BasicType())
  818. .INPUT(k, TensorType({DT_INT32}))
  819. .INPUT(num_rows, TensorType({DT_INT32}))
  820. .INPUT(num_cols, TensorType({DT_INT32}))
  821. .INPUT(padding_value, TensorType::BasicType())
  822. .OUTPUT(output, TensorType::BasicType())
  823. .OP_END_FACTORY_REG(MatrixDiagV2)
  824. REG_OP(IndexAdd)
  825. .INPUT(var, TensorType({DT_INT32, DT_INT8, DT_UINT8, DT_FLOAT32, DT_FLOAT16}))
  826. .INPUT(indices, TensorType({DT_INT32}))
  827. .INPUT(updates, TensorType({DT_INT32, DT_INT8, DT_UINT8, DT_FLOAT32, DT_FLOAT16}))
  828. .OUTPUT(var_out, TensorType({DT_INT32, DT_INT8, DT_UINT8, DT_FLOAT32, DT_FLOAT16}))
  829. .ATTR(axis, Int, 0)
  830. .OP_END_FACTORY_REG(IndexAdd)
  831. /**
  832. *@brief: Returns the upper triangular part of a matrix (2-D tensor) or batch of matrices input \n
  833. *@par Inputs:
  834. * Two inputs, including:
  835. *@li x: A Tensor. Must be one of the following types:
  836. * float16, float32, double, int32, uint8, int16, int8, complex64, int64,
  837. * qint8, quint8, qint32, uint16, complex128, uint32, uint64.
  838. *@li diagonal:(int, optional) – the diagonal to consider。\n
  839. *@par Outputs:
  840. *y: A Tensor. Has the same type as "x" . \n
  841. *@par Third-party framework compatibility
  842. * Compatible with the Pytorch operator Triu.
  843. */
  844. REG_OP(Triu)
  845. .INPUT(x, TensorType::BasicType())
  846. .ATTR(diagonal, Int, 0)
  847. .OUTPUT(y, TensorType::BasicType())
  848. .OP_END_FACTORY_REG(Triu)
  849. /**
  850. *@brief: Returns the upper triangular part of a matrix (2-D tensor) or batch of matrices input \n
  851. *@par Inputs:
  852. * Two inputs, including:
  853. *@li x: A Tensor. Must be one of the following types:
  854. * float16, float32, double, int32, uint8, int16, int8, complex64, int64,
  855. * qint8, quint8, qint32, uint16, complex128, uint32, uint64.
  856. *@li diagonal:(int, optional) – the diagonal to consider。\n
  857. *@par Outputs:
  858. *y: A Tensor. Has the same type as "x" . \n
  859. *@par Third-party framework compatibility
  860. * Compatible with the Pytorch operator Tril.
  861. */
  862. REG_OP(Tril)
  863. .INPUT(x, TensorType::BasicType())
  864. .ATTR(diagonal, Int, 0)
  865. .OUTPUT(y, TensorType::BasicType())
  866. .OP_END_FACTORY_REG(Tril)
  867. /**
  868. *@brief Concatenates a list of N tensors along the first dimension.
  869. *@par Inputs:
  870. * Two inputs, including:
  871. * @li values: A list of Tensors. Must be one of the following types: int32, float16, float32.
  872. * Tensors to be concatenated. All must have size 1 in the first dimension and same shape.
  873. * It's a dynamic input.
  874. * @li shape: A Tensor of the same type as "x".
  875. * The final shape of the result. Should be equal to the shapes of any input
  876. * but with the number of input values in the first dimension . \n
  877. *@par Attributes:
  878. *equation: The subscripts for the Einstein summation. \n
  879. *tensor_size: tensor size of input \n
  880. *@par Outputs:
  881. *@li y: Sums the product of the elements of the input operands along dimensions specified
  882. using a notation based on the Einstein summation convention. \n
  883. *@attention Constraints:
  884. *Input tensor_size must be Int. \n
  885. *@par Third-party framework compatibility
  886. *Compatible with Pytorch einsum operator.
  887. */
  888. REG_OP(EinSum)
  889. .DYNAMIC_INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32}))
  890. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32}))
  891. .REQUIRED_ATTR(equation, String)
  892. .REQUIRED_ATTR(tensor_size, Int)
  893. .OP_END_FACTORY_REG(EinSum)
  894. } // namespace ge
  895. #endif // OPS_BUILT_IN_OP_PROTO_INC_MATRIX_CALCULATION_OPS_H_

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