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 66 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
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
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
5 years ago
5 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
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
3 years ago
5 years ago
3 years ago
3 years ago
3 years ago
5 years ago
3 years ago
5 years ago
3 years ago
5 years ago
3 years ago
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
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
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
3 years ago
3 years ago
3 years ago
3 years ago
5 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820
  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 Backprop W of AttentionLnQKV + ReduceSumD \n
  26. * @par Inputs:
  27. * Four inputs, including:
  28. * @li x: A Tensor. Must be one of the following types: float16.
  29. * @li query_dx: A Tensor. Must be one of the following types: float16.
  30. * @li key_dw: A Tensor. Must be one of the following types: float16.
  31. * @li value_dw: A Tensor. Must be one of the following types: float16.
  32. * @par Attributes:
  33. * @li trans_a: A optional attribute, the type is bool. Defaults to True.
  34. * @li trans_b: A optional attribute, the type is bool. Defaults to False. \n
  35. * @par Outputs:
  36. * Six outputs, including:
  37. * @li dw_query: A Tensor. Must be one of the following types: float16.
  38. * @li dw_key: A Tensor. Must be one of the following types: float16.
  39. * @li dw_value: A Tensor. Must be one of the following types: float16.
  40. * @li dbias_query: A Tensor. Must be one of the following types: float16.
  41. * @li dbias_key: A Tensor. Must be one of the following types: float16.
  42. * @li dbias_value: A Tensor. Must be one of the following types: float16. \n
  43. * @par Restrictions:
  44. * Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use. \n
  45. */
  46. REG_OP(AttentionQKVGradW)
  47. .INPUT(x, TensorType({DT_FLOAT16}))
  48. .INPUT(query_dx, TensorType({DT_FLOAT16}))
  49. .OPTIONAL_INPUT(key_dw, TensorType({DT_FLOAT16}))
  50. .OPTIONAL_INPUT(value_dw, TensorType({DT_FLOAT16}))
  51. .OUTPUT(dw_query, TensorType({DT_FLOAT16}))
  52. .OUTPUT(dw_key, TensorType({DT_FLOAT16}))
  53. .OUTPUT(dw_value, TensorType({DT_FLOAT16}))
  54. .OUTPUT(dbias_query, TensorType({DT_FLOAT16}))
  55. .OUTPUT(dbias_key, TensorType({DT_FLOAT16}))
  56. .OUTPUT(dbias_value, TensorType({DT_FLOAT16}))
  57. .ATTR(trans_a, Bool, true)
  58. .ATTR(trans_b, Bool, false)
  59. .OP_END_FACTORY_REG(AttentionQKVGradW)
  60. /**
  61. * @brief Backprop X of AttentionLnQKV + AddN \n
  62. * @par Inputs:
  63. * Seven inputs, including:
  64. * @li ln_dx: A Tensor. Must be one of the following types: float16.
  65. * @li query_dx: A Tensor. Must be one of the following types: float16.
  66. * @li key_dw: A Tensor. Must be one of the following types: float16.
  67. * @li value_dw: A Tensor. Must be one of the following types: float16.
  68. * @li kernel_query: A Tensor. Must be one of the following types: float16.
  69. * @li kernel_key: A Tensor. Must be one of the following types: float16.
  70. * @li kernel_value: A Tensor. Must be one of the following types: float16. \n
  71. * @par Attributes:
  72. * @li trans_a: A optional attribute, the type is bool. Defaults to False.
  73. * @li trans_b: A optional attribute, the type is bool. Defaults to True. \n
  74. * @par Outputs:
  75. * One outputs, including:
  76. * @li dx: A Tensor. Must be one of the following types: float16. \n
  77. * @par Restrictions:
  78. * Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use. \n
  79. */
  80. REG_OP(AttentionQKVGradX)
  81. .INPUT(ln_dx, TensorType({DT_FLOAT16}))
  82. .INPUT(query_dx, TensorType({DT_FLOAT16}))
  83. .INPUT(key_dw, TensorType({DT_FLOAT16}))
  84. .INPUT(value_dw, TensorType({DT_FLOAT16}))
  85. .INPUT(kernel_query, TensorType({DT_FLOAT16}))
  86. .INPUT(kernel_key, TensorType({DT_FLOAT16}))
  87. .INPUT(kernel_value, TensorType({DT_FLOAT16}))
  88. .OUTPUT(dx, TensorType({DT_FLOAT16}))
  89. .ATTR(trans_a, Bool, false)
  90. .ATTR(trans_b, Bool, true)
  91. .OP_END_FACTORY_REG(AttentionQKVGradX)
  92. /**
  93. * @brief
  94. / (MatMul -> ConfusionTransposeD).
  95. LayerNorm - (MatMul -> ConfusionTransposeD).
  96. \ (MatMul -> ConfusionTransposeD). \n
  97. * @par Inputs:
  98. * Nine inputs, including:
  99. * @li x: A Tensor. Must be one of the following types: float16.
  100. * @li kernel_query: A Tensor. Must be one of the following types: float16.
  101. * @li kernel_key: A Tensor. Must be one of the following types: float16.
  102. * @li kernel_value: A Tensor. Must be one of the following types: float16.
  103. * @li gamma: A Tensor. Must be one of the following types: float16.
  104. * @li beta: A Tensor. Must be one of the following types: float16.
  105. * @li bias_query: A Tensor. Must be one of the following types: float16.
  106. * @li bias_key: A Tensor. Must be one of the following types: float16.
  107. * @li bias_value: A Tensor. Must be one of the following types: float16. \n
  108. * @par Attributes:
  109. * @li epsilon: A optional attribute, the type is float32. Defaults to 1e-7.
  110. * @li trans_a: A optional attribute, the type is bool. Defaults to False.
  111. * @li trans_b: A optional attribute, the type is bool. Defaults to False. \n
  112. * @par Outputs:
  113. * Six outputs, including:
  114. * @li norm: A Tensor. Must be one of the following types: float16.
  115. * @li query_output: A Tensor. Must be one of the following types: float16.
  116. * @li key_output: A Tensor. Must be one of the following types: float16.
  117. * @li value_output: A Tensor. Must be one of the following types: float16.
  118. * @li mean: A Tensor. Must be one of the following types: float16.
  119. * @li variance: A Tensor. Must be one of the following types: float16. \n
  120. * @par Restrictions:
  121. * Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use. \n
  122. */
  123. REG_OP(AttentionLnQKV)
  124. .INPUT(x, TensorType({DT_FLOAT16}))
  125. .INPUT(kernel_query, TensorType({DT_FLOAT16}))
  126. .INPUT(kernel_key, TensorType({DT_FLOAT16}))
  127. .INPUT(kernel_value, TensorType({DT_FLOAT16}))
  128. .INPUT(gamma, TensorType({DT_FLOAT16}))
  129. .INPUT(beta, TensorType({DT_FLOAT16}))
  130. .OPTIONAL_INPUT(bias_query, TensorType({DT_FLOAT16}))
  131. .OPTIONAL_INPUT(bias_key, TensorType({DT_FLOAT16}))
  132. .OPTIONAL_INPUT(bias_value, TensorType({DT_FLOAT16}))
  133. .OUTPUT(norm, TensorType({DT_FLOAT16}))
  134. .OUTPUT(query_output, TensorType({DT_FLOAT16}))
  135. .OUTPUT(key_output, TensorType({DT_FLOAT16}))
  136. .OUTPUT(value_output, TensorType({DT_FLOAT16}))
  137. .OUTPUT(mean, TensorType({DT_FLOAT16}))
  138. .OUTPUT(variance, TensorType({DT_FLOAT16}))
  139. .ATTR(epsilon, Float, 0.0000001)
  140. .ATTR(trans_a, Bool, false)
  141. .ATTR(trans_b, Bool, false)
  142. .OP_END_FACTORY_REG(AttentionLnQKV)
  143. /**
  144. * @brief
  145. swin_transformer model specific structure.Operator only supports swin_transformer. \n
  146. * @par Inputs:
  147. * Five inputs, including:
  148. * @li x: A Tensor. Must be one of the following types: float16.
  149. * @li gamma: A Tensor. Must be one of the following types: float16.
  150. * @li beta: A Tensor. Must be one of the following types: float16.
  151. * @li weight: A Tensor. Must be one of the following types: float16.
  152. * @li bias: A Tensor. Must be one of the following types: float16. \n
  153. * @par Attributes:
  154. * @li head_num: A optional attribute, the type is int.
  155. * @li head_dim: A optional attribute, the type is int.
  156. * @li seq_length: A optional attribute, the type is int.
  157. * @li shifts: A optional attribute, the type is list int. Defaults to ().
  158. * @li epsilon: A optional attribute, the type is float. Defaults to 1e-7. \n
  159. * @par Outputs:
  160. * Three outputs, including:
  161. * @li query_output: A Tensor. Must be one of the following types: float16.
  162. * @li key_output: A Tensor. Must be one of the following types: float16.
  163. * @li value_output: A Tensor. Must be one of the following types: float16. \n
  164. * @par Restrictions:
  165. * Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use. \n
  166. */
  167. REG_OP(SwinTransformerLnQKV)
  168. .INPUT(x, TensorType({DT_FLOAT16}))
  169. .INPUT(gamma, TensorType({DT_FLOAT16}))
  170. .INPUT(beta, TensorType({DT_FLOAT16}))
  171. .INPUT(weight, TensorType({DT_FLOAT16}))
  172. .INPUT(bias, TensorType({DT_FLOAT16}))
  173. .OUTPUT(query_output, TensorType({DT_FLOAT16}))
  174. .OUTPUT(key_output, TensorType({DT_FLOAT16}))
  175. .OUTPUT(value_output, TensorType({DT_FLOAT16}))
  176. .REQUIRED_ATTR(head_num, Int)
  177. .REQUIRED_ATTR(head_dim, Int)
  178. .REQUIRED_ATTR(seq_length, Int)
  179. .ATTR(shifts, ListInt, {})
  180. .ATTR(epsilon, Float, 0.0000001)
  181. .OP_END_FACTORY_REG(SwinTransformerLnQKV)
  182. /**
  183. *@brief Multiplies matrix "a" by matrix "b", producing "a * b". \n
  184. *@par Inputs:
  185. *Three inputs, including:
  186. * @li x1: A matrix Tensor. 2D. Must be one of the following types: float16,
  187. * float32, int32, bfloat16. Has format [ND, NHWC].
  188. * @li x2: A matrix Tensor. 2D. Must be one of the following types: float16,
  189. * float32, int32, bfloat16. Has format [ND, NHWC].
  190. * @li bias: A optional 1D Tensor. Must be one of the following types: float16,
  191. * float32, int32, bfloat16. Has format [ND, NHWC]. \n
  192. *@par Attributes:
  193. *@li transpose_x1: A bool. If True, changes the shape of "x1" from [M, K] to
  194. * [K, M].
  195. *@li transpose_x2: A bool. If True, changes the shape of "x2" from [M, K] to
  196. * [K, M]. \n
  197. *@par Outputs:
  198. *y: The result matrix Tensor. 2D. Must be one of the following types: float16,
  199. * float32, int32, bfloat16. Has format [ND, NHWC]. \n
  200. *@par Third-party framework compatibility
  201. * Compatible with the TensorFlow operator BatchMatmul.
  202. */
  203. REG_OP(MatMul)
  204. .INPUT(x1, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32, DT_BF16}))
  205. .INPUT(x2, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32, DT_BF16}))
  206. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32, DT_BF16}))
  207. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32, DT_BF16}))
  208. .ATTR(transpose_x1, Bool, false)
  209. .ATTR(transpose_x2, Bool, false)
  210. .OP_END_FACTORY_REG(MatMul)
  211. /**
  212. *@brief Multiplies matrix "a" by matrix "b", producing "a * b". \n
  213. *@par Inputs:
  214. *Four inputs, including:
  215. * @li x1: A matrix Tensor. 2D. Must be one of the following types: float32,
  216. * float16, int32, int8, int4, bfloat16. Has format [ND, NHWC].
  217. * @li x2: A matrix Tensor. 2D. Must be one of the following types: float32,
  218. * float16, int32, int8, int4, bfloat16. Has format [ND, NHWC].
  219. * @li bias: A 1D Tensor. Must be one of the following types: float32,
  220. * float16, int32 bfloat16. Has format [ND, NHWC].
  221. * @li offset_w: A Optional 1D Tensor for quantized inference. Type is int8.
  222. * Reserved. \n
  223. *@par Attributes:
  224. * @li transpose_x1: A bool. If True, changes the shape of "x1" from [K, M] to
  225. * [M, K].
  226. * @li transpose_x2: A bool. If True, changes the shape of "x2" from [N, K] to
  227. [K, N].
  228. * @li offset_x: An optional integer for quantized MatMulV2.
  229. * The negative offset added to the input x1 for int8 type. Ensure offset_x
  230. * within the effective range of int8 [-128, 127]. Defaults to "0". \n
  231. *@par Outputs:
  232. *y: The result matrix Tensor. 2D. Must be one of the following types: float32,
  233. * float16, int32, bfloat16. Has format [ND, NHWC]. \n
  234. *@attention Constraints:
  235. * if performances better in format NZ, please close
  236. * "MatmulTransdataFusionPass" in fusion configuration. \n
  237. *@par Third-party framework compatibility
  238. * Compatible with the TensorFlow operator BatchMatmul.
  239. */
  240. REG_OP(MatMulV2)
  241. .INPUT(x1, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32, DT_INT8, DT_INT4, DT_BF16}))
  242. .INPUT(x2, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32, DT_INT8, DT_INT4, DT_BF16}))
  243. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32, DT_BF16}))
  244. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32, DT_BF16}))
  245. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8, DT_INT4}))
  246. .ATTR(transpose_x1, Bool, false)
  247. .ATTR(transpose_x2, Bool, false)
  248. .ATTR(offset_x, Int, 0)
  249. .OP_END_FACTORY_REG(MatMulV2)
  250. /**
  251. *@brief Multiplies matrix "a" by matrix "b", producing "a * b". \n
  252. *@par Inputs:
  253. *Five inputs, including:
  254. * @li x1: A matrix Tensor. 2D. Must be one of the following types: int8.
  255. * @li x2: A matrix Tensor. 2D. Must be one of the following types: int8.
  256. * @li compress_index: A compress index matrix of type int8.
  257. * @li bias: An optional Tensor. 1D. Must be one of the following types: int32,
  258. * float16.
  259. * @li offset_w: An optional matrix Tensor. 2D. Must be one of the following
  260. * types: int8. \n
  261. *@par Attributes:
  262. *@li transpose_x1: A bool. If True, changes the shape of "x1" from [K, M] to
  263. * [M, K].
  264. *@li transpose_x2: A bool. If True, changes the shape of "x2" from [N, K] to
  265. * [K, N].
  266. *@li offset_x: An optional integer for quantized MatMulV2Compress.
  267. *The negative offset added to the input x1 for int8 type. Ensure offset_x
  268. * within the effective range of int8 [-128, 127]. Defaults to "0". \n
  269. *@par Outputs:
  270. *y: The result matrix Tensor. 2D. Must be one of the following types: int32,
  271. * float16. \n
  272. *@attention Constraints:
  273. * if performances better in format NZ, please close
  274. * "MatmulTransdataFusionPass" in fusion configuration.
  275. */
  276. REG_OP(MatMulV2Compress)
  277. .INPUT(x1, TensorType({DT_INT8}))
  278. .INPUT(x2, TensorType({DT_INT8}))
  279. .INPUT(compress_index, TensorType({DT_INT8}))
  280. .OPTIONAL_INPUT(bias, TensorType({DT_INT32, DT_FLOAT16}))
  281. .OUTPUT(y, TensorType({DT_INT32, DT_FLOAT16}))
  282. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  283. .ATTR(transpose_x1, Bool, false)
  284. .ATTR(transpose_x2, Bool, false)
  285. .ATTR(offset_x, Int, 0)
  286. .OP_END_FACTORY_REG(MatMulV2Compress)
  287. /**
  288. *@brief Performs Matrix-to-matrix Multiply,
  289. * producing y=alpha[0]*a*b+beta[0]*c. \n
  290. *@attention Constraints:
  291. * For better performance, The k-axis must be aligned to 16 (input type
  292. * is float16) or 32 (input type is int8). \n
  293. *@par Inputs:
  294. *Five inputs, including:
  295. * @li a: A matrix Tensor. Must be one of the following types:float32, float16,
  296. * int8, int32. Has format ND.
  297. * @li b: A matrix Tensor. Must be one of the following types:float32, float16,
  298. * int8, int32. Has format ND.
  299. *@li c: A matrix Tensor. Must be one of the following types:float32, float16,
  300. * int8, int32. Has format ND.
  301. * @li alpha: A 1D Tensor. The shape of alpha is [1].Must be one of the
  302. * following types: float16, int32, float32, int8. Has format ND.
  303. *@li beta: A 1D Tensor. The shape of beta is [1]. Must be one of the following
  304. * types: float16, int32, float32, int8. Has format ND.\n
  305. * The format of a, b, c has restriction:\n
  306. * When type of a is int8 and type of c is int32, the format of a, b, c should
  307. * all be ND.\n
  308. * When type of a is int8 and type of c is float32, the format of a, b, c
  309. * should all be ND.\n
  310. * When type of a is float16 and type of c is float16, the format of a, b, c
  311. * should all be ND.\n
  312. * When type of a is float16 and type of c is float32, the format of a, b, c
  313. * should all be ND. \n
  314. *@par Attributes:
  315. *Two attributes, including:
  316. *@li transpose_a: Optional. A bool. If True, changes the shape of "a" from
  317. * [M, K] to [K, M].
  318. *@li transpose_b: Optional. A bool. If True, changes the shape of "b" from
  319. * [K, N] to [N, K]. \n
  320. *@par Outputs:
  321. *y: The result matrix Tensor. Must be one of the following types: float16,
  322. * float32, int32. Has format [ND], the format should be equal to a.
  323. */
  324. REG_OP(GEMM)
  325. .INPUT(a, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT32}))
  326. .INPUT(b, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT32}))
  327. .INPUT(c, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT32}))
  328. .INPUT(alpha, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT32}))
  329. .INPUT(beta, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT32}))
  330. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT32}))
  331. .ATTR(transpose_a, Bool, false)
  332. .ATTR(transpose_b, Bool, false)
  333. .OP_END_FACTORY_REG(GEMM)
  334. /**
  335. *@brief Multiplies matrix "a" by matrix "b", producing "a * b". \n
  336. *@par Inputs:
  337. *Two inputs, including:
  338. * @li x1: A matrix Tensor. Must be one of the following types: float16,
  339. * float32, int32, bfloat16. 2D or higher. Has format [ND, NHWC].
  340. * @li x2: A matrix Tensor. Must be one of the following types: float16,
  341. * float32, int32, bfloat16. 2D or higher. Has format [ND, NHWC]. \n
  342. *@par Attributes:
  343. *@li adj_x1: A bool. If True, changes the shape of "x1" from [B, M, K]
  344. * to [B, K, M].
  345. *@li adj_x2: A bool. If True, changes the shape of "x2" from [B, M, K]
  346. * to [B, K, M]. \n
  347. *@par Outputs:
  348. * y: The result matrix Tensor. 2D or higher. Must be one of the following
  349. * types: float16, bfloat16,
  350. * float32, int32. 2D or higher. Has format [ND, NHWC]. Has the same shape
  351. * length as "x1" and "x2". \n
  352. *@par Third-party framework compatibility
  353. * Compatible with the TensorFlow operator BatchMatmul.
  354. */
  355. REG_OP(BatchMatMul)
  356. .INPUT(x1, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32, DT_BF16}))
  357. .INPUT(x2, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32, DT_BF16}))
  358. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32, DT_BF16}))
  359. .ATTR(adj_x1, Bool, false)
  360. .ATTR(adj_x2, Bool, false)
  361. .OP_END_FACTORY_REG(BatchMatMul)
  362. /**
  363. * @brief Multiplies matrix "a" by matrix "b", producing "a * b" . \n
  364. * @par Inputs:
  365. * Three inputs, including:
  366. * @li x1: A matrix Tensor. Must be one of the following types: float16,
  367. * float32, int32, int8, int4, bfloat16. 2D or higher. Has format [ND, NHWC].
  368. * @li x2: A matrix Tensor. Must be one of the following types: float16,
  369. * float32, int32, int8, int4, bfloat16. 2D or higher. Has format [ND, NHWC].
  370. * @li bias: A optional Tensor. Must be one of the following types:
  371. * float16,
  372. * float32, int32, int8, int4, bfloat16. Has format [ND, NHWC].
  373. * @li offset_w: A optional Tensor. Must be one of the following types:
  374. * int8, int4. Has format [ND, NHWC]. \n
  375. * @par Attributes:
  376. * @li adj_x1: A bool. If True, changes the shape of "x1" from [B, M, K] to
  377. * [B, K, M].
  378. * @li adj_x2: A bool. If True, changes the shape of "x2" from [B, M, K] to
  379. * [B, K, M]. \n
  380. * @par Outputs:
  381. * y: The result matrix Tensor. 2D or higher. Must be one of the following
  382. * types: float16,
  383. * float32, int32. 2D or higher. Has format [ND, NHWC]. Has the same shape
  384. * length as "x1" and "x2". \n
  385. *@attention Constraints:
  386. * if performances better in format NZ, please close
  387. * "MatmulTransdataFusionPass" in fusion configuration. \n
  388. * @par Third-party framework compatibility
  389. * Compatible with the TensorFlow operator BatchMatmul.
  390. */
  391. REG_OP(BatchMatMulV2)
  392. .INPUT(x1, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32, DT_INT8, DT_INT4, DT_BF16}))
  393. .INPUT(x2, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32, DT_INT8, DT_INT4, DT_BF16}))
  394. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32, DT_BF16}))
  395. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8, DT_INT4}))
  396. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32, DT_BF16}))
  397. .ATTR(adj_x1, Bool, false)
  398. .ATTR(adj_x2, Bool, false)
  399. .ATTR(offset_x, Int, 0)
  400. .OP_END_FACTORY_REG(BatchMatMulV2)
  401. /**
  402. *@brief Computes half the L2 norm of a tensor without the sqrt . \n
  403. *@par Inputs:
  404. * x: A Tensor.
  405. * TensorType::FloatingDataType() . \n
  406. *@par Outputs:
  407. *y: A Tensor. Has the same type as "x". \n
  408. *@attention Constraints:
  409. * if performances better in format NZ, please close
  410. "MatmulTransdataFusionPass" in fusion configuration. \n
  411. *@par Third-party framework compatibility
  412. *Compatible with the TensorFlow operator L2Loss.
  413. */
  414. REG_OP(L2Loss)
  415. .INPUT(x, TensorType::FloatingDataType())
  416. .OUTPUT(y, TensorType::FloatingDataType())
  417. .OP_END_FACTORY_REG(L2Loss)
  418. /**
  419. *@brief: Returns a batched diagonal tensor with a given batched diagonal values . \n
  420. *@par Inputs:
  421. *x: A Tensor. Must be one of the following types:
  422. * float16, float32, double, int32, uint8, int16, int8, complex64, int64,
  423. * qint8, quint8, qint32, uint16, complex128, uint32, uint64 . \n
  424. *@par Outputs:
  425. *y: A Tensor. Has the same type as "x" . \n
  426. *@par Third-party framework compatibility
  427. * Compatible with the TensorFlow operator MatrixDiag.
  428. */
  429. REG_OP(MatrixDiag)
  430. .INPUT(x, TensorType::BasicType())
  431. .OUTPUT(y, TensorType::BasicType())
  432. .OP_END_FACTORY_REG(MatrixDiag)
  433. /**
  434. *@brief: Returns a batched diagonal tensor with a given batched diagonal values . \n
  435. *@par Inputs:
  436. * Two inputs, including:
  437. *@li x: A Tensor. Must be one of the following types: float16, float32, int32, int8, uint8.
  438. *@li assist: A Tensor of the same type as "x" . \n
  439. *@par Outputs:
  440. *y: A Tensor. Has the same type as "x" . \n
  441. *@par Third-party framework compatibility
  442. * Compatible with the TensorFlow operator MatrixDiag.
  443. *
  444. * @par Restrictions:
  445. * Warning: THIS FUNCTION IS DEPRECATED. Please use MatrixDiag instead.
  446. */
  447. REG_OP(MatrixDiagD)
  448. .INPUT(x, TensorType::BasicType())
  449. .INPUT(assist, TensorType::BasicType())
  450. .OUTPUT(y, TensorType::BasicType())
  451. .OP_END_FACTORY_REG(MatrixDiagD)
  452. /**
  453. *@brief: Returns the batched diagonal part of a batched tensor . \n
  454. *@par Inputs:
  455. *x: A Tensor. Must be one of the following types:
  456. * float16, float32, double, int32, uint8, int16, int8, complex64, int64,
  457. * qint8, quint8, qint32, uint16, complex128, uint32, uint64 . \n
  458. *@par Outputs:
  459. *y: A Tensor. Has the same type as "x" . \n
  460. *@par Third-party framework compatibility
  461. * Compatible with the TensorFlow operator MatrixDiagPart.
  462. */
  463. REG_OP(MatrixDiagPart)
  464. .INPUT(x, TensorType::BasicType())
  465. .OUTPUT(y, TensorType::BasicType())
  466. .OP_END_FACTORY_REG(MatrixDiagPart)
  467. /**
  468. *@brief: Returns the batched diagonal part of a batched tensor . \n
  469. *@par Inputs:
  470. * Two inputs, including:
  471. *@li x: A Tensor. Must be one of the following types: float16, float32, int32, int8, uint8.
  472. *@li assist: A Tensor of the same type as "x" . \n
  473. *@par Outputs:
  474. *y: A Tensor. Has the same type as "x" . \n
  475. *@par Third-party framework compatibility
  476. * Compatible with the TensorFlow operator MatrixDiagPart.
  477. *
  478. * @par Restrictions:
  479. * Warning: THIS FUNCTION IS DEPRECATED. Please use MatrixDiagPart instead.
  480. */
  481. REG_OP(MatrixDiagPartD)
  482. .INPUT(x, TensorType::BasicType())
  483. .INPUT(assist, TensorType::BasicType())
  484. .OUTPUT(y, TensorType::BasicType())
  485. .OP_END_FACTORY_REG(MatrixDiagPartD)
  486. /**
  487. *@brief: Returns a batched matrix tensor with new batched diagonal values . \n
  488. *@par Inputs:
  489. * Two inputs, including:
  490. *@li x: A Tensor. Must be one of the following types:
  491. * float16, float32, double, int32, uint8, int16, int8, complex64, int64,
  492. * qint8, quint8, qint32, uint16, complex128, uint32, uint64.
  493. *@li diagonal: A Tensor of the same type as "x" . \n
  494. *@par Outputs:
  495. *y: A Tensor. Has the same type as "x" . \n
  496. *@par Third-party framework compatibility
  497. * Compatible with the TensorFlow operator MatrixSetDiag.
  498. */
  499. REG_OP(MatrixSetDiag)
  500. .INPUT(x, TensorType::BasicType())
  501. .INPUT(diagonal, TensorType::BasicType())
  502. .OUTPUT(y, TensorType::BasicType())
  503. .OP_END_FACTORY_REG(MatrixSetDiag)
  504. /**
  505. *@brief: Returns a batched matrix tensor with new batched diagonal values . \n
  506. *@par Inputs:
  507. * Three inputs, including:
  508. *@li x: A Tensor. Must be one of the following types: float16, float32, int32, int8, uint8.
  509. *@li diagonal: A Tensor of the same type as "x".
  510. *@li assist: A Tensor of the same type as "x" . \n
  511. *@par Outputs:
  512. *y: A Tensor. Has the same type as "x" . \n
  513. *@par Third-party framework compatibility
  514. * Compatible with the TensorFlow operator MatrixSetDiag.
  515. *
  516. * @par Restrictions:
  517. * Warning: THIS FUNCTION IS DEPRECATED. Please use MatrixSetDiag instead.
  518. */
  519. REG_OP(MatrixSetDiagD)
  520. .INPUT(x, TensorType::BasicType())
  521. .INPUT(diagonal, TensorType::BasicType())
  522. .INPUT(assist, TensorType::BasicType())
  523. .OUTPUT(y, TensorType::BasicType())
  524. .OP_END_FACTORY_REG(MatrixSetDiagD)
  525. /**
  526. * @brief Function AttentionScore. \n
  527. * @par Inputs:
  528. * six inputs, including:
  529. * @li query: A matrix Tensor. The type only support float16.
  530. * @li key: A matrix Tensor. The type only support float16.
  531. * @li value: A matrix Tensor. The type only support float16.
  532. * @li padding_mask: A matrix Tensor. The type only support float16.
  533. * @li scale: A scalar. The type only support float16.
  534. * @li drop_mask: A matrix Tensor. The type only support uint8. \n
  535. * @par Attributes:
  536. * @li keep_prob: A mutable Tensor. Must met all of the following rules:
  537. shape of "keep_prob" should be (1,) or [1,].
  538. * @li query_transpose: A bool. If True, changes the shape of "query" from [K, M] to
  539. [M, K].
  540. * @li key_transpose: A bool. If True, changes the shape of "key" from [N, K] to
  541. [K, N].
  542. * @li bmm_score_transpose_a: A bool. If True, changes the shape of "mid_data" from [K, M] to
  543. [M, K].
  544. * @li bmm_score_transpose_b: A bool. If True, changes the shape of "value" from [N, K] to
  545. [K, N].
  546. * @li axes: A list of int. The dimension softmax would be performed on. Defaults
  547. to "[-1]" . \n
  548. * @par Outputs:
  549. * attention_score: The result matrix Tensor. The type only support float16.
  550. * softmax_output: The result matrix Tensor. The type only support float16.
  551. * @par Restrictions:
  552. * Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  553. */
  554. REG_OP(AttentionScore)
  555. .INPUT(query, TensorType({DT_FLOAT16}))
  556. .INPUT(key, TensorType({DT_FLOAT16}))
  557. .INPUT(value, TensorType({DT_FLOAT16}))
  558. .INPUT(padding_mask, TensorType({DT_FLOAT16}))
  559. .INPUT(scale, TensorType({DT_FLOAT16}))
  560. .OPTIONAL_INPUT(drop_mask, TensorType({DT_INT8}))
  561. .OUTPUT(attention_score, TensorType({DT_FLOAT16}))
  562. .OUTPUT(softmax_output, TensorType({DT_FLOAT16}))
  563. .ATTR(keep_prob, Float, 1.0)
  564. .ATTR(query_transpose, Bool, false)
  565. .ATTR(key_transpose, Bool, false)
  566. .ATTR(bmm_score_transpose_a, Bool, false)
  567. .ATTR(bmm_score_transpose_b, Bool, false)
  568. .ATTR(softmax_axes, ListInt, {-1})
  569. .OP_END_FACTORY_REG(AttentionScore)
  570. /**
  571. *@brief Applies sparse "updates" to individual values or slices in a Variable . \n
  572. *@par Inputs:
  573. * Three inputs, including:
  574. *@li var: An ND Tensor.
  575. *Must be one of the following types: float16, float32, int8, uint8, double,
  576. * int64, complex64, qint8, quint8, qint32, uint16, complex128, half, uint32,
  577. * uint64
  578. *@li indices: An ND Tensor.
  579. *Must be one of the following types: int32 or int64
  580. *@li updates: An ND Tensor.
  581. *Must be one of the following types: float16, float32, int8, uint8, double,
  582. * int64, complex64, qint8, quint8, qint32, uint16, complex128, half, uint32,
  583. * uint64
  584. *@par Attributes:
  585. *use_locking: An optional bool. Defaults to "False". If "True",
  586. * the operation will be protected by a lock . \n
  587. *@par Outputs:
  588. *var: A Tensor. Has the same type and format as input "var" . \n
  589. *@par Third-party framework compatibility
  590. * Compatible with the TensorFlow operator ScatterNdUpdate.
  591. */
  592. REG_OP(ScatterNdUpdate)
  593. .INPUT(var, TensorType::BasicType())
  594. .INPUT(indices, TensorType::IndexNumberType())
  595. .INPUT(updates, TensorType::BasicType())
  596. .OUTPUT(var, TensorType::BasicType())
  597. .ATTR(use_locking, Bool, false)
  598. .OP_END_FACTORY_REG(ScatterNdUpdate)
  599. /**
  600. *@brief Applies sparse addition to individual values or slices in a Variable . \n
  601. *@par Inputs:
  602. * Three inputs, including:
  603. *@li x: An ND Tensor. \n
  604. *Must be one of the following types: float16, float32, bool, int8, uint8
  605. *@li indices: An ND Tensor. \n
  606. *Must be one of the following types: int32
  607. *@li updates: An ND Tensor. \n
  608. *Must be one of the following types: float16, float32, bool, int8, uint8
  609. *@par Outputs:
  610. *y: A Tensor. Has the same type and format as input "x" . \n
  611. *@par Third-party framework compatibility
  612. * Compatible with the TensorFlow operator TensorScatterUpdate.
  613. *@par Restrictions:
  614. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  615. */
  616. REG_OP(TensorScatterUpdate)
  617. .INPUT(x, TensorType::BasicType())
  618. .INPUT(indices, TensorType::IndexNumberType())
  619. .INPUT(updates, TensorType::BasicType())
  620. .OUTPUT(y, TensorType::BasicType())
  621. .OP_END_FACTORY_REG(TensorScatterUpdate)
  622. /**
  623. *@brief Uses "updates" to update tensor "data" by "indices". \n
  624. *@par Inputs:
  625. * Three inputs, including:
  626. *@li data: An ND Tensor . \n
  627. *Must be one of the following types: float16, float32, int32, int8, uint8
  628. *@li indices: An ND Tensor of type int32 or int64
  629. *@li updates: An Tensor. Same shape as indices. format:NCHW, NHWC . \n
  630. *Must be one of the following types: float16, float32, int32, int8, uint8
  631. *@par Attributes:
  632. *@li axis: An optional attribute. Defaults to 0.
  633. *@par Outputs:
  634. *y: A Tensor. Has the same type and format as input "data" . \n
  635. *@par Third-party framework compatibility
  636. * Compatible with the ONNX operator ScatterElements.
  637. */
  638. REG_OP(ScatterElements)
  639. .INPUT(data, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  640. .INPUT(indices, TensorType::IndexNumberType())
  641. .INPUT(updates, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  642. .OUTPUT(y, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  643. .ATTR(axis, Int, 0)
  644. .OP_END_FACTORY_REG(ScatterElements)
  645. /**
  646. *@brief Adds sparse "updates" to a variable reference . \n
  647. *@par Inputs:
  648. * Three inputs, including:
  649. *@li var: An ND Tensor .
  650. *Must be one of the following types: float16, float, int32, int8, uint8
  651. *@li indices: An ND Tensor . \n
  652. *Must be one of the following types: int32 or int64
  653. *@li updates: An ND Tensor .
  654. *Must be one of the following types: float16, float, int32, int8, uint8
  655. *@par Attributes:
  656. *use_locking: An optional bool. Defaults to "False". If "True",
  657. * the operation will be protected by a lock . \n
  658. *@par Outputs:
  659. *var: A Tensor. Has the same type and format as input "var" . \n
  660. *@par Third-party framework compatibility
  661. * Compatible with the TensorFlow operator ScatterAdd.
  662. */
  663. REG_OP(ScatterAdd)
  664. .INPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  665. .INPUT(indices, TensorType::IndexNumberType())
  666. .INPUT(updates, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  667. .OUTPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  668. .ATTR(use_locking, Bool, false)
  669. .OP_END_FACTORY_REG(ScatterAdd)
  670. /**
  671. *@brief Adds sparse "updates" to a variable reference . \n
  672. *@par Inputs:
  673. * Three inputs, including:
  674. *@li var: An ND Tensor .
  675. *Must be one of the following types: float16, float32, int32, int8, uint8
  676. *@li indices: An ND Tensor of type int32 or int64
  677. *@li updates: An ND Tensor .
  678. *Must be one of the following types: float16, float32, int32, int8, uint8
  679. *@par Attributes:
  680. * axis: An required int. The axis along which to index. \n
  681. *@par Outputs:
  682. *var: A Tensor. Has the same type and format as input "var" . \n
  683. *@par Third-party framework compatibility
  684. * Compatible with the pytorch operator ScatterAdd.
  685. */
  686. REG_OP(ScatterAddWithAxis)
  687. .INPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  688. .INPUT(indices, TensorType::IndexNumberType())
  689. .INPUT(updates, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  690. .OUTPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  691. .REQUIRED_ATTR(axis, Int)
  692. .OP_END_FACTORY_REG(ScatterAddWithAxis)
  693. /**
  694. *@brief Divides a variable reference by sparse updates . \n
  695. *@par Inputs:
  696. * Three inputs, including:
  697. *@li var: An ND Tensor.
  698. *Must be one of the following types: float16, float, int32, int8, uint8
  699. *@li indices: An ND Tensor.
  700. *Must be one of the following types: int32 or int64
  701. *@li updates: An ND Tensor.
  702. *Must be one of the following types: float16, float, int32, int8, uint8
  703. *@par Attributes:
  704. *use_locking: An optional bool. Defaults to "False". If "True",
  705. * the operation will be protected by a lock . \n
  706. *@par Outputs:
  707. *var: A Tensor. Has the same type and format as input "var" . \n
  708. *@par Third-party framework compatibility
  709. * Compatible with the TensorFlow operator ScatterDiv.
  710. */
  711. REG_OP(ScatterDiv)
  712. .INPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  713. .INPUT(indices, TensorType::IndexNumberType())
  714. .INPUT(updates, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  715. .OUTPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  716. .ATTR(use_locking, Bool, false)
  717. .OP_END_FACTORY_REG(ScatterDiv)
  718. /**
  719. *@brief Applies sparse addition to individual values or slices in a Variable . \n
  720. *@par Inputs:
  721. * Three inputs, including:
  722. *@li var: An ND Tensor.
  723. *Must be one of the following types: float16, float, int32, int8, uint8
  724. *@li indices: An ND Tensor.
  725. *Must be one of the following types: int32 or int64
  726. *@li updates: An ND Tensor.
  727. *Must be one of the following types: float16, float, int32, int8, uint8
  728. *@par Attributes:
  729. *use_locking: An optional bool. Defaults to "False". If "True",
  730. * the operation will be protected by a lock . \n
  731. *@par Outputs:
  732. *var: A Tensor. Has the same type and format as input "var" . \n
  733. *@par Third-party framework compatibility
  734. * Compatible with the TensorFlow operator ScatterNdAdd.
  735. */
  736. REG_OP(ScatterNdAdd)
  737. .INPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  738. .INPUT(indices, TensorType::IndexNumberType())
  739. .INPUT(updates, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  740. .OUTPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  741. .ATTR(use_locking, Bool, false)
  742. .OP_END_FACTORY_REG(ScatterNdAdd)
  743. /**
  744. *@brief Applies sparse addition to individual values or slices in a Variable . \n
  745. *@par Inputs:
  746. * Three inputs, including:
  747. *@li x: An ND Tensor. \n
  748. *Must be one of the following types: float16, float32, int32, int8, uint8
  749. *@li indices: An ND Tensor. \n
  750. *Must be one of the following types: int32
  751. *@li updates: An ND Tensor. \n
  752. * Must be one of the following types: float16, float32, int32, int8, uint8
  753. *@par Outputs:
  754. *y: A Tensor. Has the same type and format as input "x" . \n
  755. *@par Third-party framework compatibility
  756. * Compatible with the TensorFlow operator TensorScatterAdd.
  757. *@par Restrictions:
  758. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  759. */
  760. REG_OP(TensorScatterAdd)
  761. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  762. .INPUT(indices, TensorType::IndexNumberType())
  763. .INPUT(updates, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  764. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  765. .OP_END_FACTORY_REG(TensorScatterAdd)
  766. /**
  767. *@brief Applies sparse subtraction to individual values or slices in a Variable . \n
  768. *@par Inputs:
  769. * Three inputs, including:
  770. *@li var: An ND Tensor.
  771. *Must be one of the following types: float16, float, int32, int8, uint8
  772. *@li indices: An ND Tensor.
  773. *Must be one of the following types: int32 or int64
  774. *@li updates: An ND Tensor.
  775. *Must be one of the following types: float16, float, int32, int8, uint8
  776. *@par Attributes:
  777. *use_locking: An optional bool. Defaults to "False". If "True",
  778. * the operation will be protected by a lock . \n
  779. *@par Outputs:
  780. * var: A Tensor. Has the same type and format as input "var" . \n
  781. *@par Third-party framework compatibility
  782. * Compatible with the TensorFlow operator ScatterNdSub.
  783. */
  784. REG_OP(ScatterNdSub)
  785. .INPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  786. .INPUT(indices, TensorType::IndexNumberType())
  787. .INPUT(updates, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  788. .OUTPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  789. .ATTR(use_locking, Bool, false)
  790. .OP_END_FACTORY_REG(ScatterNdSub)
  791. /**
  792. *@brief Applies sparse addition to individual values or slices in a Variable . \n
  793. *@par Inputs:
  794. * Three inputs, including:
  795. *@li x: An ND Tensor. \n
  796. *Must be one of the following types: float16, float32, int32, int8, uint8
  797. *@li indices: An ND Tensor. \n
  798. *Must be one of the following types: int32
  799. *@li updates: An ND Tensor. \n
  800. *Must be one of the following types: float16, float32, int32, int8, uint8
  801. *@par Outputs:
  802. * y: A Tensor. Has the same type and format as input "x" . \n
  803. *@par Third-party framework compatibility
  804. * Compatible with the TensorFlow operator TensorScatterSub.
  805. *@par Restrictions:
  806. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  807. */
  808. REG_OP(TensorScatterSub)
  809. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  810. .INPUT(indices, TensorType::IndexNumberType())
  811. .INPUT(updates, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  812. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  813. .OP_END_FACTORY_REG(TensorScatterSub)
  814. /**
  815. *@brief Subtracts sparse updates to a variable reference . \n
  816. *@par Inputs:
  817. * Three inputs, including:
  818. *@li var: An ND Tensor.
  819. *Must be one of the following types: float16, float, int32, int8, uint8
  820. *@li indices: An ND Tensor.
  821. *Must be one of the following types: int32 or int64
  822. *@li updates: An ND Tensor.
  823. *Must be one of the following types: float16, float, int32, int8, uint8
  824. *@par Attributes:
  825. *use_locking: An optional bool. Defaults to "False". If "True",
  826. * the operation will be protected by a lock . \n
  827. *@par Outputs:
  828. * var: A Tensor. Has the same type and format as input "var" . \n
  829. *@par Third-party framework compatibility
  830. * Compatible with the TensorFlow operator ScatterSub.
  831. */
  832. REG_OP(ScatterSub)
  833. .INPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  834. .INPUT(indices, TensorType::IndexNumberType())
  835. .INPUT(updates, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  836. .OUTPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  837. .ATTR(use_locking, Bool, false)
  838. .OP_END_FACTORY_REG(ScatterSub)
  839. /**
  840. *@brief: Returns the batched diagonal part of a batched tensor with "assist" . \n
  841. *@par Inputs:
  842. * Two inputs, including:
  843. * @li x: A Tensor of type float16, float32, or int32.
  844. * @li assist: A Tensor of the same type as "x" . \n
  845. *@par Outputs:
  846. *y: A Tensor. Has the same type as "x" . \n
  847. *@par Third-party framework compatibility
  848. * Compatible with the TensorFlow operator DiagPart.
  849. *
  850. * @par Restrictions:
  851. * Warning: THIS FUNCTION IS DEPRECATED. Please use DiagPart instead.
  852. */
  853. REG_OP(DiagPartD)
  854. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
  855. .INPUT(assist, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
  856. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
  857. .OP_END_FACTORY_REG(DiagPartD)
  858. /**
  859. *@brief: Returns the batched diagonal part of a batched tensor . \n
  860. *@par Inputs:
  861. *x: A Tensor. Must be one of the following types:
  862. * float16, float32, int32, int64, double, complex64, complex128 . \n
  863. *@par Outputs:
  864. *y: A Tensor. Has the same type as "x" . \n
  865. *@par Third-party framework compatibility
  866. * Compatible with the TensorFlow operator DiagPart.
  867. */
  868. REG_OP(DiagPart)
  869. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32, DT_INT64, DT_DOUBLE,
  870. DT_COMPLEX64, DT_COMPLEX128}))
  871. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32, DT_INT64, DT_DOUBLE,
  872. DT_COMPLEX64, DT_COMPLEX128}))
  873. .OP_END_FACTORY_REG(DiagPart)
  874. /**
  875. *@brief Also known as a "fully-connected" layer, computes an inner product
  876. * with a set of learned weights, and (optionally) adds biases. \n
  877. *@par Inputs:
  878. * Four inputs, including:
  879. *@li x: A Tensor of type float16, int8, int4, float32, bfloat16.
  880. *@li w: A weight matrix of type float16, int8, int4, float32, bfloat16.
  881. *@li b: An optional Tensor of type float16, int8, int4, float32, bfloat16.
  882. *@li offset_w: An optional Tensor of type int8, int4.
  883. * Reserved. Only None Supported. \n
  884. *@par Attributes:
  885. *@li num_output: Required. An int, output neuron number. Reserved.
  886. *@li transpose: A bool, specifying weight whether to transpose input w,
  887. * either "true" or "false". Defaults to "false".
  888. *@li axis: Optional. An int, 1 or 2, specifying which dimension the input
  889. * "K" starts from. Defaults to 1.
  890. * The product of the subsequent dimensions starting form first dimension
  891. * or the second dimension is "K".
  892. *@li offset_x: An optional integer for quantized FullyConnection.
  893. *The negative offset added to the input image for int8 type. Ensure offset_x
  894. * within the effective range of int8 [-128, 127]. Defaults to "0". \n
  895. *@par Outputs:
  896. *y: The result tensor of type float16, int32, float32, bfloat16. \n
  897. *@par Third-party framework compatibility
  898. * Compatible with the Caffe operator InnerProduct. \n
  899. *@par Quantization supported or not
  900. * Yes
  901. */
  902. REG_OP(FullyConnection)
  903. .INPUT(x, TensorType({DT_FLOAT16, DT_INT8, DT_INT4, DT_FLOAT32, DT_BF16}))
  904. .INPUT(w, TensorType({DT_FLOAT16, DT_INT8, DT_INT4, DT_FLOAT32, DT_BF16}))
  905. .OPTIONAL_INPUT(b, TensorType({DT_FLOAT16, DT_INT32,DT_FLOAT32, DT_BF16}))
  906. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8, DT_INT4}))
  907. .OUTPUT(y, TensorType({DT_FLOAT16, DT_INT32,DT_FLOAT32, DT_BF16}))
  908. .REQUIRED_ATTR(num_output, Int)
  909. .ATTR(transpose, Bool, false)
  910. .ATTR(axis, Int, 1)
  911. .ATTR(offset_x, Int, 0)
  912. .OP_END_FACTORY_REG(FullyConnection)
  913. /**
  914. *@brief Also known as a "fully-connected-compress" layer, computes an inner
  915. * product with a set of learned weights, and (optionally) adds biases. \n
  916. *@par Inputs:
  917. * Five inputs, including:
  918. *@li x: A Tensor of type uint8, int8.
  919. *@li w: A weight matrix of type int8.
  920. *@li compress_index: A compress index matrix of type int8.
  921. *@li b: A optional Tensor of type int32.
  922. *@li offset_w: A optional Tensor of type int8.
  923. *@par Attributes:
  924. *@li num_output: A int, specifying the number of outputs.
  925. *@li transpose: A bool, specifying whether to transpose input w, either "true"
  926. * or "false". Defaults to "false".
  927. *@li axis: Optional. A int, 1 or 2, specifying which dimension the input "K"
  928. * starts from. Defaults to "1".
  929. *The product of the subsequent dimensions starting form first dimension or the
  930. * second dimension is "K".
  931. *@li offset_x: An optional integer for quantized FullyConnectionCompress.
  932. *The negative offset added to the input image for int8 type. Ensure offset_x
  933. * within the effective range of int8 [-128, 127]. Defaults to "0". \n
  934. *@par Outputs:
  935. *y: The result tensor of type int32. \n
  936. *@par Third-party framework compatibility
  937. * Compatible with the Caffe operator InnerProduct. \n
  938. *@par Quantization supported or not
  939. * Yes
  940. */
  941. REG_OP(FullyConnectionCompress)
  942. .INPUT(x, TensorType({DT_UINT8, DT_INT8}))
  943. .INPUT(w, TensorType({DT_INT8}))
  944. .INPUT(comress_index, TensorType({DT_INT8}))
  945. .OPTIONAL_INPUT(b, TensorType({DT_INT32}))
  946. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  947. .OUTPUT(y, TensorType({DT_INT32}))
  948. .REQUIRED_ATTR(num_output, Int)
  949. .ATTR(transpose, Bool, false)
  950. .ATTR(axis, Int, 1)
  951. .ATTR(offset_x, Int, 0)
  952. .OP_END_FACTORY_REG(FullyConnectionCompress)
  953. /**
  954. *@brief Computes the confusion matrix from predictions and labels . \n
  955. *@par Inputs:
  956. * Three inputs, including:
  957. *@li labels: A Tensor. Must be one of the following types: float16, float32,
  958. * int32, int8, uint8.
  959. *@li predictions: A Tensor. Must be one of the following types: float16,
  960. * float32, int32, int8, uint8.
  961. *@li weights: A Tensor. Must be one of the following types: float16, float32,
  962. * int32, int8, uint8 . \n
  963. *@par Attributes:
  964. *@li num_classes: An integer for the shape of the output matrix.
  965. * No default value.
  966. *@li dtype: Data type of the confusion matrix. No default value . \n
  967. *@par Outputs:
  968. *y: A Tensor. Has the same type and format as input "labels"
  969. *@attention Constraints:
  970. *@li "weights", "labels", and "predictions" are 1D tensors.
  971. *@li The output is with shape (num_classes, num_classes),
  972. * where, 1 <= num_classes <= 4096 . \n
  973. *@see Region()
  974. *@par Third-party framework compatibility
  975. * Compatible with the TensorFlow operator ConfusionMatrix.
  976. */
  977. REG_OP(ConfusionMatrix)
  978. .INPUT(labels, TensorType({DT_FLOAT, DT_INT32, DT_FLOAT16, DT_INT8, DT_UINT8}))
  979. .INPUT(predictions, TensorType({DT_FLOAT, DT_INT32, DT_FLOAT16, DT_INT8, DT_UINT8}))
  980. .OPTIONAL_INPUT(weights, TensorType({DT_FLOAT, DT_INT32, DT_FLOAT16, DT_INT8, DT_UINT8}))
  981. .OUTPUT(y, TensorType({DT_FLOAT, DT_INT32, DT_FLOAT16, DT_INT8, DT_UINT8}))
  982. .REQUIRED_ATTR(num_classes, Int)
  983. .REQUIRED_ATTR(dtype, String)
  984. .OP_END_FACTORY_REG(ConfusionMatrix)
  985. /**
  986. *@brief Multiplies sparse updates into a variable reference . \n
  987. *@par Inputs:
  988. * Three inputs, including:
  989. *@li var: An ND Tensor.
  990. *Must be one of the following types: float16, float, int32, int8, uint8
  991. *@li indices: An ND Tensor.
  992. *Must be one of the following types: int32 or int64
  993. *@li updates: An ND Tensor . \n
  994. *Must be one of the following types: float16, float, int32, int8, uint8
  995. *@par Attributes:
  996. *use_locking: An optional bool. Defaults to "False". If "True", the operation
  997. * will be protected by a lock . \n
  998. *@par Outputs:
  999. *var: A Tensor. Has the same type and format as input "var" . \n
  1000. *@par Third-party framework compatibility
  1001. * Compatible with the TensorFlow operator ScatterMul.
  1002. */
  1003. REG_OP(ScatterMul)
  1004. .INPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  1005. .INPUT(indices, TensorType::IndexNumberType())
  1006. .INPUT(updates, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  1007. .OUTPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  1008. .ATTR(use_locking, Bool, false)
  1009. .OP_END_FACTORY_REG(ScatterMul)
  1010. /**
  1011. *@brief Reduces sparse updates into a variable reference using
  1012. * the "min" operation . \n
  1013. *@par Inputs:
  1014. * Three inputs, including:
  1015. *@li var: An ND Tensor.
  1016. *Must be one of the following types: float16, float, int32, int8, uint8
  1017. *@li indices: An ND Tensor.
  1018. *Must be one of the following types: int32 or int64
  1019. *@li updates: An ND Tensor.
  1020. *Must be one of the following types: float16, float, int32, int8, uint8
  1021. *@par Attributes:
  1022. *use_locking: An optional bool. Defaults to "False". If "True", the operation
  1023. * will be protected by a lock . \n
  1024. *@par Outputs:
  1025. *var: A Tensor. Has the same type and format as input "var" . \n
  1026. *@par Third-party framework compatibility
  1027. * Compatible with the TensorFlow operator ScatterMin.
  1028. */
  1029. REG_OP(ScatterMin)
  1030. .INPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  1031. .INPUT(indices, TensorType::IndexNumberType())
  1032. .INPUT(updates, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  1033. .OUTPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  1034. .ATTR(use_locking, Bool, false)
  1035. .OP_END_FACTORY_REG(ScatterMin)
  1036. /**
  1037. *@brief Reduces sparse updates into a variable reference using the "max" operation . \n
  1038. *@par Inputs:
  1039. * Three inputs, including:
  1040. *@li var: An ND Tensor .
  1041. *Must be one of the following types: float16, float, int32, int8, uint8
  1042. *@li indices: An NCHW, NHWC, or ND Tensor . \n
  1043. *Must be one of the following types: int32 or int64
  1044. *@li updates: An NCHW, NHWC, or ND Tensor .
  1045. *Must be one of the following types: float16, float, int32, int8, uint8
  1046. *@par Attributes:
  1047. *use_locking: An optional bool. Defaults to "False".
  1048. * If "True", the operation will be protected by a lock . \n
  1049. *@par Outputs:
  1050. *var: A Tensor. Has the same type and format as input "var" . \n
  1051. *@par Third-party framework compatibility
  1052. * Compatible with the TensorFlow operator ScatterMax.
  1053. */
  1054. REG_OP(ScatterMax)
  1055. .INPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  1056. .INPUT(indices, TensorType::IndexNumberType())
  1057. .INPUT(updates, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  1058. .OUTPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  1059. .ATTR(use_locking, Bool, false)
  1060. .OP_END_FACTORY_REG(ScatterMax)
  1061. /**
  1062. *@brief Applies sparse updates to a variable reference . \n
  1063. *@par Inputs:
  1064. * Three inputs, including:
  1065. *@li var: An ND Tensor .
  1066. *Must be one of the following types: float16, float, int32, int8, uint8
  1067. *@li indices: An ND Tensor . \n
  1068. *Must be one of the following types: int32 or int64
  1069. *@li updates: An ND Tensor .
  1070. *Must be one of the following types: float16, float, int32, int8, uint8
  1071. *@par Attributes:
  1072. *use_locking: An optional bool. Defaults to "False". If "True",
  1073. * the operation will be protected by a lock . \n
  1074. *@par Outputs:
  1075. *var: A Tensor. Has the same type and format as input "var" . \n
  1076. *@par Third-party framework compatibility
  1077. * Compatible with the TensorFlow operator ScatterUpdate.
  1078. */
  1079. REG_OP(ScatterUpdate)
  1080. .INPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  1081. .INPUT(indices, TensorType::IndexNumberType())
  1082. .INPUT(updates, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  1083. .OUTPUT(var, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT32,DT_INT8,DT_UINT8}))
  1084. .ATTR(use_locking, Bool, false)
  1085. .OP_END_FACTORY_REG(ScatterUpdate)
  1086. /**
  1087. *@brief Returns a tensor with the `k[0]`-th to `k[1]`-th diagonals of the batched `input` . \n
  1088. *@par Inputs:
  1089. * Three inputs, including:
  1090. *@li input: Rank `r` tensor where `r >= 2`. \n
  1091. *@li k: \n
  1092. *Diagonal offset(s). Positive value means superdiagonal, 0 refers to the main \n
  1093. *diagonal, and negative value means subdiagonals. `k` can be a single integer \n
  1094. *(for a single diagonal) or a pair of integers specifying the low and high ends \n
  1095. *of a matrix band. `k[0]` must not be larger than `k[1]`. \n
  1096. *@li padding_value: The value to fill the area outside the specified diagonal band with. \n
  1097. *@par Outputs:
  1098. *diagonal: The extracted diagonal(s) . \n
  1099. *@par Third-party framework compatibility
  1100. * Compatible with the TensorFlow operator ScatterUpdate.
  1101. */
  1102. REG_OP(MatrixDiagPartV2)
  1103. .INPUT(input, TensorType::BasicType())
  1104. .INPUT(k, TensorType({DT_INT32}))
  1105. .INPUT(padding_value, TensorType::BasicType())
  1106. .OUTPUT(diagonal, TensorType::BasicType())
  1107. .OP_END_FACTORY_REG(MatrixDiagPartV2)
  1108. /**
  1109. *@brief Returns a batched matrix tensor with new batched diagonal values . \n
  1110. *@par Inputs:
  1111. * Three inputs, including:
  1112. *@li input: "Rank `r+1`, where `r >= 1`. \n
  1113. *@li diagonal: Rank `r` when `k` is an integer or `k[0] == k[1]`. Otherwise, it has rank `r+1`. \n
  1114. *@li k:
  1115. *Diagonal offset(s). Positive value means superdiagonal, 0 refers to the main \n
  1116. *diagonal, and negative value means subdiagonals. `k` can be a single integer \n
  1117. *(for a single diagonal) or a pair of integers specifying the low and high ends \n
  1118. *of a matrix band. `k[0]` must not be larger than `k[1]`. \n
  1119. *@par Outputs:
  1120. *output: Rank `r+1`, with `output.shape = input.shape` . \n
  1121. *@par Third-party framework compatibility
  1122. * Compatible with the TensorFlow operator ScatterUpdate.
  1123. */
  1124. REG_OP(MatrixSetDiagV2)
  1125. .INPUT(input, TensorType::BasicType())
  1126. .INPUT(diagonal, TensorType::BasicType())
  1127. .INPUT(k, TensorType({DT_INT32}))
  1128. .OUTPUT(output, TensorType::BasicType())
  1129. .OP_END_FACTORY_REG(MatrixSetDiagV2)
  1130. /**
  1131. *@brief Returns a batched matrix tensor with new batched diagonal values . \n
  1132. *@par Inputs:
  1133. * Three inputs, including:
  1134. *@li input: "Rank `r+1`, where `r >= 1`. \n
  1135. *@li diagonal: Rank `r` when `k` is an integer or `k[0] == k[1]`. Otherwise, it has rank `r+1`. \n
  1136. *@li k:
  1137. *Diagonal offset(s). Positive value means superdiagonal, 0 refers to the main \n
  1138. *diagonal, and negative value means subdiagonals. `k` can be a single integer \n
  1139. *(for a single diagonal) or a pair of integers specifying the low and high ends \n
  1140. *of a matrix band. `k[0]` must not be larger than `k[1]`. \n
  1141. *@par Attributes:
  1142. *@li align: An optional string. Defaults to RIGHT_LEFT. It is a string specifying \n
  1143. *how superdiagonals and subdiagonals should be aligned, respectively. \n
  1144. *other optional: LEFT_RIGHT, LEFT_LEFT, and RIGHT_RIGHT.\n
  1145. *@par Outputs:
  1146. *output: Rank `r+1`, with `output.shape = input.shape` . \n
  1147. *@par Third-party framework compatibility
  1148. * Compatible with the TensorFlow operator ScatterUpdate.
  1149. */
  1150. REG_OP(MatrixSetDiagV3)
  1151. .INPUT(input, TensorType::BasicType())
  1152. .INPUT(diagonal, TensorType::BasicType())
  1153. .INPUT(k, TensorType({DT_INT32}))
  1154. .OUTPUT(output, TensorType::BasicType())
  1155. .ATTR(align, String, "RIGHT_LEFT")
  1156. .OP_END_FACTORY_REG(MatrixSetDiagV3)
  1157. /**
  1158. *@brief Returns a batched diagonal tensor with given batched diagonal values . \n
  1159. *@par Inputs:
  1160. * Five inputs, including:
  1161. *@li diagonal: Rank `r`, where `r >= 1` \n
  1162. *@li k:
  1163. *Diagonal offset(s). Positive value means superdiagonal, 0 refers to the main \n
  1164. *diagonal, and negative value means subdiagonals. `k` can be a single integer \n
  1165. *(for a single diagonal) or a pair of integers specifying the low and high ends \n
  1166. *of a matrix band. `k[0]` must not be larger than `k[1]`. \n
  1167. *@li num_rows:
  1168. *The number of rows of the output matrix. If it is not provided, the op assumes \n
  1169. *the output matrix is a square matrix and infers the matrix size from k and the \n
  1170. *innermost dimension of `diagonal`. \n
  1171. *@li num_cols: An NCHW, NHWC, or ND Tensor.
  1172. *The number of columns of the output matrix. If it is not provided, the op \n
  1173. *assumes the output matrix is a square matrix and infers the matrix size from \n
  1174. *k and the innermost dimension of `diagonal`. \n
  1175. *@li padding_value: The number to fill the area outside the specified diagonal band with. \n
  1176. *@par Outputs:
  1177. *output: Has rank `r+1` when `k` is an integer or `k[0] == k[1]`, rank `r` otherwise . \n
  1178. *@par Third-party framework compatibility
  1179. * Compatible with the TensorFlow operator ScatterUpdate.
  1180. */
  1181. REG_OP(MatrixDiagV2)
  1182. .INPUT(diagonal, TensorType::BasicType())
  1183. .INPUT(k, TensorType({DT_INT32}))
  1184. .INPUT(num_rows, TensorType({DT_INT32}))
  1185. .INPUT(num_cols, TensorType({DT_INT32}))
  1186. .INPUT(padding_value, TensorType::BasicType())
  1187. .OUTPUT(output, TensorType::BasicType())
  1188. .OP_END_FACTORY_REG(MatrixDiagV2)
  1189. /**
  1190. * @brief Add updates to var_out according to axis and indices.
  1191. * @par Inputs:
  1192. * Three inputs, including:
  1193. * @li var: A Tensor. Must be one of the following types:
  1194. * float16, float32, int32, int8, uint8.
  1195. * @li indices: A Tensor of the indices, type should be int32.
  1196. * @li updates: A Tensor of the same type as "var".
  1197. * @par Attributes:
  1198. * @li axis: An required int to specify the axis to perform indices add.
  1199. * @par Outputs:
  1200. * @li var_out: A Tensor. Same as input "var".
  1201. * @par Third-party framework compatibility
  1202. * Compatible with the Pytorch operator index_add.
  1203. * @par Restrictions:
  1204. * Warning:THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  1205. */
  1206. REG_OP(IndexAdd)
  1207. .INPUT(var, TensorType({DT_INT32, DT_INT8, DT_UINT8, DT_FLOAT32, DT_FLOAT16}))
  1208. .INPUT(indices, TensorType({DT_INT32}))
  1209. .INPUT(updates, TensorType({DT_INT32, DT_INT8, DT_UINT8, DT_FLOAT32, DT_FLOAT16}))
  1210. .OUTPUT(var_out, TensorType({DT_INT32, DT_INT8, DT_UINT8, DT_FLOAT32, DT_FLOAT16}))
  1211. .ATTR(axis, Int, 0)
  1212. .OP_END_FACTORY_REG(IndexAdd)
  1213. /**
  1214. * @brief According to the index number of indexes, replace the value
  1215. *corresponding to X1 with the value in x2.
  1216. * @par Inputs:
  1217. * Three inputs, including:
  1218. * @li x1: A Tensor. Must be one of the following types:
  1219. *float16, float32, double, int32, uint8, int16, int8, complex64, int64,
  1220. *qint8, quint8, qint32, uint16, complex128, uint32, uint64. \n
  1221. * @li x2: A Tensor of the same type as "x1".
  1222. * @li indices: A Tensor of the indices,
  1223. * @par Attributes:
  1224. * @li accumulate: Does it support self accumulation.Defaults to 0.
  1225. * @par Outputs:
  1226. * @li y: A Tensor. Same as input "x1".
  1227. * @par Third-party framework compatibility
  1228. * Compatible with the Pytorch operator index_put.
  1229. * @par Restrictions:
  1230. * Warning:THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  1231. */
  1232. REG_OP(IndexPut)
  1233. .INPUT(x1, TensorType::BasicType())
  1234. .INPUT(x2, TensorType::BasicType())
  1235. .OUTPUT(y, TensorType::BasicType())
  1236. .REQUIRED_ATTR(indices, ListInt)
  1237. .ATTR(accumulate, Int, 0)
  1238. .OP_END_FACTORY_REG(IndexPut)
  1239. /**
  1240. *@brief: Returns the upper triangular part of a matrix (2-D tensor) or batch of matrices input \n
  1241. *@par Inputs:
  1242. *x: A Tensor. Must be one of the following types:
  1243. *float16, float32, double, int32, uint8, int16, int8, complex64, int64,
  1244. *qint8, quint8, qint32, uint16, complex128, uint32, uint64. \n
  1245. *@par Attributes:
  1246. *diagonal: An optional attribute indicates the diagonal to consider. \n
  1247. *@par Outputs:
  1248. *y: A Tensor. Has the same type as "x" . \n
  1249. *@par Third-party framework compatibility
  1250. * Compatible with the Pytorch operator Triu.
  1251. */
  1252. REG_OP(Triu)
  1253. .INPUT(x, TensorType::BasicType())
  1254. .ATTR(diagonal, Int, 0)
  1255. .OUTPUT(y, TensorType::BasicType())
  1256. .OP_END_FACTORY_REG(Triu)
  1257. /**
  1258. *@brief: Returns the upper triangular part of a matrix (2-D tensor) or batch of matrices input \n
  1259. *@par Inputs:
  1260. *x: A Tensor. Must be one of the following types:
  1261. *float16, float32, double, int32, uint8, int16, int8, complex64, int64,
  1262. *qint8, quint8, qint32, uint16, complex128, uint32, uint64. \n
  1263. *@par Attributes:
  1264. *diagonal: An optional attribute indicates the diagonal to consider. \n
  1265. *@par Outputs:
  1266. *y: A Tensor. Has the same type as "x" . \n
  1267. *@par Third-party framework compatibility
  1268. * Compatible with the Pytorch operator Tril.
  1269. */
  1270. REG_OP(Tril)
  1271. .INPUT(x, TensorType::BasicType())
  1272. .ATTR(diagonal, Int, 0)
  1273. .OUTPUT(y, TensorType::BasicType())
  1274. .OP_END_FACTORY_REG(Tril)
  1275. /**
  1276. *@brief Concatenates a list of N tensors along the first dimension.
  1277. *@par Inputs:
  1278. * @li x: A list of Tensors. Must be one of the following types: int32,
  1279. * float16, float32. Tensors to be concatenated. All must have size 1 in
  1280. * the first dimension and same shape.It's a dynamic input. \n
  1281. *@par Attributes:
  1282. * @li equation: The subscripts for the Einstein summation. \n
  1283. * @li N: tensor size of input. \n
  1284. *@par Outputs:
  1285. *@li y: Sums the product of the elements of the input operands along
  1286. * dimensions specified
  1287. * using a notation based on the Einstein summation convention. \n
  1288. *@attention Constraints:
  1289. *Input N must be Int. \n
  1290. *@par Third-party framework compatibility
  1291. *Compatible with Pytorch einsum operator.
  1292. */
  1293. REG_OP(Einsum)
  1294. .DYNAMIC_INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32}))
  1295. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32}))
  1296. .REQUIRED_ATTR(equation, String)
  1297. .REQUIRED_ATTR(N, Int)
  1298. .OP_END_FACTORY_REG(Einsum)
  1299. /**
  1300. *@brief Returns a 2-D tensor with ones on the diagonal and zeros elsewhere. \n
  1301. *@par Inputs:
  1302. *No inputs
  1303. *@par Attributes:
  1304. *@li num_rows: An required int. \n
  1305. *@li num_columns: An optional int.Defaults to 0. \n
  1306. *@li batch_shape: An optional ListInt.Defaults to []. \n
  1307. *@li dtype: An optional int.Defaults to 0. \n
  1308. *@par Outputs:
  1309. *y: A Tensor with targeted type and shape. \n
  1310. *@par Third-party framework compatibility
  1311. *Compatible with the Pytorch operator Eye. \n
  1312. */
  1313. REG_OP(Eye)
  1314. .OUTPUT(y, TensorType::BasicType()) /* "Result, has targeted element type" */
  1315. .REQUIRED_ATTR(num_rows, Int)
  1316. .ATTR(num_columns, Int, 0)
  1317. .ATTR(batch_shape, ListInt, {})
  1318. .ATTR(dtype, Int, 0)
  1319. .OP_END_FACTORY_REG(Eye)
  1320. /**
  1321. *@brief: Fill diagonal of at least 2 dimension tensors with value . \n
  1322. *@par Inputs:
  1323. *x: A Tensor. Must be one of the following types:
  1324. * float32, int32, int64 . \n
  1325. *@par Outputs:
  1326. *y: A Tensor. Has the same type as "x" . \n
  1327. *@par Attributes:
  1328. *fill_value:The value to fill in
  1329. *wrap: An optional bool. Defaults to "False". If "True", Use recursive fill. \n
  1330. *@par Third-party framework compatibility
  1331. * Compatible with the Pytorch operator FillDiagonal.
  1332. */
  1333. REG_OP(FillDiagonal)
  1334. .INPUT(x, TensorType({DT_FLOAT, DT_INT32, DT_INT64}))
  1335. .OUTPUT(y, TensorType({DT_FLOAT, DT_INT32, DT_INT64}))
  1336. .REQUIRED_ATTR(fill_value, Float)
  1337. .ATTR(wrap, Bool, false)
  1338. .OP_END_FACTORY_REG(FillDiagonal)
  1339. /**
  1340. *@brief: Returns the sum of the elements of the diagonal of the input 2-D matrix. \n
  1341. *@par Inputs:
  1342. *x: A Tensor. Must be one of the following types:
  1343. * float16, float. \n
  1344. *@par Outputs:
  1345. *y: A Tensor. Has the same type as "x" . \n
  1346. *@par Third-party framework compatibility
  1347. * Compatible with the Pytorch operator Trace.
  1348. */
  1349. REG_OP(Trace)
  1350. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  1351. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  1352. .OP_END_FACTORY_REG(Trace)
  1353. /**
  1354. *@brief Computes the generalized inverse of any matrix. \n
  1355. *@par Inputs:
  1356. * @li x: input matrix. Must be one of the following types:
  1357. * double, float. \n
  1358. *@par Attributes:
  1359. * @li rcond: An optional float >= 0 or inf. Defaults to 1e-15. \n
  1360. *@par Outputs:
  1361. * y: A Tensor with the same type and shape of x's transpose. \n
  1362. */
  1363. REG_OP(Pinverse)
  1364. .INPUT(x, TensorType({ DT_FLOAT, DT_DOUBLE }))
  1365. .OUTPUT(y, TensorType({ DT_FLOAT, DT_DOUBLE }))
  1366. .ATTR(rcond, Float, 1e-15)
  1367. .OP_END_FACTORY_REG(Pinverse)
  1368. /**
  1369. * @brief From the input tensor and updates tensor, select the maximum value according to indices to output. \n
  1370. * @par Inputs:
  1371. * Three inputs, including:
  1372. * @li input: Must be one of the following types:
  1373. * float16, float32, double, int32, uint8, int16, int8, complex64, int64,
  1374. * qint8, quint8, qint32, uint16, complex128, uint32, uint64.
  1375. * @li indices: Must be one of the following types:
  1376. * int32, int64.
  1377. * @li updates: Must have the same type as input. \n
  1378. * @par Outputs:
  1379. * output: A Tensor with the same type as input. \n
  1380. */
  1381. REG_OP(TensorScatterMax)
  1382. .INPUT(input, TensorType::BasicType())
  1383. .INPUT(indices, TensorType::IndexNumberType())
  1384. .INPUT(updates, TensorType::BasicType())
  1385. .OUTPUT(output, TensorType::BasicType())
  1386. .OP_END_FACTORY_REG(TensorScatterMax)
  1387. /**
  1388. * @brief From the input tensor and updates tensor, select the minimum value according to indices to output. \n
  1389. * @par Inputs:
  1390. * Three inputs, including:
  1391. * @li input: Must be one of the following types:
  1392. * float16, float32, double, int32, uint8, int16, int8, complex64, int64,
  1393. * qint8, quint8, qint32, uint16, complex128, uint32, uint64.
  1394. * @li indices: Must be one of the following types:
  1395. * int32, int64.
  1396. * @li updates: Must have the same type as input. \n
  1397. * @par Outputs:
  1398. * output: A Tensor with the same type as input. \n
  1399. */
  1400. REG_OP(TensorScatterMin)
  1401. .INPUT(input, TensorType::BasicType())
  1402. .INPUT(indices, TensorType::IndexNumberType())
  1403. .INPUT(updates, TensorType::BasicType())
  1404. .OUTPUT(output, TensorType::BasicType())
  1405. .OP_END_FACTORY_REG(TensorScatterMin)
  1406. /**
  1407. * @brief: Returns the batched diagonal part of a batched tensor. \n
  1408. * @par Inputs:
  1409. * @li x: A Tensor. Rank r tensor where r >= 2.
  1410. * @li k: A Tensor of type int32. Diagonal offset(s). Positive value means superdiagonal,
  1411. 0 refers to the main diagonal, and negative value means subdiagonals. k can be a
  1412. single integer (for a single diagonal) or a pair of integers specifying the low and
  1413. high ends of a matrix band. k[0] must not be larger than k[1].
  1414. * @li padding_value:A Tensor. Must have the same type as input. The value to fill the area
  1415. outside the specified diagonal band with. Default is 0. \n
  1416. * @par Outputs:
  1417. * @li y: A Tensor. Has the same type as "input". \n
  1418. * @par Attributes:
  1419. * @li align:An optional string from: "LEFT_RIGHT", "RIGHT_LEFT", "LEFT_LEFT", "RIGHT_RIGHT". Defaults to "RIGHT_LEFT".
  1420. * @par Third-party framework compatibility
  1421. * Compatible with the Tensorflow operator FillDiagonal.
  1422. */
  1423. REG_OP(MatrixDiagPartV3)
  1424. .INPUT(x, TensorType::BasicType())
  1425. .INPUT(k, TensorType({DT_INT32}))
  1426. .INPUT(padding_value, TensorType::BasicType())
  1427. .OUTPUT(y, TensorType::BasicType())
  1428. .ATTR(align,String ,"RIGHT_LEFT")
  1429. .OP_END_FACTORY_REG(MatrixDiagPartV3)
  1430. /**
  1431. * @brief Returns a batched diagonal tensor with given batched diagonal values . \n
  1432. * @par Inputs:
  1433. * Five inputs, including:
  1434. * @li x: Rank `r`, where `r >= 1` \n
  1435. * @li k:
  1436. * Diagonal offset(s). Positive value means superdiagonal, 0 refers to the main
  1437. * diagonal, and negative value means subdiagonals. `k` can be a single integer
  1438. * (for a single diagonal) or a pair of integers specifying the low and high ends
  1439. * of a matrix band. `k[0]` must not be larger than `k[1]`. \n
  1440. * @li num_rows:
  1441. * The number of rows of the output matrix. If it is not provided, the op assumes
  1442. * the output matrix is a square matrix and infers the matrix size from k and the
  1443. * innermost dimension of `diagonal`. \n
  1444. * @li num_cols: An NCHW, NHWC, or ND Tensor.
  1445. * The number of columns of the output matrix. If it is not provided, the op
  1446. * assumes the output matrix is a square matrix and infers the matrix size from
  1447. * k and the innermost dimension of `diagonal`. \n
  1448. * @li padding_value: The number to fill the area outside the specified diagonal band with. \n
  1449. * @par Attributes:
  1450. * @li align: An optional string from: "LEFT_RIGHT", "RIGHT_LEFT", "LEFT_LEFT", "RIGHT_RIGHT".
  1451. * Defaults to "RIGHT_LEFT" \n
  1452. * @par Outputs:
  1453. * @li y: Has rank `r+1` when `k` is an integer or `k[0] == k[1]`, rank `r` otherwise . \n
  1454. * @par Third-party framework compatibility
  1455. * Compatible with the TensorFlow operator ScatterUpdate.
  1456. */
  1457. REG_OP(MatrixDiagV3)
  1458. .INPUT(x, TensorType::BasicType())
  1459. .INPUT(k, TensorType({DT_INT32}))
  1460. .INPUT(num_rows, TensorType({DT_INT32}))
  1461. .INPUT(num_cols, TensorType({DT_INT32}))
  1462. .INPUT(padding_value, TensorType::BasicType())
  1463. .OUTPUT(y, TensorType::BasicType())
  1464. .ATTR(align, String, "RIGHT_LEFT")
  1465. .OP_END_FACTORY_REG(MatrixDiagV3)
  1466. /**
  1467. * @brief Function SwinAttentionScore. \n
  1468. * @par Inputs:
  1469. * six inputs, including:
  1470. * @li query: A matrix Tensor. The type only support float16.
  1471. * @li key: A matrix Tensor. The type only support float16.
  1472. * @li value: A matrix Tensor. The type only support float16.
  1473. * @li padding_mask1: A matrix Tensor. The type only support float16.
  1474. * @li padding_mask2: A matrix Tensor. The type only support float16.
  1475. * @li scale: A scalar. The type only support float16.
  1476. * @li drop_mask: A matrix Tensor. The type only support uint8. \n
  1477. * @par Attributes:
  1478. * @li keep_prob: A mutable Tensor. Must met all of the following rules:
  1479. shape of "keep_prob" should be (1,) or [1,].
  1480. * @li query_transpose: A bool. If True, changes the shape of "query" from [K, M] to
  1481. [M, K].
  1482. * @li key_transpose: A bool. If True, changes the shape of "key" from [N, K] to
  1483. [K, N].
  1484. * @li bmm_score_transpose_a: A bool. If True, changes the shape of "mid_data" from [K, M] to
  1485. [M, K].
  1486. * @li bmm_score_transpose_b: A bool. If True, changes the shape of "value" from [N, K] to
  1487. [K, N].
  1488. * @li axes: A list of int. The dimension softmax would be performed on. Defaults
  1489. to "[]" . \n
  1490. * @par Outputs:
  1491. * attention_score: The result matrix Tensor. The type only support float16.
  1492. * softmax: The result matrix Tensor. The type only support float16.
  1493. * @par Restrictions:
  1494. * Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  1495. */
  1496. REG_OP(SwinAttentionScore)
  1497. .INPUT(query, TensorType({DT_FLOAT16}))
  1498. .INPUT(key, TensorType({DT_FLOAT16}))
  1499. .INPUT(value, TensorType({DT_FLOAT16}))
  1500. .INPUT(padding_mask1, TensorType({DT_FLOAT16}))
  1501. .OPTIONAL_INPUT(padding_mask2, TensorType({DT_FLOAT16}))
  1502. .INPUT(scale, TensorType({DT_FLOAT16}))
  1503. .OPTIONAL_INPUT(drop_mask, TensorType({DT_INT8}))
  1504. .OUTPUT(attention_score, TensorType({DT_FLOAT16}))
  1505. .OUTPUT(softmax, TensorType({DT_FLOAT16}))
  1506. .ATTR(keep_prob, Float, 1.0)
  1507. .ATTR(query_transpose, Bool, false)
  1508. .ATTR(key_transpose, Bool, false)
  1509. .ATTR(bmm_score_transpose_a, Bool, false)
  1510. .ATTR(bmm_score_transpose_b, Bool, false)
  1511. .ATTR(softmax_axes, ListInt, {})
  1512. .OP_END_FACTORY_REG(SwinAttentionScore)
  1513. } // namespace ge
  1514. #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两部分组成,详细的架构图如下所示