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 35 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
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007
  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 Also known as a "fully-connected-compress" layer, computes an inner product with a set of learned weights, and (optionally) adds biases.
  578. *@par Inputs:
  579. * Four inputs, including:
  580. *@li x: A Tensor of type uint8, int8.
  581. *@li w: A weight matrix of type int8, int8.
  582. *@li w: A compress index matrix of type int8, int8.
  583. *@li b: A Tensor of type float16, int32, int32.
  584. *@li offset_w: A Tensor of type int8.i
  585. *@par Attributes:
  586. *@li num_output: Reserved.
  587. *@li transpose: A bool, specifying whether to transpose, either "true" or "false". Defaults to "false".
  588. *@li axis: Reserved.
  589. *@li offset_x: Reserved.
  590. *@par Outputs:
  591. *y: The result tensor of type int32.
  592. *@par Third-party framework compatibility
  593. * Compatible with the Caffe operator InnerProduct.
  594. *@par Quantization supported or not
  595. * Yes
  596. */
  597. REG_OP(FullyConnectionCompress)
  598. .INPUT(x, TensorType({DT_UINT8, DT_INT8}))
  599. .INPUT(w, TensorType({DT_INT8}))
  600. .INPUT(comress_index, TensorType({DT_INT8}))
  601. .OPTIONAL_INPUT(b, TensorType({DT_INT32}))
  602. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  603. .OUTPUT(y, TensorType({DT_INT32}))
  604. .REQUIRED_ATTR(num_output, Int)
  605. .ATTR(transpose, Bool, false)
  606. .ATTR(axis, Int, 1)
  607. .ATTR(offset_x, Int, 0)
  608. .OP_END_FACTORY_REG(FullyConnectionCompress)
  609. /**
  610. *@brief Computes the confusion matrix from predictions and labels.
  611. *@par Inputs:
  612. * Three inputs, including:
  613. *@li labels: A Tensor. Must be one of the following types: float16, float32,
  614. * int32, int8, uint8.
  615. *@li predictions: A Tensor. Must be one of the following types: float16,
  616. * float32, int32, int8, uint8.
  617. *@li weights: A Tensor. Must be one of the following types: float16, float32,
  618. * int32, int8, uint8.
  619. *@par Attributes:
  620. *@li num_classes: An integer for the shape of the output matrix.
  621. * No default value.
  622. *@li dtype: Data type of the confusion matrix. No default value.
  623. *@par Outputs:
  624. *y: A Tensor. Has the same type and format as input "labels"
  625. *@attention Constraints:
  626. *@li "weights", "labels", and "predictions" are 1D tensors.
  627. *@li The output is with shape (num_classes, num_classes),
  628. * where, 1 <= num_classes <= 4096.
  629. *@see Region()
  630. *@par Third-party framework compatibility
  631. * Compatible with the TensorFlow operator ConfusionMatrix.
  632. */
  633. REG_OP(ConfusionMatrix)
  634. .INPUT(labels, TensorType({DT_FLOAT, DT_INT32, DT_FLOAT16, DT_INT8, DT_UINT8}))
  635. .INPUT(predictions, TensorType({DT_FLOAT, DT_INT32, DT_FLOAT16, DT_INT8, DT_UINT8}))
  636. .OPTIONAL_INPUT(weights, TensorType({DT_FLOAT, DT_INT32, DT_FLOAT16, DT_INT8, DT_UINT8}))
  637. .OUTPUT(y, TensorType({DT_FLOAT, DT_INT32, DT_FLOAT16, DT_INT8, DT_UINT8}))
  638. .REQUIRED_ATTR(num_classes, Int)
  639. .REQUIRED_ATTR(dtype, String)
  640. .OP_END_FACTORY_REG(ConfusionMatrix)
  641. /**
  642. *@brief Multiplies sparse updates into a variable reference.
  643. *@par Inputs:
  644. * Three inputs, including:
  645. *@li var: An ND Tensor.
  646. *Must be one of the following types: float16, float, int32, int8, uint8
  647. *@li indices: An ND Tensor.
  648. *Must be one of the following types: int32
  649. *@li updates: An ND Tensor.
  650. *Must be one of the following types: float16, float, int32, int8, uint8
  651. *@par Attributes:
  652. *use_locking: An optional bool. Defaults to "False". If "True", the operation
  653. * will be protected by a lock.
  654. *@par Outputs:
  655. *var: A Tensor. Has the same type and format as input "var".
  656. *@par Third-party framework compatibility
  657. * Compatible with the TensorFlow operator ScatterMul.
  658. */
  659. REG_OP(ScatterMul)
  660. .INPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  661. .INPUT(indices, TensorType({DT_INT32}))
  662. .INPUT(updates, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  663. .OUTPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  664. .ATTR(use_locking, Bool, false)
  665. .OP_END_FACTORY_REG(ScatterMul)
  666. /**
  667. *@brief Reduces sparse updates into a variable reference using
  668. * the "min" operation.
  669. *@par Inputs:
  670. * Three inputs, including:
  671. *@li var: An ND Tensor.
  672. *Must be one of the following types: float16, float, int32
  673. *@li indices: An ND Tensor.
  674. *Must be one of the following types: int32
  675. *@li updates: An ND Tensor.
  676. *Must be one of the following types: float16, float, int32
  677. *@par Attributes:
  678. *use_locking: An optional bool. Defaults to "False". If "True", the operation
  679. * will be protected by a lock.
  680. *@par Outputs:
  681. *var: A Tensor. Has the same type and format as input "var".
  682. *@par Third-party framework compatibility
  683. * Compatible with the TensorFlow operator ScatterMin.
  684. */
  685. REG_OP(ScatterMin)
  686. .INPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32}))
  687. .INPUT(indices, TensorType({DT_INT32}))
  688. .INPUT(updates, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32}))
  689. .OUTPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32}))
  690. .ATTR(use_locking, Bool, false)
  691. .OP_END_FACTORY_REG(ScatterMin)
  692. /**
  693. *@brief Reduces sparse updates into a variable reference using the "max" operation.
  694. *@par Inputs:
  695. * Three inputs, including:
  696. *@li var: An ND Tensor.
  697. *Must be one of the following types: float16, float, int32
  698. *@li indices: An NCHW, NHWC, or ND Tensor.
  699. *Must be one of the following types: int32
  700. *@li updates: An NCHW, NHWC, or ND Tensor.
  701. *Must be one of the following types: float16, float, int32
  702. *@par Attributes:
  703. *use_locking: An optional bool. Defaults to "False".
  704. * If "True", the operation will be protected by a lock.
  705. *@par Outputs:
  706. *var: A Tensor. Has the same type and format as input "var".
  707. *@par Third-party framework compatibility
  708. * Compatible with the TensorFlow operator ScatterMax.
  709. */
  710. REG_OP(ScatterMax)
  711. .INPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32}))
  712. .INPUT(indices, TensorType({DT_INT32}))
  713. .INPUT(updates, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32}))
  714. .OUTPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32}))
  715. .ATTR(use_locking, Bool, false)
  716. .OP_END_FACTORY_REG(ScatterMax)
  717. /**
  718. *@brief Applies sparse updates to a variable reference.
  719. *@par Inputs:
  720. * Three inputs, including:
  721. *@li var: An ND Tensor.
  722. *Must be one of the following types: float16, float, int32, int8, uint8
  723. *@li indices: An ND Tensor.
  724. *Must be one of the following types: int32
  725. *@li updates: An ND Tensor.
  726. *Must be one of the following types: float16, float, int32, int8, uint8
  727. *@par Attributes:
  728. *use_locking: An optional bool. Defaults to "False". If "True",
  729. * the operation will be protected by a lock.
  730. *@par Outputs:
  731. *var: A Tensor. Has the same type and format as input "var".
  732. *@par Third-party framework compatibility
  733. * Compatible with the TensorFlow operator ScatterUpdate.
  734. */
  735. REG_OP(ScatterUpdate)
  736. .INPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT8,DT_UINT8}))
  737. .INPUT(indices, TensorType({DT_INT32}))
  738. .INPUT(updates, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT8,DT_UINT8}))
  739. .OUTPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT8,DT_UINT8}))
  740. .ATTR(use_locking, Bool, false)
  741. .OP_END_FACTORY_REG(ScatterUpdate)
  742. /**
  743. *@brief Returns a tensor with the `k[0]`-th to `k[1]`-th diagonals of the batched `input`.
  744. *@par Inputs:
  745. * Three inputs, including:
  746. *@li input: Rank `r` tensor where `r >= 2`. \n
  747. *@li k: \n
  748. *Diagonal offset(s). Positive value means superdiagonal, 0 refers to the main \n
  749. *diagonal, and negative value means subdiagonals. `k` can be a single integer \n
  750. *(for a single diagonal) or a pair of integers specifying the low and high ends \n
  751. *of a matrix band. `k[0]` must not be larger than `k[1]`. \n
  752. *@li padding_value: The value to fill the area outside the specified diagonal band with. \n
  753. *@par Outputs:
  754. *diagonal: The extracted diagonal(s).
  755. *@par Third-party framework compatibility
  756. * Compatible with the TensorFlow operator ScatterUpdate.
  757. */
  758. REG_OP(MatrixDiagPartV2)
  759. .INPUT(input, TensorType::BasicType())
  760. .INPUT(k, TensorType({DT_INT32}))
  761. .INPUT(padding_value, TensorType::BasicType())
  762. .OUTPUT(diagonal, TensorType::BasicType())
  763. .OP_END_FACTORY_REG(MatrixDiagPartV2)
  764. /**
  765. *@brief Returns a batched matrix tensor with new batched diagonal values.
  766. *@par Inputs:
  767. * Three inputs, including:
  768. *@li input: "Rank `r+1`, where `r >= 1`. \n
  769. *@li diagonal: Rank `r` when `k` is an integer or `k[0] == k[1]`. Otherwise, it has rank `r+1`. \n
  770. *@li k:
  771. *Diagonal offset(s). Positive value means superdiagonal, 0 refers to the main \n
  772. *diagonal, and negative value means subdiagonals. `k` can be a single integer \n
  773. *(for a single diagonal) or a pair of integers specifying the low and high ends \n
  774. *of a matrix band. `k[0]` must not be larger than `k[1]`. \n
  775. *@par Outputs:
  776. *output: Rank `r+1`, with `output.shape = input.shape`.
  777. *@par Third-party framework compatibility
  778. * Compatible with the TensorFlow operator ScatterUpdate.
  779. */
  780. REG_OP(MatrixSetDiagV2)
  781. .INPUT(input, TensorType::BasicType())
  782. .INPUT(diagonal, TensorType::BasicType())
  783. .INPUT(k, TensorType({DT_INT32}))
  784. .OUTPUT(output, TensorType::BasicType())
  785. .OP_END_FACTORY_REG(MatrixSetDiagV2)
  786. /**
  787. *@brief Returns a batched diagonal tensor with given batched diagonal values.
  788. *@par Inputs:
  789. * Five inputs, including:
  790. *@li diagonal: Rank `r`, where `r >= 1` \n
  791. *@li k:
  792. *Diagonal offset(s). Positive value means superdiagonal, 0 refers to the main \n
  793. *diagonal, and negative value means subdiagonals. `k` can be a single integer \n
  794. *(for a single diagonal) or a pair of integers specifying the low and high ends \n
  795. *of a matrix band. `k[0]` must not be larger than `k[1]`. \n
  796. *@li num_rows:
  797. *The number of rows of the output matrix. If it is not provided, the op assumes \n
  798. *the output matrix is a square matrix and infers the matrix size from k and the \n
  799. *innermost dimension of `diagonal`. \n
  800. *@li num_cols: An NCHW, NHWC, or ND Tensor.
  801. *The number of columns of the output matrix. If it is not provided, the op \n
  802. *assumes the output matrix is a square matrix and infers the matrix size from \n
  803. *k and the innermost dimension of `diagonal`. \n
  804. *@li padding_value: The number to fill the area outside the specified diagonal band with. \n
  805. *@par Outputs:
  806. *output: Has rank `r+1` when `k` is an integer or `k[0] == k[1]`, rank `r` otherwise.
  807. *@par Third-party framework compatibility
  808. * Compatible with the TensorFlow operator ScatterUpdate.
  809. */
  810. REG_OP(MatrixDiagV2)
  811. .INPUT(diagonal, TensorType::BasicType())
  812. .INPUT(k, TensorType({DT_INT32}))
  813. .INPUT(num_rows, TensorType({DT_INT32}))
  814. .INPUT(num_cols, TensorType({DT_INT32}))
  815. .INPUT(padding_value, TensorType::BasicType())
  816. .OUTPUT(output, TensorType::BasicType())
  817. .OP_END_FACTORY_REG(MatrixDiagV2)
  818. } // namespace ge
  819. #endif // GE_OP_MATRIX_CALCULATION_OPS_H

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