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

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