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 48 kB

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