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