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