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
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
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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404
  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, 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, 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, DT_INT4, DT_BF16}))
  79. .INPUT(x2, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32, DT_INT8, DT_INT4, DT_BF16}))
  80. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32, DT_BF16}))
  81. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32, DT_BF16}))
  82. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8, DT_INT4}))
  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_FLOAT, DT_FLOAT16, DT_INT8, DT_INT32}))
  160. .INPUT(b, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT32}))
  161. .INPUT(c, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT32}))
  162. .INPUT(alpha, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT32}))
  163. .INPUT(beta, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT32}))
  164. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, 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, DT_BF16}))
  187. .INPUT(x2, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32, DT_BF16}))
  188. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32, DT_BF16}))
  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, DT_INT4, DT_BF16}))
  213. .INPUT(x2, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32, DT_INT8, DT_INT4, DT_BF16}))
  214. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32, DT_BF16}))
  215. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8, DT_INT4}))
  216. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32, DT_BF16}))
  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, float, int32, int8, uint8
  423. *@li indices: An ND Tensor . \n
  424. *Must be one of the following types: int32 or int64
  425. *@li updates: An ND Tensor .
  426. *Must be one of the following types: float16, float, int32, int8, uint8
  427. *@par Attributes:
  428. *use_locking: An optional bool. Defaults to "False". If "True",
  429. * the operation will be protected by a lock . \n
  430. *@par Outputs:
  431. *var: A Tensor. Has the same type and format as input "var" . \n
  432. *@par Third-party framework compatibility
  433. * Compatible with the TensorFlow operator ScatterAdd.
  434. */
  435. REG_OP(ScatterAdd)
  436. .INPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  437. .INPUT(indices, TensorType::IndexNumberType())
  438. .INPUT(updates, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  439. .OUTPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  440. .ATTR(use_locking, Bool, false)
  441. .OP_END_FACTORY_REG(ScatterAdd)
  442. /**
  443. *@brief Adds sparse "updates" to a variable reference . \n
  444. *@par Inputs:
  445. * Three inputs, including:
  446. *@li var: An ND Tensor .
  447. *Must be one of the following types: float16, float32, int32, int8, uint8
  448. *@li indices: An ND Tensor of type int32 or int64
  449. *@li updates: An ND Tensor .
  450. *Must be one of the following types: float16, float32, int32, int8, uint8
  451. *@par Attributes:
  452. * axis: An required int. The axis along which to index. \n
  453. *@par Outputs:
  454. *var: A Tensor. Has the same type and format as input "var" . \n
  455. *@par Third-party framework compatibility
  456. * Compatible with the pytorch operator ScatterAdd.
  457. */
  458. REG_OP(ScatterAddWithAxis)
  459. .INPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  460. .INPUT(indices, TensorType::IndexNumberType())
  461. .INPUT(updates, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  462. .OUTPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  463. .REQUIRED_ATTR(axis, Int)
  464. .OP_END_FACTORY_REG(ScatterAddWithAxis)
  465. /**
  466. *@brief Divides a variable reference by sparse updates . \n
  467. *@par Inputs:
  468. * Three inputs, including:
  469. *@li var: An ND Tensor.
  470. *Must be one of the following types: float16, float, int32, int8, uint8
  471. *@li indices: An ND Tensor.
  472. *Must be one of the following types: int32 or int64
  473. *@li updates: An ND Tensor.
  474. *Must be one of the following types: float16, float, int32, int8, uint8
  475. *@par Attributes:
  476. *use_locking: An optional bool. Defaults to "False". If "True",
  477. * the operation will be protected by a lock . \n
  478. *@par Outputs:
  479. *var: A Tensor. Has the same type and format as input "var" . \n
  480. *@par Third-party framework compatibility
  481. * Compatible with the TensorFlow operator ScatterDiv.
  482. */
  483. REG_OP(ScatterDiv)
  484. .INPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  485. .INPUT(indices, TensorType::IndexNumberType())
  486. .INPUT(updates, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  487. .OUTPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  488. .ATTR(use_locking, Bool, false)
  489. .OP_END_FACTORY_REG(ScatterDiv)
  490. /**
  491. *@brief Applies sparse addition to individual values or slices in a Variable . \n
  492. *@par Inputs:
  493. * Three inputs, including:
  494. *@li var: An ND Tensor.
  495. *Must be one of the following types: float16, float, int32, int8, uint8
  496. *@li indices: An ND Tensor.
  497. *Must be one of the following types: int32 or int64
  498. *@li updates: An ND Tensor.
  499. *Must be one of the following types: float16, float, int32, int8, uint8
  500. *@par Attributes:
  501. *use_locking: An optional bool. Defaults to "False". If "True",
  502. * the operation will be protected by a lock . \n
  503. *@par Outputs:
  504. *var: A Tensor. Has the same type and format as input "var" . \n
  505. *@par Third-party framework compatibility
  506. * Compatible with the TensorFlow operator ScatterNdAdd.
  507. */
  508. REG_OP(ScatterNdAdd)
  509. .INPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  510. .INPUT(indices, TensorType::IndexNumberType())
  511. .INPUT(updates, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  512. .OUTPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  513. .ATTR(use_locking, Bool, false)
  514. .OP_END_FACTORY_REG(ScatterNdAdd)
  515. /**
  516. *@brief Applies sparse addition to individual values or slices in a Variable . \n
  517. *@par Inputs:
  518. * Three inputs, including:
  519. *@li x: An ND Tensor. \n
  520. *Must be one of the following types: float16, float32, int32, int8, uint8
  521. *@li indices: An ND Tensor. \n
  522. *Must be one of the following types: int32
  523. *@li updates: An ND Tensor. \n
  524. * Must be one of the following types: float16, float32, int32, int8, uint8
  525. *@par Outputs:
  526. *y: A Tensor. Has the same type and format as input "x" . \n
  527. *@par Third-party framework compatibility
  528. * Compatible with the TensorFlow operator TensorScatterAdd.
  529. *@par Restrictions:
  530. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  531. */
  532. REG_OP(TensorScatterAdd)
  533. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  534. .INPUT(indices, TensorType::IndexNumberType())
  535. .INPUT(updates, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  536. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  537. .OP_END_FACTORY_REG(TensorScatterAdd)
  538. /**
  539. *@brief Applies sparse subtraction to individual values or slices in a Variable . \n
  540. *@par Inputs:
  541. * Three inputs, including:
  542. *@li var: An ND Tensor.
  543. *Must be one of the following types: float16, float, int32, int8, uint8
  544. *@li indices: An ND Tensor.
  545. *Must be one of the following types: int32 or int64
  546. *@li updates: An ND Tensor.
  547. *Must be one of the following types: float16, float, int32, int8, uint8
  548. *@par Attributes:
  549. *use_locking: An optional bool. Defaults to "False". If "True",
  550. * the operation will be protected by a lock . \n
  551. *@par Outputs:
  552. * var: A Tensor. Has the same type and format as input "var" . \n
  553. *@par Third-party framework compatibility
  554. * Compatible with the TensorFlow operator ScatterNdSub.
  555. */
  556. REG_OP(ScatterNdSub)
  557. .INPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  558. .INPUT(indices, TensorType::IndexNumberType())
  559. .INPUT(updates, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  560. .OUTPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  561. .ATTR(use_locking, Bool, false)
  562. .OP_END_FACTORY_REG(ScatterNdSub)
  563. /**
  564. *@brief Applies sparse addition to individual values or slices in a Variable . \n
  565. *@par Inputs:
  566. * Three inputs, including:
  567. *@li x: An ND Tensor. \n
  568. *Must be one of the following types: float16, float32, int32, int8, uint8
  569. *@li indices: An ND Tensor. \n
  570. *Must be one of the following types: int32
  571. *@li updates: An ND Tensor. \n
  572. *Must be one of the following types: float16, float32, int32, int8, uint8
  573. *@par Outputs:
  574. * y: A Tensor. Has the same type and format as input "x" . \n
  575. *@par Third-party framework compatibility
  576. * Compatible with the TensorFlow operator TensorScatterSub.
  577. *@par Restrictions:
  578. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  579. */
  580. REG_OP(TensorScatterSub)
  581. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  582. .INPUT(indices, TensorType::IndexNumberType())
  583. .INPUT(updates, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  584. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  585. .OP_END_FACTORY_REG(TensorScatterSub)
  586. /**
  587. *@brief Subtracts sparse updates to a variable reference . \n
  588. *@par Inputs:
  589. * Three inputs, including:
  590. *@li var: An ND Tensor.
  591. *Must be one of the following types: float16, float, int32, int8, uint8
  592. *@li indices: An ND Tensor.
  593. *Must be one of the following types: int32 or int64
  594. *@li updates: An ND Tensor.
  595. *Must be one of the following types: float16, float, int32, int8, uint8
  596. *@par Attributes:
  597. *use_locking: An optional bool. Defaults to "False". If "True",
  598. * the operation will be protected by a lock . \n
  599. *@par Outputs:
  600. * var: A Tensor. Has the same type and format as input "var" . \n
  601. *@par Third-party framework compatibility
  602. * Compatible with the TensorFlow operator ScatterSub.
  603. */
  604. REG_OP(ScatterSub)
  605. .INPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  606. .INPUT(indices, TensorType::IndexNumberType())
  607. .INPUT(updates, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  608. .OUTPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  609. .ATTR(use_locking, Bool, false)
  610. .OP_END_FACTORY_REG(ScatterSub)
  611. /**
  612. *@brief: Returns the batched diagonal part of a batched tensor with "assist" . \n
  613. *@par Inputs:
  614. * Two inputs, including:
  615. * @li x: A Tensor of type float16, float32, or int32.
  616. * @li assist: A Tensor of the same type as "x" . \n
  617. *@par Outputs:
  618. *y: A Tensor. Has the same type as "x" . \n
  619. *@par Third-party framework compatibility
  620. * Compatible with the TensorFlow operator DiagPart.
  621. *
  622. * @par Restrictions:
  623. * Warning: THIS FUNCTION IS DEPRECATED. Please use DiagPart instead.
  624. */
  625. REG_OP(DiagPartD)
  626. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
  627. .INPUT(assist, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
  628. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
  629. .OP_END_FACTORY_REG(DiagPartD)
  630. /**
  631. *@brief: Returns the batched diagonal part of a batched tensor . \n
  632. *@par Inputs:
  633. *x: A Tensor. Must be one of the following types:
  634. * float16, float32, int32, int64, double, complex64, complex128 . \n
  635. *@par Outputs:
  636. *y: A Tensor. Has the same type as "x" . \n
  637. *@par Third-party framework compatibility
  638. * Compatible with the TensorFlow operator DiagPart.
  639. */
  640. REG_OP(DiagPart)
  641. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32, DT_INT64, DT_DOUBLE,
  642. DT_COMPLEX64, DT_COMPLEX128}))
  643. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32, DT_INT64, DT_DOUBLE,
  644. DT_COMPLEX64, DT_COMPLEX128}))
  645. .OP_END_FACTORY_REG(DiagPart)
  646. /**
  647. *@brief Also known as a "fully-connected" layer, computes an inner product with a set of learned weights, and (optionally) adds biases . \n
  648. *@par Inputs:
  649. * Four inputs, including:
  650. *@li x: A Tensor of type float16, int8.
  651. *@li w: A weight matrix of type float16, int8.
  652. *@li b: An optional Tensor of type float16, int32, float32.
  653. *@li offset_w: An optional Tensor of type int8. Reserved. Only None Supported. \n
  654. *@par Attributes:
  655. *@li num_output: Required. An int, output neuron number. Reserved.
  656. *@li transpose: A bool, specifying weight whether to transpose input w, either "true" or "false". Defaults to "false".
  657. *@li axis: Optional. An int, 1 or 2, specifying which dimension the input "K" starts from. Defaults to 1.
  658. * The product of the subsequent dimensions starting form first dimension or the second dimension is "K".
  659. *@li offset_x: An optional integer for quantized FullyConnection.
  660. *The negative offset added to the input image for int8 type. Ensure offset_x within the
  661. *effective range of int8 [-128, 127]. Defaults to "0". \n
  662. *@par Outputs:
  663. *y: The result tensor of type float16, int32, float32 . \n
  664. *@par Third-party framework compatibility
  665. * Compatible with the Caffe operator InnerProduct . \n
  666. *@par Quantization supported or not
  667. * Yes
  668. */
  669. REG_OP(FullyConnection)
  670. .INPUT(x, TensorType({DT_FLOAT16, DT_INT8, DT_INT4, DT_FLOAT32, DT_BF16}))
  671. .INPUT(w, TensorType({DT_FLOAT16, DT_INT8, DT_INT4, DT_FLOAT32, DT_BF16}))
  672. .OPTIONAL_INPUT(b, TensorType({DT_FLOAT16, DT_INT32,DT_FLOAT32, DT_BF16}))
  673. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8, DT_INT4}))
  674. .OUTPUT(y, TensorType({DT_FLOAT16, DT_INT32,DT_FLOAT32, DT_BF16}))
  675. .REQUIRED_ATTR(num_output, Int)
  676. .ATTR(transpose, Bool, false)
  677. .ATTR(axis, Int, 1)
  678. .ATTR(offset_x, Int, 0)
  679. .OP_END_FACTORY_REG(FullyConnection)
  680. /**
  681. *@brief Also known as a "fully-connected-compress" layer, computes an inner
  682. product with a set of learned weights, and (optionally) adds biases . \n
  683. *@par Inputs:
  684. * Five inputs, including:
  685. *@li x: A Tensor of type uint8, int8.
  686. *@li w: A weight matrix of type int8.
  687. *@li compress_index: A compress index matrix of type int8.
  688. *@li b: A Tensor of type int32.
  689. *@li offset_w: A Tensor of type int8.
  690. *@par Attributes:
  691. *@li num_output: A int, specifying the number of outputs.
  692. *@li transpose: A bool, specifying whether to transpose input w, either "true"
  693. or "false". Defaults to "false".
  694. *@li axis: Optional. A int, 1 or 2, specifying which dimension the input "K"
  695. starts from. Defaults to "1".
  696. * The product of the subsequent dimensions starting form first dimension or the
  697. second dimension is "K".
  698. *@li offset_x: An optional integer for quantized FullyConnectionCompress.
  699. *The negative offset added to the input image for int8 type. Ensure offset_x
  700. within the effective range of int8 [-128, 127]. Defaults to "0". \n
  701. *@par Outputs:
  702. *y: The result tensor of type int32. \n
  703. *@par Third-party framework compatibility
  704. * Compatible with the Caffe operator InnerProduct. \n
  705. *@par Quantization supported or not
  706. * Yes
  707. */
  708. REG_OP(FullyConnectionCompress)
  709. .INPUT(x, TensorType({DT_UINT8, DT_INT8}))
  710. .INPUT(w, TensorType({DT_INT8}))
  711. .INPUT(comress_index, TensorType({DT_INT8}))
  712. .OPTIONAL_INPUT(b, TensorType({DT_INT32}))
  713. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  714. .OUTPUT(y, TensorType({DT_INT32}))
  715. .REQUIRED_ATTR(num_output, Int)
  716. .ATTR(transpose, Bool, false)
  717. .ATTR(axis, Int, 1)
  718. .ATTR(offset_x, Int, 0)
  719. .OP_END_FACTORY_REG(FullyConnectionCompress)
  720. /**
  721. *@brief Computes the confusion matrix from predictions and labels . \n
  722. *@par Inputs:
  723. * Three inputs, including:
  724. *@li labels: A Tensor. Must be one of the following types: float16, float32,
  725. * int32, int8, uint8.
  726. *@li predictions: A Tensor. Must be one of the following types: float16,
  727. * float32, int32, int8, uint8.
  728. *@li weights: A Tensor. Must be one of the following types: float16, float32,
  729. * int32, int8, uint8 . \n
  730. *@par Attributes:
  731. *@li num_classes: An integer for the shape of the output matrix.
  732. * No default value.
  733. *@li dtype: Data type of the confusion matrix. No default value . \n
  734. *@par Outputs:
  735. *y: A Tensor. Has the same type and format as input "labels"
  736. *@attention Constraints:
  737. *@li "weights", "labels", and "predictions" are 1D tensors.
  738. *@li The output is with shape (num_classes, num_classes),
  739. * where, 1 <= num_classes <= 4096 . \n
  740. *@see Region()
  741. *@par Third-party framework compatibility
  742. * Compatible with the TensorFlow operator ConfusionMatrix.
  743. */
  744. REG_OP(ConfusionMatrix)
  745. .INPUT(labels, TensorType({DT_FLOAT, DT_INT32, DT_FLOAT16, DT_INT8, DT_UINT8}))
  746. .INPUT(predictions, TensorType({DT_FLOAT, DT_INT32, DT_FLOAT16, DT_INT8, DT_UINT8}))
  747. .OPTIONAL_INPUT(weights, TensorType({DT_FLOAT, DT_INT32, DT_FLOAT16, DT_INT8, DT_UINT8}))
  748. .OUTPUT(y, TensorType({DT_FLOAT, DT_INT32, DT_FLOAT16, DT_INT8, DT_UINT8}))
  749. .REQUIRED_ATTR(num_classes, Int)
  750. .REQUIRED_ATTR(dtype, String)
  751. .OP_END_FACTORY_REG(ConfusionMatrix)
  752. /**
  753. *@brief Multiplies sparse updates into a variable reference . \n
  754. *@par Inputs:
  755. * Three inputs, including:
  756. *@li var: An ND Tensor.
  757. *Must be one of the following types: float16, float, int32, int8, uint8
  758. *@li indices: An ND Tensor.
  759. *Must be one of the following types: int32 or int64
  760. *@li updates: An ND Tensor . \n
  761. *Must be one of the following types: float16, float, int32, int8, uint8
  762. *@par Attributes:
  763. *use_locking: An optional bool. Defaults to "False". If "True", the operation
  764. * will be protected by a lock . \n
  765. *@par Outputs:
  766. *var: A Tensor. Has the same type and format as input "var" . \n
  767. *@par Third-party framework compatibility
  768. * Compatible with the TensorFlow operator ScatterMul.
  769. */
  770. REG_OP(ScatterMul)
  771. .INPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  772. .INPUT(indices, TensorType::IndexNumberType())
  773. .INPUT(updates, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  774. .OUTPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  775. .ATTR(use_locking, Bool, false)
  776. .OP_END_FACTORY_REG(ScatterMul)
  777. /**
  778. *@brief Reduces sparse updates into a variable reference using
  779. * the "min" operation . \n
  780. *@par Inputs:
  781. * Three inputs, including:
  782. *@li var: An ND Tensor.
  783. *Must be one of the following types: float16, float, int32, int8, uint8
  784. *@li indices: An ND Tensor.
  785. *Must be one of the following types: int32 or int64
  786. *@li updates: An ND Tensor.
  787. *Must be one of the following types: float16, float, int32, int8, uint8
  788. *@par Attributes:
  789. *use_locking: An optional bool. Defaults to "False". If "True", the operation
  790. * will be protected by a lock . \n
  791. *@par Outputs:
  792. *var: A Tensor. Has the same type and format as input "var" . \n
  793. *@par Third-party framework compatibility
  794. * Compatible with the TensorFlow operator ScatterMin.
  795. */
  796. REG_OP(ScatterMin)
  797. .INPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  798. .INPUT(indices, TensorType::IndexNumberType())
  799. .INPUT(updates, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  800. .OUTPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  801. .ATTR(use_locking, Bool, false)
  802. .OP_END_FACTORY_REG(ScatterMin)
  803. /**
  804. *@brief Reduces sparse updates into a variable reference using the "max" operation . \n
  805. *@par Inputs:
  806. * Three inputs, including:
  807. *@li var: An ND Tensor .
  808. *Must be one of the following types: float16, float, int32, int8, uint8
  809. *@li indices: An NCHW, NHWC, or ND Tensor . \n
  810. *Must be one of the following types: int32 or int64
  811. *@li updates: An NCHW, NHWC, or ND Tensor .
  812. *Must be one of the following types: float16, float, int32, int8, uint8
  813. *@par Attributes:
  814. *use_locking: An optional bool. Defaults to "False".
  815. * If "True", the operation will be protected by a lock . \n
  816. *@par Outputs:
  817. *var: A Tensor. Has the same type and format as input "var" . \n
  818. *@par Third-party framework compatibility
  819. * Compatible with the TensorFlow operator ScatterMax.
  820. */
  821. REG_OP(ScatterMax)
  822. .INPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  823. .INPUT(indices, TensorType::IndexNumberType())
  824. .INPUT(updates, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  825. .OUTPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  826. .ATTR(use_locking, Bool, false)
  827. .OP_END_FACTORY_REG(ScatterMax)
  828. /**
  829. *@brief Applies sparse updates to a variable reference . \n
  830. *@par Inputs:
  831. * Three inputs, including:
  832. *@li var: An ND Tensor .
  833. *Must be one of the following types: float16, float, int32, int8, uint8
  834. *@li indices: An ND Tensor . \n
  835. *Must be one of the following types: int32 or int64
  836. *@li updates: An ND Tensor .
  837. *Must be one of the following types: float16, float, int32, int8, uint8
  838. *@par Attributes:
  839. *use_locking: An optional bool. Defaults to "False". If "True",
  840. * the operation will be protected by a lock . \n
  841. *@par Outputs:
  842. *var: A Tensor. Has the same type and format as input "var" . \n
  843. *@par Third-party framework compatibility
  844. * Compatible with the TensorFlow operator ScatterUpdate.
  845. */
  846. REG_OP(ScatterUpdate)
  847. .INPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  848. .INPUT(indices, TensorType::IndexNumberType())
  849. .INPUT(updates, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  850. .OUTPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  851. .ATTR(use_locking, Bool, false)
  852. .OP_END_FACTORY_REG(ScatterUpdate)
  853. /**
  854. *@brief Returns a tensor with the `k[0]`-th to `k[1]`-th diagonals of the batched `input` . \n
  855. *@par Inputs:
  856. * Three inputs, including:
  857. *@li input: Rank `r` tensor where `r >= 2`. \n
  858. *@li k: \n
  859. *Diagonal offset(s). Positive value means superdiagonal, 0 refers to the main \n
  860. *diagonal, and negative value means subdiagonals. `k` can be a single integer \n
  861. *(for a single diagonal) or a pair of integers specifying the low and high ends \n
  862. *of a matrix band. `k[0]` must not be larger than `k[1]`. \n
  863. *@li padding_value: The value to fill the area outside the specified diagonal band with. \n
  864. *@par Outputs:
  865. *diagonal: The extracted diagonal(s) . \n
  866. *@par Third-party framework compatibility
  867. * Compatible with the TensorFlow operator ScatterUpdate.
  868. */
  869. REG_OP(MatrixDiagPartV2)
  870. .INPUT(input, TensorType::BasicType())
  871. .INPUT(k, TensorType({DT_INT32}))
  872. .INPUT(padding_value, TensorType::BasicType())
  873. .OUTPUT(diagonal, TensorType::BasicType())
  874. .OP_END_FACTORY_REG(MatrixDiagPartV2)
  875. /**
  876. *@brief Returns a batched matrix tensor with new batched diagonal values . \n
  877. *@par Inputs:
  878. * Three inputs, including:
  879. *@li input: "Rank `r+1`, where `r >= 1`. \n
  880. *@li diagonal: Rank `r` when `k` is an integer or `k[0] == k[1]`. Otherwise, it has rank `r+1`. \n
  881. *@li k:
  882. *Diagonal offset(s). Positive value means superdiagonal, 0 refers to the main \n
  883. *diagonal, and negative value means subdiagonals. `k` can be a single integer \n
  884. *(for a single diagonal) or a pair of integers specifying the low and high ends \n
  885. *of a matrix band. `k[0]` must not be larger than `k[1]`. \n
  886. *@par Outputs:
  887. *output: Rank `r+1`, with `output.shape = input.shape` . \n
  888. *@par Third-party framework compatibility
  889. * Compatible with the TensorFlow operator ScatterUpdate.
  890. */
  891. REG_OP(MatrixSetDiagV2)
  892. .INPUT(input, TensorType::BasicType())
  893. .INPUT(diagonal, TensorType::BasicType())
  894. .INPUT(k, TensorType({DT_INT32}))
  895. .OUTPUT(output, TensorType::BasicType())
  896. .OP_END_FACTORY_REG(MatrixSetDiagV2)
  897. /**
  898. *@brief Returns a batched matrix tensor with new batched diagonal values . \n
  899. *@par Inputs:
  900. * Three inputs, including:
  901. *@li input: "Rank `r+1`, where `r >= 1`. \n
  902. *@li diagonal: Rank `r` when `k` is an integer or `k[0] == k[1]`. Otherwise, it has rank `r+1`. \n
  903. *@li k:
  904. *Diagonal offset(s). Positive value means superdiagonal, 0 refers to the main \n
  905. *diagonal, and negative value means subdiagonals. `k` can be a single integer \n
  906. *(for a single diagonal) or a pair of integers specifying the low and high ends \n
  907. *of a matrix band. `k[0]` must not be larger than `k[1]`. \n
  908. *@par Attributes:
  909. *@li align: An optional string. Defaults to RIGHT_LEFT. It is a string specifying \n
  910. *how superdiagonals and subdiagonals should be aligned, respectively. \n
  911. *other optional: LEFT_RIGHT, LEFT_LEFT, and RIGHT_RIGHT.\n
  912. *@par Outputs:
  913. *output: Rank `r+1`, with `output.shape = input.shape` . \n
  914. *@par Third-party framework compatibility
  915. * Compatible with the TensorFlow operator ScatterUpdate.
  916. */
  917. REG_OP(MatrixSetDiagV3)
  918. .INPUT(input, TensorType::BasicType())
  919. .INPUT(diagonal, TensorType::BasicType())
  920. .INPUT(k, TensorType({DT_INT32}))
  921. .OUTPUT(output, TensorType::BasicType())
  922. .ATTR(align, String, "RIGHT_LEFT")
  923. .OP_END_FACTORY_REG(MatrixSetDiagV3)
  924. /**
  925. *@brief Returns a batched diagonal tensor with given batched diagonal values . \n
  926. *@par Inputs:
  927. * Five inputs, including:
  928. *@li diagonal: Rank `r`, where `r >= 1` \n
  929. *@li k:
  930. *Diagonal offset(s). Positive value means superdiagonal, 0 refers to the main \n
  931. *diagonal, and negative value means subdiagonals. `k` can be a single integer \n
  932. *(for a single diagonal) or a pair of integers specifying the low and high ends \n
  933. *of a matrix band. `k[0]` must not be larger than `k[1]`. \n
  934. *@li num_rows:
  935. *The number of rows of the output matrix. If it is not provided, the op assumes \n
  936. *the output matrix is a square matrix and infers the matrix size from k and the \n
  937. *innermost dimension of `diagonal`. \n
  938. *@li num_cols: An NCHW, NHWC, or ND Tensor.
  939. *The number of columns of the output matrix. If it is not provided, the op \n
  940. *assumes the output matrix is a square matrix and infers the matrix size from \n
  941. *k and the innermost dimension of `diagonal`. \n
  942. *@li padding_value: The number to fill the area outside the specified diagonal band with. \n
  943. *@par Outputs:
  944. *output: Has rank `r+1` when `k` is an integer or `k[0] == k[1]`, rank `r` otherwise . \n
  945. *@par Third-party framework compatibility
  946. * Compatible with the TensorFlow operator ScatterUpdate.
  947. */
  948. REG_OP(MatrixDiagV2)
  949. .INPUT(diagonal, TensorType::BasicType())
  950. .INPUT(k, TensorType({DT_INT32}))
  951. .INPUT(num_rows, TensorType({DT_INT32}))
  952. .INPUT(num_cols, TensorType({DT_INT32}))
  953. .INPUT(padding_value, TensorType::BasicType())
  954. .OUTPUT(output, TensorType::BasicType())
  955. .OP_END_FACTORY_REG(MatrixDiagV2)
  956. /**
  957. * @brief Add updates to var_out according to axis and indices.
  958. * @par Inputs:
  959. * Three inputs, including:
  960. * @li var: A Tensor. Must be one of the following types:
  961. * float16, float32, int32, int8, uint8.
  962. * @li indices: A Tensor of the indices, type should be int32.
  963. * @li updates: A Tensor of the same type as "var".
  964. * @par Attributes:
  965. * @li axis: An required int to specify the axis to perform indices add.
  966. * @par Outputs:
  967. * @li var_out: A Tensor. Same as input "var".
  968. * @par Third-party framework compatibility
  969. * Compatible with the Pytorch operator index_add.
  970. * @par Restrictions:
  971. * Warning:THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  972. */
  973. REG_OP(IndexAdd)
  974. .INPUT(var, TensorType({DT_INT32, DT_INT8, DT_UINT8, DT_FLOAT32, DT_FLOAT16}))
  975. .INPUT(indices, TensorType({DT_INT32}))
  976. .INPUT(updates, TensorType({DT_INT32, DT_INT8, DT_UINT8, DT_FLOAT32, DT_FLOAT16}))
  977. .OUTPUT(var_out, TensorType({DT_INT32, DT_INT8, DT_UINT8, DT_FLOAT32, DT_FLOAT16}))
  978. .ATTR(axis, Int, 0)
  979. .OP_END_FACTORY_REG(IndexAdd)
  980. /**
  981. * @brief According to the index number of indexes, replace the value
  982. *corresponding to X1 with the value in x2.
  983. * @par Inputs:
  984. * Three inputs, including:
  985. * @li x1: A Tensor. Must be one of the following types:
  986. *float16, float32, double, int32, uint8, int16, int8, complex64, int64,
  987. *qint8, quint8, qint32, uint16, complex128, uint32, uint64. \n
  988. * @li x2: A Tensor of the same type as "x1".
  989. * @li indices: A Tensor of the indices,
  990. * @par Attributes:
  991. * @li accumulate: Does it support self accumulation.Defaults to 0.
  992. * @par Outputs:
  993. * @li y: A Tensor. Same as input "x1".
  994. * @par Third-party framework compatibility
  995. * Compatible with the Pytorch operator index_put.
  996. * @par Restrictions:
  997. * Warning:THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  998. */
  999. REG_OP(IndexPut)
  1000. .INPUT(x1, TensorType::BasicType())
  1001. .INPUT(x2, TensorType::BasicType())
  1002. .OUTPUT(y, TensorType::BasicType())
  1003. .REQUIRED_ATTR(indices, ListInt)
  1004. .ATTR(accumulate, Int, 0)
  1005. .OP_END_FACTORY_REG(IndexPut)
  1006. /**
  1007. *@brief: Returns the upper triangular part of a matrix (2-D tensor) or batch of matrices input \n
  1008. *@par Inputs:
  1009. *x: A Tensor. Must be one of the following types:
  1010. *float16, float32, double, int32, uint8, int16, int8, complex64, int64,
  1011. *qint8, quint8, qint32, uint16, complex128, uint32, uint64. \n
  1012. *@par Attributes:
  1013. *diagonal: An optional attribute indicates the diagonal to consider. \n
  1014. *@par Outputs:
  1015. *y: A Tensor. Has the same type as "x" . \n
  1016. *@par Third-party framework compatibility
  1017. * Compatible with the Pytorch operator Triu.
  1018. */
  1019. REG_OP(Triu)
  1020. .INPUT(x, TensorType::BasicType())
  1021. .ATTR(diagonal, Int, 0)
  1022. .OUTPUT(y, TensorType::BasicType())
  1023. .OP_END_FACTORY_REG(Triu)
  1024. /**
  1025. *@brief: Returns the upper triangular part of a matrix (2-D tensor) or batch of matrices input \n
  1026. *@par Inputs:
  1027. *x: A Tensor. Must be one of the following types:
  1028. *float16, float32, double, int32, uint8, int16, int8, complex64, int64,
  1029. *qint8, quint8, qint32, uint16, complex128, uint32, uint64. \n
  1030. *@par Attributes:
  1031. *diagonal: An optional attribute indicates the diagonal to consider. \n
  1032. *@par Outputs:
  1033. *y: A Tensor. Has the same type as "x" . \n
  1034. *@par Third-party framework compatibility
  1035. * Compatible with the Pytorch operator Tril.
  1036. */
  1037. REG_OP(Tril)
  1038. .INPUT(x, TensorType::BasicType())
  1039. .ATTR(diagonal, Int, 0)
  1040. .OUTPUT(y, TensorType::BasicType())
  1041. .OP_END_FACTORY_REG(Tril)
  1042. /**
  1043. *@brief Concatenates a list of N tensors along the first dimension.
  1044. *@par Inputs:
  1045. * Two inputs, including:
  1046. * @li values: A list of Tensors. Must be one of the following types: int32, float16, float32.
  1047. * Tensors to be concatenated. All must have size 1 in the first dimension and same shape.
  1048. * It's a dynamic input.
  1049. * @li shape: A Tensor of the same type as "x".
  1050. * The final shape of the result. Should be equal to the shapes of any input
  1051. * but with the number of input values in the first dimension . \n
  1052. *@par Attributes:
  1053. *equation: The subscripts for the Einstein summation. \n
  1054. *N: tensor size of input \n
  1055. *@par Outputs:
  1056. *@li y: Sums the product of the elements of the input operands along dimensions specified
  1057. using a notation based on the Einstein summation convention. \n
  1058. *@attention Constraints:
  1059. *Input N must be Int. \n
  1060. *@par Third-party framework compatibility
  1061. *Compatible with Pytorch einsum operator.
  1062. */
  1063. REG_OP(Einsum)
  1064. .DYNAMIC_INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32}))
  1065. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32}))
  1066. .REQUIRED_ATTR(equation, String)
  1067. .REQUIRED_ATTR(N, Int)
  1068. .OP_END_FACTORY_REG(Einsum)
  1069. /**
  1070. *@brief Returns a 2-D tensor with ones on the diagonal and zeros elsewhere. \n
  1071. *@par Inputs:
  1072. *No inputs
  1073. *@par Attributes:
  1074. *@li num_rows: An required int. \n
  1075. *@li num_columns: An optional int.Defaults to 0. \n
  1076. *@li batch_shape: An optional ListInt.Defaults to []. \n
  1077. *@li dtype: An optional int.Defaults to 0. \n
  1078. *@par Outputs:
  1079. *y: A Tensor with targeted type and shape. \n
  1080. *@par Third-party framework compatibility
  1081. *Compatible with the Pytorch operator Eye. \n
  1082. */
  1083. REG_OP(Eye)
  1084. .OUTPUT(y, TensorType::BasicType()) /* "Result, has targeted element type" */
  1085. .REQUIRED_ATTR(num_rows, Int)
  1086. .ATTR(num_columns, Int, 0)
  1087. .ATTR(batch_shape, ListInt, {})
  1088. .ATTR(dtype, Int, 0)
  1089. .OP_END_FACTORY_REG(Eye)
  1090. /**
  1091. *@brief: Fill diagonal of at least 2 dimension tensors with value . \n
  1092. *@par Inputs:
  1093. *x: A Tensor. Must be one of the following types:
  1094. * float32, int32, int64 . \n
  1095. *@par Outputs:
  1096. *y: A Tensor. Has the same type as "x" . \n
  1097. *@par Attributes:
  1098. *fill_value:The value to fill in
  1099. *wrap: An optional bool. Defaults to "False". If "True", Use recursive fill. \n
  1100. *@par Third-party framework compatibility
  1101. * Compatible with the Pytorch operator FillDiagonal.
  1102. */
  1103. REG_OP(FillDiagonal)
  1104. .INPUT(x, TensorType({DT_FLOAT, DT_INT32, DT_INT64}))
  1105. .OUTPUT(y, TensorType({DT_FLOAT, DT_INT32, DT_INT64}))
  1106. .REQUIRED_ATTR(fill_value, Float)
  1107. .ATTR(wrap, Bool, false)
  1108. .OP_END_FACTORY_REG(FillDiagonal)
  1109. /**
  1110. *@brief: Returns the sum of the elements of the diagonal of the input 2-D matrix. \n
  1111. *@par Inputs:
  1112. *x: A Tensor. Must be one of the following types:
  1113. * float16, float. \n
  1114. *@par Outputs:
  1115. *y: A Tensor. Has the same type as "x" . \n
  1116. *@par Third-party framework compatibility
  1117. * Compatible with the Pytorch operator Trace.
  1118. */
  1119. REG_OP(Trace)
  1120. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  1121. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  1122. .OP_END_FACTORY_REG(Trace)
  1123. /**
  1124. *@brief Computes the generalized inverse of any matrix. \n
  1125. *@par Inputs:
  1126. * @li x: input matrix. Must be one of the following types:
  1127. * double, float. \n
  1128. *@par Attributes:
  1129. * @li rcond: An optional float >= 0 or inf. Defaults to 1e-15. \n
  1130. *@par Outputs:
  1131. * y: A Tensor with the same type and shape of x's transpose. \n
  1132. */
  1133. REG_OP(Pinverse)
  1134. .INPUT(x, TensorType({ DT_FLOAT, DT_DOUBLE }))
  1135. .OUTPUT(y, TensorType({ DT_FLOAT, DT_DOUBLE }))
  1136. .ATTR(rcond, Float, 1e-15)
  1137. .OP_END_FACTORY_REG(Pinverse)
  1138. } // namespace ge
  1139. #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两部分组成,详细的架构图如下所示