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

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