You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

matrix_calculation_ops.h 48 kB

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