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

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