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

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