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

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
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
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
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968
  1. /**
  2. * Copyright 2019-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. #ifndef GE_OP_MATRIX_CALCULATION_OPS_H
  17. #define GE_OP_MATRIX_CALCULATION_OPS_H
  18. #include "graph/operator_reg.h"
  19. namespace ge {
  20. /**
  21. *@brief Multiplies matrix "a" by matrix "b", producing "a * b".
  22. *@par Inputs:
  23. *Three inputs, including:
  24. * @li x1: A matrix Tensor. 2D. Must be one of the following types: float16,
  25. * float32, int32. Has format [ND, NHWC, FRACTAL_NZ].
  26. * @li x2: A matrix Tensor. 2D. Must be one of the following types: float16,
  27. * float32, int32. Has format [ND, NHWC, FRACTAL_NZ].
  28. * @li bias: A optional 1D Tensor. Must be one of the following types: float16,
  29. * float32, int32. Has format [ND, NHWC].
  30. *@par Attributes:
  31. *@li transpose_a: A bool. If True, changes the shape of "x1" from [M, K] to [K, M].
  32. *@li transpose_b: A bool. If True, changes the shape of "x2" from [M, K] to [K, M].
  33. *@par Outputs:
  34. *y: The result matrix Tensor. 2D. Must be one of the following types: float16,
  35. * float32, int32. Has format [ND, NHWC, FRACTAL_NZ].
  36. *@par Third-party framework compatibility
  37. * Compatible with the TensorFlow operator BatchMatmul.
  38. */
  39. REG_OP(MatMul)
  40. .INPUT(x1, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
  41. .INPUT(x2, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
  42. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
  43. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
  44. .ATTR(transpose_x1, Bool, false)
  45. .ATTR(transpose_x2, Bool, false)
  46. .OP_END_FACTORY_REG(MatMul)
  47. /**
  48. *@brief Multiplies matrix "a" by matrix "b", producing "a * b".
  49. *@par Inputs:
  50. *Two inputs, including:
  51. * @li x1: A matrix Tensor. 2D. Must be one of the following types: float16,
  52. * float32, int32. Has format [ND, NHWC, FRACTAL_NZ].
  53. * @li x2: A matrix Tensor. 2D. Must be one of the following types: float16,
  54. * float32, int32. Has format [ND, NHWC, FRACTAL_NZ].
  55. * @li bias: A 1D Tensor. Must be one of the following types: float16,
  56. * float32, int32. Has format [ND, NHWC].
  57. *@par Attributes:
  58. *@li transpose_a: A bool. If True, changes the shape of "x1" from [M, K] to [K, M].
  59. *@li transpose_b: A bool. If True, changes the shape of "x2" from [M, K] to [K, M].
  60. *@par Outputs:
  61. *y: The result matrix Tensor. 2D. Must be one of the following types: float16,
  62. * float32, int32. Has format [ND, NHWC, FRACTAL_NZ].
  63. *@par Third-party framework compatibility
  64. * Compatible with the TensorFlow operator BatchMatmul.
  65. */
  66. REG_OP(MatMulV2)
  67. .INPUT(x1, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32, DT_INT8}))
  68. .INPUT(x2, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32, DT_INT8}))
  69. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
  70. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
  71. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  72. .ATTR(transpose_x1, Bool, false)
  73. .ATTR(transpose_x2, Bool, false)
  74. .ATTR(offset_x, Int, 0)
  75. .OP_END_FACTORY_REG(MatMulV2)
  76. /**
  77. *@brief Performs Matrix-to-matrix Multiply, producing c=alpha[0]*a*b+beta[0]*c.
  78. *@par Inputs:
  79. *Five inputs, including:
  80. *@li a: A matrix Tensor. Must be one of the following types: float16, int8.
  81. * Has format [ND, FRACTAL_NZ]. 2D(ND) or 4D(FRACTAL_NZ).
  82. *@li b: A matrix Tensor. Must be one of the following types: float16, int8.
  83. * Has format [ND, FRACTAL_NZ, FRACTAL_Z]. 2D(ND) or 4D(FRACTAL_NZ, FRACTAL_Z).
  84. *@li c: A matrix Tensor. Must be one of the following types: float16, int32,
  85. * float32. has format [ND, FRACTAL_NZ]. 2D(ND) or 4D(FRACTAL_NZ).
  86. *@li alpha: A 1D Tensor. The shape of alpha is [1].Must be one of the following
  87. * types: float16, int32, float32. Has format [ND].
  88. *@li beta: A 1D Tensor. The shape of beta is [1]. Must be one of the following
  89. * types: float16, int32, float32. Has format [ND].
  90. * The format of a, b, c has restriction:\n
  91. * When type of a is int8 and type of c is int32, the format of a, b, c should
  92. * all be ND, or a is FRACTAL_NZ and b is FRACTAL_Z and c is ND.\n
  93. * When type of a is int8 and type of c is float32, the format of a, b, c should
  94. * all be ND or a is FRACTAL_NZ and b is FRACTAL_Z and c is FRACTAL_NZ.\n
  95. * When type of a is float16 and type of c is float16, the format of a, b, c
  96. * should all be ND or FRACTAL_NZ.\n
  97. * When type of a is float16 and type of c is float32, the format of a, b, c
  98. * should all be ND or FRACTAL_NZ.
  99. *@par Attributes:
  100. *Two attributes, including:
  101. *@li transpose_a: Optional. A bool. If True, changes the shape of "a" from
  102. * [M, K] to [K, M].
  103. *@li transpose_b: Optional. A bool. If True, changes the shape of "b" from
  104. * [K, N] to [N, K].
  105. *@par Outputs:
  106. *y: The result matrix Tensor. Must be one of the following types: float16,
  107. * float32, int32. Has format [ND, FRACTAL_NZ], the format should be equal to a.
  108. * 2D(ND) or 4D(FRACTAL_NZ).
  109. */
  110. REG_OP(GEMM)
  111. .INPUT(a, TensorType({DT_FLOAT16, DT_INT8}))
  112. .INPUT(b, TensorType({DT_FLOAT16, DT_INT8}))
  113. .INPUT(c, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
  114. .INPUT(alpha, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
  115. .INPUT(beta, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
  116. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
  117. .ATTR(transpose_a, Bool, false)
  118. .ATTR(transpose_b, Bool, false)
  119. .OP_END_FACTORY_REG(GEMM)
  120. /**
  121. *@brief Multiplies matrix "a" by matrix "b", producing "a * b".
  122. *@par Inputs:
  123. *Three inputs, including:
  124. * @li x1: A matrix Tensor. Must be one of the following types: float16,
  125. * float32, int32. 2D or higher. Has format [ND, NHWC, FRACTAL_NZ].
  126. * @li x2: A matrix Tensor. Must be one of the following types: float16,
  127. * float32, int32. 2D or higher. Has format [ND, NHWC, FRACTAL_NZ].
  128. *@par Attributes:
  129. *@li adj_x: A bool. If True, changes the shape of "x1" from [B, M, K] to [B, K, M].
  130. *@li adj_y: A bool. If True, changes the shape of "x2" from [B, M, K] to [B, K, M].
  131. *@par Outputs:
  132. *y: The result matrix Tensor. 2D or higher. Must be one of the following types: float16,
  133. * float32, int32. 2D or higher. Has format [ND, NHWC, FRACTAL_NZ]. Has the same shape length as "x1" and "x2".
  134. *@par Third-party framework compatibility
  135. * Compatible with the TensorFlow operator BatchMatmul.
  136. */
  137. REG_OP(BatchMatMul)
  138. .INPUT(x1, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
  139. .INPUT(x2, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
  140. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
  141. .ATTR(adj_x1, Bool, false)
  142. .ATTR(adj_x2, Bool, false)
  143. .OP_END_FACTORY_REG(BatchMatMul)
  144. REG_OP(MeanCCE)
  145. .INPUT(x, TensorType::ALL())
  146. .INPUT(indices, TensorType::ALL())
  147. .OUTPUT(y, TensorType::ALL())
  148. .ATTR(keep_dims, Bool, false)
  149. .ATTR(value1, ListInt, {})
  150. .ATTR(mode, Int, 3) // 0:max pooling or 1:avg pooling
  151. .ATTR(pad_mode, Int, 0)
  152. .ATTR(global_pooling, Bool, true) // tensorflow have no attr, set default value
  153. .ATTR(window, ListInt, {1,1}) // kernel size
  154. .ATTR(pad, ListInt, {0,0,0,0}) // pad size
  155. .ATTR(stride, ListInt, {1,1}) // stride size
  156. .ATTR(ceil_mode, Int, 0)
  157. .ATTR(data_mode, Int, 1)
  158. .ATTR(nan_opt, Int, 0)
  159. .ATTR(fomart, Int, 0)
  160. .OP_END_FACTORY_REG(MeanCCE)
  161. REG_OP(MeanGrad)
  162. .INPUT(x, TensorType::ALL())
  163. .OUTPUT(y, TensorType::ALL())
  164. .ATTR(mode, Int, 1) // 0:max pooling or 1:avg pooling
  165. .ATTR(pad_mode, Int, 0)
  166. .ATTR(global_pooling, Bool, false)
  167. .ATTR(window, ListInt, {1,1}) // kernel size
  168. .ATTR(pad, ListInt, {0,0,0,0}) // pad size
  169. .ATTR(stride, ListInt, {1,1}) // stride size
  170. .ATTR(ceil_mode, Int, 0)
  171. .ATTR(data_mode, Int, 1)
  172. .ATTR(nan_opt, Int, 0)
  173. .ATTR(mean_grad_output_shape_value, ListInt, {1,1,1,1})
  174. .ATTR(mean_grad_output_shape_format, Int, 1) //must be NHWC
  175. .OP_END_FACTORY_REG(MeanGrad)
  176. REG_OP(MatMulCCE)
  177. .INPUT(x1, TensorType({DT_FLOAT}))
  178. .INPUT(x2, TensorType({DT_FLOAT}))
  179. .OPTIONAL_INPUT(x3, TensorType({DT_FLOAT}))
  180. .OUTPUT(y, TensorType({DT_FLOAT}))
  181. .ATTR(transpose_a, Bool, false)
  182. .ATTR(transpose_b, Bool, false)
  183. .ATTR(has_bias, Bool, false)
  184. .OP_END_FACTORY_REG(MatMulCCE)
  185. /**
  186. *@brief Computes half the L2 norm of a tensor without the sqrt.
  187. *@par Inputs:
  188. * x: A Tensor.
  189. * TensorType::FloatingDataType().
  190. *@par Outputs:
  191. *y: A Tensor. Has the same type as "x".
  192. *@par Third-party framework compatibility
  193. *Compatible with the TensorFlow operator L2Loss.
  194. */
  195. REG_OP(L2Loss)
  196. .INPUT(x, TensorType::FloatingDataType())
  197. .OUTPUT(y, TensorType::FloatingDataType())
  198. .OP_END_FACTORY_REG(L2Loss)
  199. /**
  200. *@brief: Returns a batched diagonal tensor with a given batched diagonal values.
  201. *@par Inputs:
  202. *x: A Tensor. Must be one of the following types:
  203. * float16, float32, double, int32, uint8, int16, int8, complex64, int64,
  204. * qint8, quint8, qint32, uint16, complex128, uint32, uint64.
  205. *@par Outputs:
  206. *y: A Tensor. Has the same type as "x".
  207. *@par Third-party framework compatibility
  208. * Compatible with the TensorFlow operator MatrixDiag.
  209. */
  210. REG_OP(MatrixDiag)
  211. .INPUT(x, TensorType::BasicType())
  212. .OUTPUT(y, TensorType::BasicType())
  213. .OP_END_FACTORY_REG(MatrixDiag)
  214. /**
  215. *@brief: Returns a batched diagonal tensor with a given batched diagonal values.
  216. *@par Inputs:
  217. * Two inputs, including:
  218. *@li x: A Tensor. Must be one of the following types: float16, float32, int32, int8, uint8.
  219. *@li assist: A Tensor of the same type as "x".
  220. *@par Outputs:
  221. *y: A Tensor. Has the same type as "x".
  222. *@par Third-party framework compatibility
  223. * Compatible with the TensorFlow operator MatrixDiag.
  224. */
  225. REG_OP(MatrixDiagD)
  226. .INPUT(x, TensorType::BasicType())
  227. .INPUT(assist, TensorType::BasicType())
  228. .OUTPUT(y, TensorType::BasicType())
  229. .OP_END_FACTORY_REG(MatrixDiagD)
  230. /**
  231. *@brief: Returns the batched diagonal part of a batched tensor.
  232. *@par Inputs:
  233. *x: A Tensor. Must be one of the following types:
  234. * float16, float32, double, int32, uint8, int16, int8, complex64, int64,
  235. * qint8, quint8, qint32, uint16, complex128, uint32, uint64.
  236. *@par Outputs:
  237. *y: A Tensor. Has the same type as "x".
  238. *@par Third-party framework compatibility
  239. * Compatible with the TensorFlow operator MatrixDiagPart.
  240. */
  241. REG_OP(MatrixDiagPart)
  242. .INPUT(x, TensorType::BasicType())
  243. .OUTPUT(y, TensorType::BasicType())
  244. .OP_END_FACTORY_REG(MatrixDiagPart)
  245. /**
  246. *@brief: Returns the batched diagonal part of a batched tensor.
  247. *@par Inputs:
  248. * Two inputs, including:
  249. *@li x: A Tensor. Must be one of the following types: float16, float32, int32, int8, uint8.
  250. *@li assist: A Tensor of the same type as "x".
  251. *@par Outputs:
  252. *y: A Tensor. Has the same type as "x".
  253. *@par Third-party framework compatibility
  254. * Compatible with the TensorFlow operator MatrixDiagPart.
  255. */
  256. REG_OP(MatrixDiagPartD)
  257. .INPUT(x, TensorType::BasicType())
  258. .INPUT(assist, TensorType::BasicType())
  259. .OUTPUT(y, TensorType::BasicType())
  260. .OP_END_FACTORY_REG(MatrixDiagPartD)
  261. /**
  262. *@brief: Returns a batched matrix tensor with new batched diagonal values.
  263. *@par Inputs:
  264. * Two inputs, including:
  265. *@li x: A Tensor. Must be one of the following types:
  266. * float16, float32, double, int32, uint8, int16, int8, complex64, int64,
  267. * qint8, quint8, qint32, uint16, complex128, uint32, uint64.
  268. *@li diagonal: A Tensor of the same type as "x".
  269. *@par Outputs:
  270. *y: A Tensor. Has the same type as "x".
  271. *@par Third-party framework compatibility
  272. * Compatible with the TensorFlow operator MatrixSetDiag.
  273. */
  274. REG_OP(MatrixSetDiag)
  275. .INPUT(x, TensorType::BasicType())
  276. .INPUT(diagonal, TensorType::BasicType())
  277. .OUTPUT(y, TensorType::BasicType())
  278. .OP_END_FACTORY_REG(MatrixSetDiag)
  279. /**
  280. *@brief: Returns a batched matrix tensor with new batched diagonal values.
  281. *@par Inputs:
  282. * Three inputs, including:
  283. *@li x: A Tensor. Must be one of the following types: float16, float32, int32, int8, uint8.
  284. *@li diagonal: A Tensor of the same type as "x".
  285. *@li assist: A Tensor of the same type as "x".
  286. *@par Outputs:
  287. *y: A Tensor. Has the same type as "x".
  288. *@par Third-party framework compatibility
  289. * Compatible with the TensorFlow operator MatrixSetDiag.
  290. */
  291. REG_OP(MatrixSetDiagD)
  292. .INPUT(x, TensorType::BasicType())
  293. .INPUT(diagonal, TensorType::BasicType())
  294. .INPUT(assist, TensorType::BasicType())
  295. .OUTPUT(y, TensorType::BasicType())
  296. .OP_END_FACTORY_REG(MatrixSetDiagD)
  297. /**
  298. *@brief Applies sparse "updates" to individual values or slices in a Variable.
  299. *@par Inputs:
  300. * Three inputs, including:
  301. *@li var: An ND Tensor.
  302. *Must be one of the following types: float16, float32, int8, uint8, double,
  303. * int64, complex64, qint8, quint8, qint32, uint16, complex128, half, uint32,
  304. * uint64
  305. *@li indices: An ND Tensor.
  306. *Must be one of the following types: int32, int64
  307. *@li updates: An ND Tensor.
  308. *Must be one of the following types: float16, float32, int8, uint8, double,
  309. * int64, complex64, qint8, quint8, qint32, uint16, complex128, half, uint32,
  310. * uint64
  311. *@par Attributes:
  312. *use_locking: An optional bool. Defaults to "False". If "True",
  313. * the operation will be protected by a lock.
  314. *@par Outputs:
  315. *var: A Tensor. Has the same type and format as input "var".
  316. *@par Third-party framework compatibility
  317. * Compatible with the TensorFlow operator ScatterNdUpdate.
  318. */
  319. REG_OP(ScatterNdUpdate)
  320. .INPUT(var, TensorType::BasicType())
  321. .INPUT(indices, TensorType::IndexNumberType())
  322. .INPUT(updates, TensorType::BasicType())
  323. .OUTPUT(var, TensorType::BasicType())
  324. .ATTR(use_locking, Bool, false)
  325. .OP_END_FACTORY_REG(ScatterNdUpdate)
  326. /**
  327. *@brief Applies sparse addition to individual values or slices in a Variable.
  328. *@par Inputs:
  329. * Three inputs, including:
  330. *@li x: An ND Tensor. \n
  331. *Must be one of the following types: float16, float32, bool, int8, uint8
  332. *@li indices: An ND Tensor. \n
  333. *Must be one of the following types: int32
  334. *@li updates: An ND Tensor. \n
  335. *Must be one of the following types: float16, float32, bool, int8, uint8
  336. *@par Outputs:
  337. *y: A Tensor. Has the same type and format as input "x".
  338. *@par Third-party framework compatibility
  339. * Compatible with the TensorFlow operator TensorScatterUpdate.
  340. */
  341. REG_OP(TensorScatterUpdate)
  342. .INPUT(x, TensorType::BasicType())
  343. .INPUT(indices, TensorType::IndexNumberType())
  344. .INPUT(updates, TensorType::BasicType())
  345. .OUTPUT(y, TensorType::BasicType())
  346. .OP_END_FACTORY_REG(TensorScatterUpdate)
  347. /**
  348. *@brief Adds sparse "updates" to a variable reference.
  349. *@par Inputs:
  350. * Three inputs, including:
  351. *@li var: An ND Tensor.
  352. *Must be one of the following types: float16, float32, int32, int8, uint8
  353. *@li indices: An ND Tensor of type int32 or int64.
  354. *@li updates: An Tensor. format:NCHW, NHWC.
  355. *Must be one of the following types: float16, float32, int32, int8, uint8
  356. *@par Attributes:
  357. *use_locking: An optional bool. Defaults to "False". If "True", the operation
  358. * will be protected by a lock.
  359. *@par Outputs:
  360. *var: A Tensor. Has the same type and format as input "var".
  361. *@par Third-party framework compatibility
  362. * Compatible with the TensorFlow operator ScatterAdd.
  363. */
  364. REG_OP(ScatterAdd)
  365. .INPUT(var, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  366. .INPUT(indices, TensorType::IndexNumberType())
  367. .INPUT(updates, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  368. .OUTPUT(var, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  369. .ATTR(use_locking, Bool, false)
  370. .OP_END_FACTORY_REG(ScatterAdd)
  371. /**
  372. *@brief Divides a variable reference by sparse updates.
  373. *@par Inputs:
  374. * Three inputs, including:
  375. *@li var: An ND Tensor.
  376. *Must be one of the following types: float16, float, int32, int8, uint8
  377. *@li indices: An ND Tensor.
  378. *Must be one of the following types: int32
  379. *@li updates: An ND Tensor.
  380. *Must be one of the following types: float16, float, int32, int8, uint8
  381. *@par Attributes:
  382. *@li use_locking: An optional bool. Defaults to "False". If "True",
  383. * the operation will be protected by a lock.
  384. *@par Outputs:
  385. *var: A Tensor. Has the same type and format as input "var".
  386. *@par Third-party framework compatibility
  387. * Compatible with the TensorFlow operator ScatterDiv.
  388. */
  389. REG_OP(ScatterDiv)
  390. .INPUT(var, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  391. .INPUT(indices, TensorType({DT_INT32}))
  392. .INPUT(updates, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  393. .OUTPUT(var, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  394. .ATTR(use_locking, Bool, false)
  395. .OP_END_FACTORY_REG(ScatterDiv)
  396. /**
  397. *@brief Applies sparse addition to individual values or slices in a Variable.
  398. *@par Inputs:
  399. * Three inputs, including:
  400. *@li var: An ND Tensor.
  401. *Must be one of the following types: float16, float, int32, int8, uint8
  402. *@li indices: An ND Tensor.
  403. *Must be one of the following types: int32
  404. *@li updates: An ND Tensor.
  405. *Must be one of the following types: float16, float, int32, int8, uint8
  406. *@par Attributes:
  407. *use_locking: An optional bool. Defaults to "False". If "True",
  408. * the operation will be protected by a lock.
  409. *@par Outputs:
  410. *var: A Tensor. Has the same type and format as input "var".
  411. *@par Third-party framework compatibility
  412. * Compatible with the TensorFlow operator ScatterNdAdd.
  413. */
  414. REG_OP(ScatterNdAdd)
  415. .INPUT(var, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  416. .INPUT(indices, TensorType::IndexNumberType())
  417. .INPUT(updates, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  418. .OUTPUT(var, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  419. .ATTR(use_locking, Bool, false)
  420. .OP_END_FACTORY_REG(ScatterNdAdd)
  421. /**
  422. *@brief Applies sparse addition to individual values or slices in a Variable.
  423. *@par Inputs:
  424. * Three inputs, including:
  425. *@li x: An ND Tensor. \n
  426. *Must be one of the following types: float16, float32, int32, int8, uint8
  427. *@li indices: An ND Tensor. \n
  428. *Must be one of the following types: int32
  429. *@li updates: An ND Tensor. \n
  430. *Must be one of the following types: float16, float32, int32, int8, uint8
  431. *@par Outputs:
  432. *y: A Tensor. Has the same type and format as input "x".
  433. *@par Third-party framework compatibility
  434. * Compatible with the TensorFlow operator TensorScatterAdd.
  435. */
  436. REG_OP(TensorScatterAdd)
  437. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  438. .INPUT(indices, TensorType::IndexNumberType())
  439. .INPUT(updates, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  440. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  441. .OP_END_FACTORY_REG(TensorScatterAdd)
  442. /**
  443. *@brief Applies sparse subtraction to individual values or slices in a Variable.
  444. *@par Inputs:
  445. * Three inputs, including:
  446. *@li var: An ND Tensor.
  447. *Must be one of the following types: float16, float, int32, int8, uint8
  448. *@li indices: An ND Tensor.
  449. *Must be one of the following types: int32, int64
  450. *@li updates: An ND Tensor.
  451. *Must be one of the following types: float16, float, int32, int8, uint8
  452. *@par Attributes:
  453. *use_locking: An optional bool. Defaults to "False". If "True",
  454. * the operation will be protected by a lock.
  455. *@par Outputs:
  456. *var: A Tensor. Has the same type and format as input "var".
  457. *@par Third-party framework compatibility
  458. * Compatible with the TensorFlow operator ScatterNdSub.
  459. */
  460. REG_OP(ScatterNdSub)
  461. .INPUT(var, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  462. .INPUT(indices, TensorType::IndexNumberType())
  463. .INPUT(updates, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  464. .OUTPUT(var, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  465. .ATTR(use_locking, Bool, false)
  466. .OP_END_FACTORY_REG(ScatterNdSub)
  467. /**
  468. *@brief Applies sparse addition to individual values or slices in a Variable.
  469. *@par Inputs:
  470. * Three inputs, including:
  471. *@li x: An ND Tensor. \n
  472. *Must be one of the following types: float16, float32, int32, int8, uint8
  473. *@li indices: An ND Tensor. \n
  474. *Must be one of the following types: int32
  475. *@li updates: An ND Tensor. \n
  476. *Must be one of the following types: float16, float32, int32, int8, uint8
  477. *@par Outputs:
  478. *y: A Tensor. Has the same type and format as input "x".
  479. *@par Third-party framework compatibility
  480. * Compatible with the TensorFlow operator TensorScatterSub.
  481. */
  482. REG_OP(TensorScatterSub)
  483. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  484. .INPUT(indices, TensorType::IndexNumberType())
  485. .INPUT(updates, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  486. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  487. .OP_END_FACTORY_REG(TensorScatterSub)
  488. /**
  489. *@brief Subtracts sparse updates to a variable reference.
  490. *@par Inputs:
  491. * Three inputs, including:
  492. *@li var: An ND Tensor.
  493. *Must be one of the following types: float16, float, int32, int8, uint8
  494. *@li indices: An ND Tensor.
  495. *Must be one of the following types: int32, int64
  496. *@li updates: An ND Tensor.
  497. *Must be one of the following types: float16, float, int32, int8, uint8
  498. *@par Attributes:
  499. *use_locking: An optional bool. Defaults to "False". If "True",
  500. * the operation will be protected by a lock.
  501. *@par Outputs:
  502. *var: A Tensor. Has the same type and format as input "var".
  503. *@par Third-party framework compatibility
  504. * Compatible with the TensorFlow operator ScatterSub.
  505. */
  506. REG_OP(ScatterSub)
  507. .INPUT(var, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  508. .INPUT(indices, TensorType::IndexNumberType())
  509. .INPUT(updates, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  510. .OUTPUT(var, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  511. .ATTR(use_locking, Bool, false)
  512. .OP_END_FACTORY_REG(ScatterSub)
  513. /**
  514. *@brief: Returns the batched diagonal part of a batched tensor with "assist".
  515. *@par Inputs:
  516. * Two inputs, including:
  517. * @li x: A Tensor of type float16, float32, or int32.
  518. * @li assist: A Tensor of the same type as "x".
  519. *@par Outputs:
  520. *y: A Tensor. Has the same type as "x".
  521. *@par Third-party framework compatibility
  522. * Compatible with the TensorFlow operator DiagPart.
  523. */
  524. REG_OP(DiagPartD)
  525. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
  526. .INPUT(assist, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
  527. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
  528. .OP_END_FACTORY_REG(DiagPartD)
  529. /**
  530. *@brief: Returns the batched diagonal part of a batched tensor.
  531. *@par Inputs:
  532. *x: A Tensor. Must be one of the following types:
  533. * float16, float32, int32, int64, double, complex64, complex128.
  534. *@par Outputs:
  535. *y: A Tensor. Has the same type as "x".
  536. *@par Third-party framework compatibility
  537. * Compatible with the TensorFlow operator DiagPart.
  538. */
  539. REG_OP(DiagPart)
  540. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32, DT_INT64, DT_DOUBLE,
  541. DT_COMPLEX64, DT_COMPLEX128}))
  542. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32, DT_INT64, DT_DOUBLE,
  543. DT_COMPLEX64, DT_COMPLEX128}))
  544. .OP_END_FACTORY_REG(DiagPart)
  545. /**
  546. *@brief Also known as a "fully-connected" layer, computes an inner product with a set of learned weights, and (optionally) adds biases.
  547. *@par Inputs:
  548. * Four inputs, including:
  549. *@li x: A Tensor of type float16, int8.
  550. *@li w: A weight matrix of type float16, int8.
  551. *@li b: A Tensor of type float16, int32, float32.
  552. *@li offset_w: A Tensor of type int8.
  553. *@par Attributes:
  554. *@li num_output: Reserved.
  555. *@li transpose: A bool, specifying whether to transpose, either "true" or "false". Defaults to "false".
  556. *@li axis: Optional. A int. 1 or 2.
  557. *@li offset_x: Reserved.
  558. *@par Outputs:
  559. *y: The result tensor of type float16, int32, float32.
  560. *@par Third-party framework compatibility
  561. * Compatible with the Caffe operator InnerProduct.
  562. *@par Quantization supported or not
  563. * Yes
  564. */
  565. REG_OP(FullyConnection)
  566. .INPUT(x, TensorType({DT_FLOAT16, DT_INT8}))
  567. .INPUT(w, TensorType({DT_FLOAT16, DT_INT8}))
  568. .OPTIONAL_INPUT(b, TensorType({DT_FLOAT16, DT_INT32,DT_FLOAT32}))
  569. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  570. .OUTPUT(y, TensorType({DT_FLOAT16, DT_INT32,DT_FLOAT32}))
  571. .REQUIRED_ATTR(num_output, Int)
  572. .ATTR(transpose, Bool, false)
  573. .ATTR(axis, Int, 1)
  574. .ATTR(offset_x, Int, 0)
  575. .OP_END_FACTORY_REG(FullyConnection)
  576. /**
  577. *@brief Computes the confusion matrix from predictions and labels.
  578. *@par Inputs:
  579. * Three inputs, including:
  580. *@li labels: A Tensor. Must be one of the following types: float16, float32,
  581. * int32, int8, uint8.
  582. *@li predictions: A Tensor. Must be one of the following types: float16,
  583. * float32, int32, int8, uint8.
  584. *@li weights: A Tensor. Must be one of the following types: float16, float32,
  585. * int32, int8, uint8.
  586. *@par Attributes:
  587. *@li num_classes: An integer for the shape of the output matrix.
  588. * No default value.
  589. *@li dtype: Data type of the confusion matrix. No default value.
  590. *@par Outputs:
  591. *y: A Tensor. Has the same type and format as input "labels"
  592. *@attention Constraints:
  593. *@li "weights", "labels", and "predictions" are 1D tensors.
  594. *@li The output is with shape (num_classes, num_classes),
  595. * where, 1 <= num_classes <= 4096.
  596. *@see Region()
  597. *@par Third-party framework compatibility
  598. * Compatible with the TensorFlow operator ConfusionMatrix.
  599. */
  600. REG_OP(ConfusionMatrix)
  601. .INPUT(labels, TensorType({DT_FLOAT, DT_INT32, DT_FLOAT16, DT_INT8, DT_UINT8}))
  602. .INPUT(predictions, TensorType({DT_FLOAT, DT_INT32, DT_FLOAT16, DT_INT8, DT_UINT8}))
  603. .OPTIONAL_INPUT(weights, TensorType({DT_FLOAT, DT_INT32, DT_FLOAT16, DT_INT8, DT_UINT8}))
  604. .OUTPUT(y, TensorType({DT_FLOAT, DT_INT32, DT_FLOAT16, DT_INT8, DT_UINT8}))
  605. .REQUIRED_ATTR(num_classes, Int)
  606. .REQUIRED_ATTR(dtype, String)
  607. .OP_END_FACTORY_REG(ConfusionMatrix)
  608. /**
  609. *@brief Multiplies sparse updates into a variable reference.
  610. *@par Inputs:
  611. * Three inputs, including:
  612. *@li var: An ND Tensor.
  613. *Must be one of the following types: float16, float, int32, int8, uint8
  614. *@li indices: An ND Tensor.
  615. *Must be one of the following types: int32
  616. *@li updates: An ND Tensor.
  617. *Must be one of the following types: float16, float, int32, int8, uint8
  618. *@par Attributes:
  619. *use_locking: An optional bool. Defaults to "False". If "True", the operation
  620. * will be protected by a lock.
  621. *@par Outputs:
  622. *var: A Tensor. Has the same type and format as input "var".
  623. *@par Third-party framework compatibility
  624. * Compatible with the TensorFlow operator ScatterMul.
  625. */
  626. REG_OP(ScatterMul)
  627. .INPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  628. .INPUT(indices, TensorType({DT_INT32}))
  629. .INPUT(updates, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  630. .OUTPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  631. .ATTR(use_locking, Bool, false)
  632. .OP_END_FACTORY_REG(ScatterMul)
  633. /**
  634. *@brief Reduces sparse updates into a variable reference using
  635. * the "min" operation.
  636. *@par Inputs:
  637. * Three inputs, including:
  638. *@li var: An ND Tensor.
  639. *Must be one of the following types: float16, float, int32
  640. *@li indices: An ND Tensor.
  641. *Must be one of the following types: int32
  642. *@li updates: An ND Tensor.
  643. *Must be one of the following types: float16, float, int32
  644. *@par Attributes:
  645. *use_locking: An optional bool. Defaults to "False". If "True", the operation
  646. * will be protected by a lock.
  647. *@par Outputs:
  648. *var: A Tensor. Has the same type and format as input "var".
  649. *@par Third-party framework compatibility
  650. * Compatible with the TensorFlow operator ScatterMin.
  651. */
  652. REG_OP(ScatterMin)
  653. .INPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32}))
  654. .INPUT(indices, TensorType({DT_INT32}))
  655. .INPUT(updates, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32}))
  656. .OUTPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32}))
  657. .ATTR(use_locking, Bool, false)
  658. .OP_END_FACTORY_REG(ScatterMin)
  659. /**
  660. *@brief Reduces sparse updates into a variable reference using the "max" operation.
  661. *@par Inputs:
  662. * Three inputs, including:
  663. *@li var: An ND Tensor.
  664. *Must be one of the following types: float16, float, int32
  665. *@li indices: An NCHW, NHWC, or ND Tensor.
  666. *Must be one of the following types: int32
  667. *@li updates: An NCHW, NHWC, or ND Tensor.
  668. *Must be one of the following types: float16, float, int32
  669. *@par Attributes:
  670. *use_locking: An optional bool. Defaults to "False".
  671. * If "True", the operation will be protected by a lock.
  672. *@par Outputs:
  673. *var: A Tensor. Has the same type and format as input "var".
  674. *@par Third-party framework compatibility
  675. * Compatible with the TensorFlow operator ScatterMax.
  676. */
  677. REG_OP(ScatterMax)
  678. .INPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32}))
  679. .INPUT(indices, TensorType({DT_INT32}))
  680. .INPUT(updates, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32}))
  681. .OUTPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32}))
  682. .ATTR(use_locking, Bool, false)
  683. .OP_END_FACTORY_REG(ScatterMax)
  684. /**
  685. *@brief Applies sparse updates to a variable reference.
  686. *@par Inputs:
  687. * Three inputs, including:
  688. *@li var: An ND Tensor.
  689. *Must be one of the following types: float16, float, int32, int8, uint8
  690. *@li indices: An ND Tensor.
  691. *Must be one of the following types: int32
  692. *@li updates: An ND Tensor.
  693. *Must be one of the following types: float16, float, int32, int8, uint8
  694. *@par Attributes:
  695. *use_locking: An optional bool. Defaults to "False". If "True",
  696. * the operation will be protected by a lock.
  697. *@par Outputs:
  698. *var: A Tensor. Has the same type and format as input "var".
  699. *@par Third-party framework compatibility
  700. * Compatible with the TensorFlow operator ScatterUpdate.
  701. */
  702. REG_OP(ScatterUpdate)
  703. .INPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT8,DT_UINT8}))
  704. .INPUT(indices, TensorType({DT_INT32}))
  705. .INPUT(updates, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT8,DT_UINT8}))
  706. .OUTPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT8,DT_UINT8}))
  707. .ATTR(use_locking, Bool, false)
  708. .OP_END_FACTORY_REG(ScatterUpdate)
  709. /**
  710. *@brief Returns a tensor with the `k[0]`-th to `k[1]`-th diagonals of the batched `input`.
  711. *@par Inputs:
  712. * Three inputs, including:
  713. *@li input: Rank `r` tensor where `r >= 2`. \n
  714. *@li k: \n
  715. *Diagonal offset(s). Positive value means superdiagonal, 0 refers to the main \n
  716. *diagonal, and negative value means subdiagonals. `k` can be a single integer \n
  717. *(for a single diagonal) or a pair of integers specifying the low and high ends \n
  718. *of a matrix band. `k[0]` must not be larger than `k[1]`. \n
  719. *@li padding_value: The value to fill the area outside the specified diagonal band with. \n
  720. *@par Outputs:
  721. *diagonal: The extracted diagonal(s).
  722. *@par Third-party framework compatibility
  723. * Compatible with the TensorFlow operator ScatterUpdate.
  724. */
  725. REG_OP(MatrixDiagPartV2)
  726. .INPUT(input, TensorType::BasicType())
  727. .INPUT(k, TensorType({DT_INT32}))
  728. .INPUT(padding_value, TensorType::BasicType())
  729. .OUTPUT(diagonal, TensorType::BasicType())
  730. .OP_END_FACTORY_REG(MatrixDiagPartV2)
  731. /**
  732. *@brief Returns a batched matrix tensor with new batched diagonal values.
  733. *@par Inputs:
  734. * Three inputs, including:
  735. *@li input: "Rank `r+1`, where `r >= 1`. \n
  736. *@li diagonal: Rank `r` when `k` is an integer or `k[0] == k[1]`. Otherwise, it has rank `r+1`. \n
  737. *@li k:
  738. *Diagonal offset(s). Positive value means superdiagonal, 0 refers to the main \n
  739. *diagonal, and negative value means subdiagonals. `k` can be a single integer \n
  740. *(for a single diagonal) or a pair of integers specifying the low and high ends \n
  741. *of a matrix band. `k[0]` must not be larger than `k[1]`. \n
  742. *@par Outputs:
  743. *output: Rank `r+1`, with `output.shape = input.shape`.
  744. *@par Third-party framework compatibility
  745. * Compatible with the TensorFlow operator ScatterUpdate.
  746. */
  747. REG_OP(MatrixSetDiagV2)
  748. .INPUT(input, TensorType::BasicType())
  749. .INPUT(diagonal, TensorType::BasicType())
  750. .INPUT(k, TensorType({DT_INT32}))
  751. .OUTPUT(output, TensorType::BasicType())
  752. .OP_END_FACTORY_REG(MatrixSetDiagV2)
  753. /**
  754. *@brief Returns a batched diagonal tensor with given batched diagonal values.
  755. *@par Inputs:
  756. * Five inputs, including:
  757. *@li diagonal: Rank `r`, where `r >= 1` \n
  758. *@li k:
  759. *Diagonal offset(s). Positive value means superdiagonal, 0 refers to the main \n
  760. *diagonal, and negative value means subdiagonals. `k` can be a single integer \n
  761. *(for a single diagonal) or a pair of integers specifying the low and high ends \n
  762. *of a matrix band. `k[0]` must not be larger than `k[1]`. \n
  763. *@li num_rows:
  764. *The number of rows of the output matrix. If it is not provided, the op assumes \n
  765. *the output matrix is a square matrix and infers the matrix size from k and the \n
  766. *innermost dimension of `diagonal`. \n
  767. *@li num_cols: An NCHW, NHWC, or ND Tensor.
  768. *The number of columns of the output matrix. If it is not provided, the op \n
  769. *assumes the output matrix is a square matrix and infers the matrix size from \n
  770. *k and the innermost dimension of `diagonal`. \n
  771. *@li padding_value: The number to fill the area outside the specified diagonal band with. \n
  772. *@par Outputs:
  773. *output: Has rank `r+1` when `k` is an integer or `k[0] == k[1]`, rank `r` otherwise.
  774. *@par Third-party framework compatibility
  775. * Compatible with the TensorFlow operator ScatterUpdate.
  776. */
  777. REG_OP(MatrixDiagV2)
  778. .INPUT(diagonal, TensorType::BasicType())
  779. .INPUT(k, TensorType({DT_INT32}))
  780. .INPUT(num_rows, TensorType({DT_INT32}))
  781. .INPUT(num_cols, TensorType({DT_INT32}))
  782. .INPUT(padding_value, TensorType::BasicType())
  783. .OUTPUT(output, TensorType::BasicType())
  784. .OP_END_FACTORY_REG(MatrixDiagV2)
  785. } // namespace ge
  786. #endif // GE_OP_MATRIX_CALCULATION_OPS_H

图引擎模块(GE)是MindSpore的一个子模块,其代码由C++实现,位于前端模块ME和底层硬件之间,起到承接作用。图引擎模块以ME下发的图作为输入,然后进行一系列的深度图优化操作,最后输出一张可以在底层硬件上高效运行的图。GE针对昇腾AI处理器的硬件结构特点,做了特定的优化工作,以此来充分发挥出昇腾AI处理器的强大算力。在进行模型训练/推理时,GE会被自动调用而用户并不感知。GE主要由GE API和GE Core两部分组成,详细的架构图如下所示