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.

reduce_ops.h 36 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961
  1. /**
  2. * Copyright 2019-2020 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef GE_OP_REDUCE_OPS_H
  17. #define GE_OP_REDUCE_OPS_H
  18. #include "graph/operator_reg.h"
  19. namespace ge {
  20. /**
  21. *@brief Performs reduced batch normalization.
  22. *@par Inputs:
  23. *x: A 5D Tensor of type float16 or float32, with format NC1HWC0.
  24. *@par Outputs:
  25. *@li sum: A 1D Tensor of type float32 for SUM reduced "x".
  26. *@li square_sum: A 1D Tensor of type float32 for SUMSQ reduced "x".
  27. *@attention Constraints:
  28. * This operator is a BatchNorm fusion operator for updating the moving
  29. * averages for training. \n
  30. * This operator is used in conjunction with BNTrainingUpdate.
  31. */
  32. REG_OP(BNTrainingReduce)
  33. .INPUT(x, TensorType({DT_FLOAT16,DT_FLOAT}))
  34. .OUTPUT(sum, TensorType({DT_FLOAT}))
  35. .OUTPUT(square_sum, TensorType({DT_FLOAT}))
  36. .OP_END_FACTORY_REG(BNTrainingReduce)
  37. /**
  38. *@brief Performs the backpropagation of BatchNorm.
  39. *@par Inputs:
  40. * Seven inputs, including: \n
  41. *@li grads: A 5D Tensor of type float16 or float32, with format NC1HWC0, for
  42. * the gradient.
  43. *@li x: A 5D Tensor of type float16 or float32, with format NC1HWC0.
  44. *@li diff_scale: A 5D Tensor of type float32, with format NC1HWC0,
  45. * for the mean of "x".
  46. *@li diff_offset: A 5D Tensor of type float32, with format NC1HWC0,
  47. * for the variance of "x".
  48. *@li scale: A 5D Tensor of type float32, with format NC1HWC0.
  49. *@li batch_mean: A 5D Tensor of type float32, with format NC1HWC0,
  50. * for the mean of "x".
  51. *@li batch_variance: A 5D Tensor of type float32, with format NC1HWC0,
  52. * for the variance of "x".
  53. *@par Attributes:
  54. *epsilon: An optional float32. Defaults to "0.0001". A small float number
  55. * added to the variance of "x".
  56. *@par Outputs:
  57. *y: A Tensor of type float16 or float32, with format NC1HWC0, for the offset
  58. * of "x".
  59. *@attention Constraints:
  60. * The preceding layer of this operator must be BNTrainingUpdateGrad.
  61. *@see BNTrainingUpdateGrad
  62. */
  63. REG_OP(BNTrainingReduceGrad)
  64. .INPUT(grads, TensorType({DT_FLOAT16,DT_FLOAT}))
  65. .INPUT(x, TensorType({DT_FLOAT16,DT_FLOAT}))
  66. .INPUT(diff_scale, TensorType({DT_FLOAT}))
  67. .INPUT(diff_offset, TensorType({DT_FLOAT}))
  68. .INPUT(scale, TensorType({DT_FLOAT}))
  69. .INPUT(batch_mean, TensorType({DT_FLOAT}))
  70. .INPUT(batch_variance, TensorType({DT_FLOAT}))
  71. .OUTPUT(y, TensorType({DT_FLOAT16,DT_FLOAT}))
  72. .ATTR(epsilon, Float, 0.0001)
  73. .OP_END_FACTORY_REG(BNTrainingReduceGrad)
  74. /**
  75. *@brief Performs reduced batch normalization.
  76. *@par Inputs:
  77. * Seven inputs, including: (NC1HWC0 supported)
  78. *@li x: A 5D Tensor of type float16 or float32.
  79. *@li sum: A 1D Tensor of type float32 for the output of operator
  80. * BNTrainingReduce.
  81. *@li square_sum: A 1D Tensor of type float32 for the output of operator
  82. * BNTrainingReduce.
  83. *@li scale: A 1D Tensor of type float32, for the scaling factor.
  84. *@li offset: A 1D Tensor of type float32, for the scaling offset.
  85. *@li mean: A 1D Tensor of type float32, for the updated mean.
  86. *@li variance: A 1D Tensor of type float32, for the updated variance.
  87. *@par Attributes:
  88. *@li epsilon: A required float32, specifying the small value added to variance
  89. * to avoid dividing by zero.
  90. *@li factor: A required float32, specifying the weight for updating the mean
  91. * and variance.
  92. *@par Outputs:
  93. * Five outputs, including: (NC1HWC0 supported)
  94. *@li y: A 5D Tensor of type float16 or float32, for normalized "x".
  95. *@li mean: A 5D Tensor of type float32, for the updated mean.
  96. *@li variance: A 5D Tensor of type float32, for the updated variance.
  97. *@li batch_mean: A 1D Tensor of type float32, for the mean of "x".
  98. *@li batch_variance: A 1D Tensor of type float32, for the variance of "x".
  99. *@attention Constraints:
  100. *@li This operator is a BatchNorm fusion operator for updating the moving
  101. * averages for training. \n
  102. *This operator is used in conjunction with BNTrainingReduce.
  103. *@li For Ascend 310, the result accuracy fails to reach 1‰ due to the square
  104. * root instruction.
  105. */
  106. REG_OP(BNTrainingUpdate)
  107. .INPUT(x, TensorType({DT_FLOAT16,DT_FLOAT}))
  108. .INPUT(sum, TensorType({DT_FLOAT}))
  109. .INPUT(square_sum, TensorType({DT_FLOAT}))
  110. .INPUT(scale, TensorType({DT_FLOAT}))
  111. .INPUT(offset, TensorType({DT_FLOAT}))
  112. .INPUT(mean, TensorType({DT_FLOAT}))
  113. .INPUT(variance, TensorType({DT_FLOAT}))
  114. .REQUIRED_ATTR(factor, Float)
  115. .REQUIRED_ATTR(epsilon, Float)
  116. .OUTPUT(y, TensorType({DT_FLOAT16,DT_FLOAT}))
  117. .OUTPUT(mean, TensorType({DT_FLOAT}))
  118. .OUTPUT(variance, TensorType({DT_FLOAT}))
  119. .OUTPUT(batch_mean, TensorType({DT_FLOAT}))
  120. .OUTPUT(batch_variance, TensorType({DT_FLOAT}))
  121. .OP_END_FACTORY_REG(BNTrainingUpdate)
  122. /**
  123. *@brief Performs batch normalization for inference.
  124. *@par Inputs:\n
  125. * Five inputs, including: (NC1HWC0 supported)
  126. *@li x: A 5D Tensor of type float16 or float32.
  127. *@li scale: A 5D Tensor of type float32, for the scaling factor.
  128. *@li offset: A 5D Tensor of type float32, for the scaling offset.
  129. *@li mean: A 5D Tensor of type float32, for the mean.
  130. *@li variance: A 5D Tensor of type float32, for the variance.
  131. *@par Attributes:
  132. *epsilon: An optional float32, specifying the small value added to variance to
  133. * avoid dividing by zero. Defaults to "0.0001".
  134. *@par Outputs:\n
  135. *y: A 5D Tensor of type float16 or float32 for the normalized "x".
  136. *@attention Constraints:
  137. *For Ascend 310, the result accuracy fails to reach 1‰ due to the square root
  138. * instruction.
  139. */
  140. REG_OP(BNInfer)
  141. .INPUT(x, TensorType({DT_FLOAT16,DT_FLOAT}))
  142. .INPUT(scale, TensorType({DT_FLOAT}))
  143. .INPUT(offset, TensorType({DT_FLOAT}))
  144. .INPUT(mean, TensorType({DT_FLOAT}))
  145. .INPUT(variance, TensorType({DT_FLOAT}))
  146. .REQUIRED_ATTR(epsilon, Float)
  147. .OUTPUT(y, TensorType({DT_FLOAT16,DT_FLOAT}))
  148. .OP_END_FACTORY_REG(BNInfer)
  149. /**
  150. *@brief Performs reduced batch normalization. For some scene which don't contain
  151. assignmoving average.
  152. *@par Inputs:
  153. *Five inputs, including: (NC1HWC0 supported)
  154. *@li x: A 5D Tensor of type float16 or float32.
  155. *@li sum: A 5D Tensor of type float32 for the output of operator BNTrainingReduce.
  156. *@li square_sum: A 5D Tensor of type float32 for the output of operator BNTrainingReduce.
  157. *@li scale: A 5D Tensor of type float32, for the scaling factor.
  158. *@li offset: A 5D Tensor of type float32, for the scaling offset.
  159. *@par Attributes:
  160. *epsilon: A required float32, specifying the small value added to variance to avoid dividing by zero.
  161. *@par Outputs:
  162. *Three outputs, including: (NC1HWC0 supported)
  163. *@li y: A 5D Tensor of type float16 or float32, for normalized "x".
  164. *@li batch_mean: A 5D Tensor of type float32, for the mean of "x".
  165. *@li batch_variance: A 5D Tensor of type float32, for the variance of "x".
  166. *@attention Constraints:
  167. *This operator is used in conjunction with BNTrainingReduce. \n
  168. For Ascend 310, the result accuracy fails to reach 1‰ due to the square root instruction.
  169. */
  170. REG_OP(BNTrainingUpdateV2)
  171. .INPUT(x, TensorType({DT_FLOAT16,DT_FLOAT}))
  172. .INPUT(sum, TensorType({DT_FLOAT}))
  173. .INPUT(square_sum, TensorType({DT_FLOAT}))
  174. .INPUT(scale, TensorType({DT_FLOAT}))
  175. .INPUT(offset, TensorType({DT_FLOAT}))
  176. .REQUIRED_ATTR(epsilon, Float)
  177. .OUTPUT(y, TensorType({DT_FLOAT16,DT_FLOAT}))
  178. .OUTPUT(batch_mean, TensorType({DT_FLOAT}))
  179. .OUTPUT(batch_variance, TensorType({DT_FLOAT}))
  180. .OP_END_FACTORY_REG(BNTrainingUpdateV2)
  181. /**
  182. *@brief Performs reduced batch normalization v3. For some scene which don't contain
  183. assignmoving average.
  184. *@par Inputs:
  185. * Five inputs, including: (NC1HWC0 supported)
  186. *@li x: A 5D Tensor of type float16 or float32.
  187. *@li sum: A 5D Tensor of type float32 for the output of operator BNTrainingReduce.
  188. *@li square_sum: A 5D Tensor of type float32 for the output of operator BNTrainingReduce.
  189. *@li scale: A 5D Tensor of type float32, for the scaling factor.
  190. *@li offset: A 5D Tensor of type float32, for the scaling offset.
  191. *@par Attributes:
  192. *epsilon: A required float32, specifying the small value added to variance to avoid dividing by zero.
  193. *@par Outputs:
  194. * Three outputs, including: (NC1HWC0 supported)
  195. *@li y: A 5D Tensor of type float16 or float32, for normalized "x".
  196. *@li batch_mean: A 5D Tensor of type float32, for the mean of "x".
  197. *@li batch_variance: A 5D Tensor of type float32, for the variance of "x".
  198. *@li reserve_1: A 5D Tensor of type float32, for the mean of batch "x". Has the same type as batch_mean.
  199. *@li reserve_2: A 5D Tensor of type float32, for the variance of batch "x". Has the same type as batch_mean.
  200. *@attention Constraints:
  201. *@li This operator is used in conjunction with BNTrainingReduce.
  202. *@li For Ascend 310, the result accuracy fails to reach 1‰ due to the square root instruction.
  203. */
  204. REG_OP(BNTrainingUpdateV3)
  205. .INPUT(x, TensorType({DT_FLOAT16,DT_FLOAT}))
  206. .INPUT(sum, TensorType({DT_FLOAT}))
  207. .INPUT(square_sum, TensorType({DT_FLOAT}))
  208. .INPUT(scale, TensorType({DT_FLOAT}))
  209. .INPUT(offset, TensorType({DT_FLOAT}))
  210. .REQUIRED_ATTR(epsilon, Float)
  211. .OUTPUT(y, TensorType({DT_FLOAT16,DT_FLOAT}))
  212. .OUTPUT(batch_mean, TensorType({DT_FLOAT}))
  213. .OUTPUT(batch_variance, TensorType({DT_FLOAT}))
  214. .OUTPUT(reserve_1, TensorType({DT_FLOAT}))
  215. .OUTPUT(reserve_2, TensorType({DT_FLOAT}))
  216. .OP_END_FACTORY_REG(BNTrainingUpdateV3)
  217. /**
  218. *@brief Performs the backpropagation of BatchNorm.
  219. *@par Inputs:
  220. * Four inputs, including: \n
  221. *@li grads: A 5D Tensor of type float16 or float32, with format NC1HWC0,
  222. * for the gradient.
  223. *@li x: A 5D Tensor of type float16 or float32, with format NC1HWC0.
  224. *@li batch_mean: A 5D Tensor of type float32, with format NC1HWC0,
  225. * for the mean of "x".
  226. *@li batch_variance: A 5D Tensor of type float32, with format NC1HWC0,
  227. * for the variance of "x".
  228. *@par Attributes:
  229. *epsilon: An optional float32. Defaults to "0.0001". A small float number
  230. * added to the variance of "x".
  231. *@par Outputs:
  232. *@li diff_scale: A Tensor of type float32, with format NC1HWC0,
  233. * for the offset of "scale".
  234. *@li diff_offset: A Tensor of type float32, with format NC1HWC0,
  235. * for the offset of "offset".
  236. */
  237. REG_OP(BNTrainingUpdateGrad)
  238. .INPUT(grads, TensorType({DT_FLOAT16,DT_FLOAT}))
  239. .INPUT(x, TensorType({DT_FLOAT16,DT_FLOAT}))
  240. .INPUT(batch_mean, TensorType({DT_FLOAT}))
  241. .INPUT(batch_variance, TensorType({DT_FLOAT}))
  242. .ATTR(epsilon, Float, 0.0001)
  243. .OUTPUT(diff_scale, TensorType({DT_FLOAT}))
  244. .OUTPUT(diff_offset, TensorType({DT_FLOAT}))
  245. .OP_END_FACTORY_REG(BNTrainingUpdateGrad)
  246. /**
  247. *@brief Performs the backpropagation of BatchNorm for inference.
  248. *@par Inputs:
  249. * Three inputs, including: \n
  250. *@li grads: A 5D Tensor of type loat16 or float32, with format NC1HWC0, for the gradient.
  251. *@li scale: A 5D Tensor of type float32, with format NC1HWC0.
  252. *@li batch_variance: A 5D Tensor of type float32, with format NC1HWC0. It is an output of BatchNorm.
  253. *@par Attributes:
  254. *epsilon: An optional float32. Defaults to "0.0001". A small float number added to the variance of "x".
  255. *@par Outputs:
  256. *x_backprop: A Tensor of type float16 or float32, with format NC1HWC0, for the offset of "x".
  257. *@attention Constraints:
  258. * The preceding layer of this operator must be operator BatchNorm.
  259. */
  260. REG_OP(BNInferGrad)
  261. .INPUT(grads, TensorType({DT_FLOAT16,DT_FLOAT}))
  262. .INPUT(scale, TensorType({DT_FLOAT}))
  263. .INPUT(batch_variance, TensorType({DT_FLOAT}))
  264. .OUTPUT(x_backprop, TensorType({DT_FLOAT16,DT_FLOAT}))
  265. .ATTR(epsilon, Float, 0.0001)
  266. .OP_END_FACTORY_REG(BNInferGrad)
  267. /**
  268. *@brief Computes the sum of elements across dimensions of a tensor.
  269. *@par Inputs:
  270. * Two inputs, including: \n
  271. *@li x: A Tensor. Must be one of the following types:
  272. * float32, float64, int32, uint8, int16, int8,
  273. * complex64, int64, qint8, quint8, qint32, uint16,
  274. * complex128, float16, uint32, uint64, complex64, complex128.
  275. *@li axes: A 1D list or tuple of int32 or int64. Specifies the dimensions to reduce.
  276. *@par Attributes:
  277. *keep_dims: An optional bool. If "true", retains reduced dimensions with length 1. Defaults to "false".
  278. *@par Outputs:
  279. *y: The reduced tensor. Has the same type and format as input "x".
  280. *@par Third-party framework compatibility
  281. * Compatible with the TensorFlow operator Sum.
  282. */
  283. REG_OP(ReduceSum)
  284. .INPUT(x, TensorType::NumberType())
  285. .INPUT(axes, TensorType::IndexNumberType())
  286. .OUTPUT(y, TensorType::NumberType())
  287. .ATTR(keep_dims, Bool, false)
  288. .OP_END_FACTORY_REG(ReduceSum)
  289. /**
  290. *@brief Computes the sum of elements across dimensions of a tensor.
  291. *@par Inputs:
  292. * One input: \n
  293. *x: A Tensor. Up to 8D. Must be one of the following types: float16, float32, int32, int8, uint8.
  294. *@par Attributes:
  295. *@li axes: A required 1D list or tuple of int32 or int64. Specifies the dimensions to reduce.
  296. *@li keep_dims: An optional bool. If "true", retains reduced dimensions with length 1. Defaults to "false".
  297. *@par Outputs:
  298. *y: The reduced tensor. Has the same type and format as input "x".
  299. *@par Third-party framework compatibility
  300. * Compatible with the TensorFlow operator Sum.
  301. */
  302. REG_OP(ReduceSumD)
  303. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT8, DT_UINT8, DT_INT32}))
  304. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT8, DT_UINT8, DT_INT32}))
  305. .REQUIRED_ATTR(axes, ListInt)
  306. .ATTR(keep_dims, Bool, false)
  307. .OP_END_FACTORY_REG(ReduceSumD)
  308. /**
  309. *@brief Calculates the "logical sum" of elements of a tensor in a dimension.
  310. *@par Inputs:
  311. *One input:
  312. *x: The boolean tensor to reduce.
  313. *@par Attributes:
  314. *@li keep_dims: A bool. If true, retains reduced dimensions with length 1.
  315. *@li axis: The dimensions to reduce. If None, reduces all dimensions.
  316. *Must be in the range [- rank (input_sensor), rank (input_sensor)).
  317. *@par Outputs:
  318. *y: The reduced tensor.
  319. *@par Third-party framework compatibility
  320. * Compatible with the TensorFlow operator ReduceAll.
  321. */
  322. REG_OP(ReduceAllD)
  323. .INPUT(x, TensorType({DT_BOOL}))
  324. .OUTPUT(y, TensorType({DT_BOOL}))
  325. .REQUIRED_ATTR(axes, ListInt)
  326. .ATTR(keep_dims, Bool, false)
  327. .OP_END_FACTORY_REG(ReduceAllD)
  328. /**
  329. *@brief Calculates the "logical sum" of elements of a tensor in a dimension.
  330. *@par Inputs:
  331. *Two inputs, including:
  332. *@li x: The boolean tensor to reduce.
  333. *@li axis: A mutable Tensor. The dimensions to reduce. If None, reduces all dimensions. Must be in the range [- rank (input_sensor), rank (input_sensor)).
  334. *@par Attributes:
  335. *keep_dims: A bool. If true, retains reduced dimensions with length 1.
  336. *@par Outputs:
  337. *y: The reduced tensor.
  338. *@par Third-party framework compatibility
  339. * Compatible with the TensorFlow operator ReduceAll.
  340. */
  341. REG_OP(ReduceAll)
  342. .INPUT(x, TensorType({DT_BOOL}))
  343. .INPUT(axes, TensorType::IndexNumberType())
  344. .OUTPUT(y, TensorType({DT_BOOL}))
  345. .ATTR(keep_dims, Bool, false)
  346. .OP_END_FACTORY_REG(ReduceAll)
  347. /**
  348. *@brief Reduce a tensor on a certain axis based on product..
  349. *@par Inputs:
  350. *Two inputs, including:
  351. *@li x: A mutable Tensor. Must be the type of NumberType.
  352. *@li axis: A mutable Tensor. The dimensions to reduce.
  353. *@par Attributes:
  354. *@li keep_dims: A bool. If true, retains reduced dimensions with length 1. Defaults to "False".
  355. *@par Outputs:
  356. *y: A Tensor. Has the same type and format as input "x".
  357. *@par Third-party framework compatibility
  358. * Compatible with the TensorFlow operator ReduceProd.
  359. */
  360. REG_OP(ReduceProd)
  361. .INPUT(x,TensorType::NumberType())
  362. .INPUT(axes, TensorType::IndexNumberType())
  363. .OUTPUT(y,TensorType::NumberType())
  364. .ATTR(keep_dims, Bool, false)
  365. .OP_END_FACTORY_REG(ReduceProd)
  366. /**
  367. *@brief Computes the product of elements across dimensions of a tensor.
  368. *@par Inputs:
  369. * One input: \n
  370. *x: A Tensor. Must be one of the following types: float16, float, int8, uint8.
  371. *@par Attributes:
  372. *@li axes: A required int8, int16, int32, or int64. Specifies the dimensions to reduce. No default value.
  373. *@li keep_dims: An optional bool. If "True", retains reduced dimensions with length 1. Defaults to "False".
  374. *@par Outputs:
  375. *y: A Tensor. Has the same type and format as input "x".
  376. *@attention Constraints:
  377. * "keep_dims" is in the range [-rank(input_tensor), rank(input_tensor)].
  378. *@par Third-party framework compatibility
  379. * Compatible with the TensorFlow operator ReduceProd.
  380. */
  381. REG_OP(ReduceProdD)
  382. .INPUT(x,TensorType({DT_FLOAT, DT_UINT8, DT_INT8, DT_INT32, DT_FLOAT16}))
  383. .OUTPUT(y,TensorType({DT_FLOAT, DT_UINT8, DT_INT8, DT_INT32, DT_FLOAT16}))
  384. .REQUIRED_ATTR(axes, ListInt)
  385. .ATTR(keep_dims, Bool, false)
  386. .OP_END_FACTORY_REG(ReduceProdD)
  387. /**
  388. *@brief Reduces "x" along the dimensions according to "axis".
  389. *@par Inputs:
  390. *Two inputs, including:
  391. * @li x: A Tensor. Must be one of the following types: float16, float32, int8, uint8.
  392. * @li axes: The dimensions to reduce. Must be one of the following types: int, list, tuple, NoneType.\n
  393. * - If None (the default), reduces all dimensions.\n
  394. * - Must be in the range [-rank(x), rank(x)).
  395. *@par Attributes:
  396. *keep_dims: A bool or NoneType. \n
  397. * - If true, retains reduced dimensions with length 1. \n
  398. * - If false, the rank of the tensor is reduced by 1 for each entry in axis.
  399. *@par Outputs:
  400. *y: A Tensor. Has the same type as "x".
  401. *@par Third-party framework compatibility:
  402. * Compatible with the TensorFlow operator ReduceMean.
  403. */
  404. REG_OP(ReduceMean)
  405. .INPUT(x, TensorType::NumberType())
  406. .INPUT(axes, TensorType::IndexNumberType())
  407. .OUTPUT(y, TensorType::NumberType())
  408. .ATTR(keep_dims, Bool, false)
  409. .OP_END_FACTORY_REG(ReduceMean)
  410. /**
  411. *@brief Reduces "x" along the dimensions according to "axis".
  412. *@par Inputs:
  413. *One input:
  414. * @li x: A Tensor. Must be one of the following types: float16, float32, int8, uint8.
  415. *@par Attributes:
  416. *@li axes: The dimensions to reduce. Must be one of the following types: int, list, tuple, NoneType. \n
  417. * If None (the default), reduces all dimensions. \n
  418. * Must be in the range [-rank(x), rank(x)). \n
  419. *@li keep_dims: A bool or NoneType. \n
  420. * - If true, retains reduced dimensions with length 1. \n
  421. * - If false, the rank of the tensor is reduced by 1 for each entry in axis.
  422. *@par Outputs:
  423. *y: A Tensor. Has the same type as "x".
  424. *@par Third-party framework compatibility:
  425. * Compatible with the TensorFlow operator ReduceMean.
  426. */
  427. REG_OP(ReduceMeanD)
  428. .INPUT(x, TensorType({DT_FLOAT16, DT_INT32, DT_FLOAT, DT_INT8, DT_UINT8}))
  429. .OUTPUT(y, TensorType({DT_FLOAT16, DT_INT32, DT_FLOAT, DT_INT8, DT_UINT8}))
  430. .REQUIRED_ATTR(axes, ListInt)
  431. .ATTR(keep_dims, Bool, false)
  432. .OP_END_FACTORY_REG(ReduceMeanD)
  433. /**
  434. *@brief Returns the maximum of elements across dimensions of a Tensor.
  435. *@par Inputs:
  436. * Two inputs, including: \n
  437. *@li x: A multi-dimensional Tensor of type float16, float32, or int16.
  438. *@li axes: A Scalar of type int32, specifying the axes information of the index with the maximum value.
  439. *@par Attributes:
  440. *keep_dims: A bool, specifying whether to keep dimensions for the output Tensor. Defaults to "false".
  441. *@par Outputs:
  442. *y: A multi-dimensional Tensor, specifying the maximum value of the corresponding axis in the tensor. Has the same type as "x". (If "keep_dims" is set to "false", the output dimensions are reduced by "dimension" compared with that of "x". Otherwise, the output has one fewer dimension than "x".)
  443. *@attention Constraints:
  444. * The value range of "axes" is [-dims, dims - 1]. "dims" indicates the dimension length of "x".
  445. *@par Third-party framework compatibility
  446. * Compatible with TensorFlow operator Max.
  447. */
  448. REG_OP(ReduceMax)
  449. .INPUT(x, TensorType::NumberType())
  450. .INPUT(axes, TensorType::IndexNumberType())
  451. .OUTPUT(y, TensorType::NumberType())
  452. .ATTR(keep_dims, Bool, false)
  453. .OP_END_FACTORY_REG(ReduceMax)
  454. /**
  455. *@brief Returns the maximum of elements across dimensions of a Tensor.
  456. *@par Inputs:
  457. *x: A multi-dimensional Tensor of type float16, float32, or int16.
  458. *@par Attributes:
  459. * Two attributes, including: \n
  460. *@li axes: A required listint, specifying the axes information of the index with the maximum value.
  461. *@li keep_dims: A bool, specifying whether to keep dimensions for the output Tensor. Defaults to "false".
  462. *@par Outputs:
  463. *y: A multi-dimensional Tensor, specifying the maximum value of the corresponding axis in the tensor. Has the same type as "x". (If "keep_dims" is set to "false", the output dimensions are reduced by "dimension" compared with that of "x". Otherwise, the output has one fewer dimension than "x".)
  464. *@attention Constraints:
  465. * The value range of "axis" is [-dims, dims - 1]. "dims" indicates the dimension length of "x".
  466. *@par Third-party framework compatibility
  467. * Compatible with TensorFlow operator Max.
  468. */
  469. REG_OP(ReduceMaxD)
  470. .INPUT(x, TensorType({DT_FLOAT, DT_UINT8, DT_INT8,
  471. DT_FLOAT16, DT_INT32}))
  472. .OUTPUT(y, TensorType({DT_FLOAT, DT_UINT8, DT_INT8,
  473. DT_FLOAT16, DT_INT32}))
  474. .REQUIRED_ATTR(axes, ListInt)
  475. .ATTR(keep_dims, Bool, false)
  476. .OP_END_FACTORY_REG(ReduceMaxD)
  477. /**
  478. *@brief Computes the minimum of elements across dimensions of a tensor.
  479. *@par Inputs:
  480. *@li input_tensor: A Tensor. Must be one of the following types: float16, float32, int8, uint8.
  481. *@li axes: A Tensor of type int8 or int32. Specifies the dimensions to reduce. Defaults to "None".
  482. *@par Attributes:\n
  483. *keep_dims: An optional bool. If "True", reduced dimensions will be retained. Defaults to "False".
  484. *@par Outputs:\n
  485. *output_tensor: A Tensor. Must be one of the following types: float16, float32, int8, uint8.
  486. *@attention Constraints:\n
  487. * If "axes = None", all dimensions will be reduced. "axes" must be in the range [-rank(input_shape), rank(input_shape)).
  488. *@par Third-party framework compatibility
  489. * Compatible with the TensorFlow operator reduce_min.
  490. */
  491. REG_OP(ReduceMin)
  492. .INPUT(x, TensorType::NumberType())
  493. .INPUT(axes, TensorType::IndexNumberType())
  494. .OUTPUT(y, TensorType::NumberType())
  495. .ATTR(keep_dims, Bool, false)
  496. .OP_END_FACTORY_REG(ReduceMin)
  497. /**
  498. *@brief Computes the minimum of elements across dimensions of a tensor.
  499. *@par Inputs:\n
  500. *input_min: A Tensor. Must be one of the following types: float16, float32, int8, uint8.
  501. *@par Attributes:
  502. *@li axes: An optional int32, list, tuple, or NoneType value. Specifies the dimensions to reduce. Defaults to "None".
  503. *@li keep_dims: An optional bool or NoneType value. If "True", reduced dimensions will be retained. Defaults to "None" (equivalent to "False").
  504. *@par Outputs:\n
  505. *output_min: A Tensor. Must be one of the following types: float16, float32, int8, uint8.
  506. *@attention Constraints:\n
  507. * If "axes = None", all dimensions will be reduced. "axes" must be in the range [-rank(input_shape), rank(input_shape)).
  508. *@par Third-party framework compatibility
  509. * Compatible with the TensorFlow operator reduce_min.
  510. */
  511. REG_OP(ReduceMinD)
  512. .INPUT(x, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT8,DT_UINT8}))
  513. .OUTPUT(y, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT8,DT_UINT8}))
  514. .REQUIRED_ATTR(axes, ListInt)
  515. .ATTR(keep_dims, Bool, false)
  516. .OP_END_FACTORY_REG(ReduceMinD)
  517. /**
  518. *@brief Computes the "logical or" of elements across dimensions of a tensor.
  519. * Reduces "x" along the dimensions given in "axes".
  520. * Unless "keep_dims" is true, the rank of the tensor is reduced by 1 for each
  521. * entry in "axes". If "keep_dims" is true, the reduced dimensions
  522. * are retained with length 1.
  523. *
  524. * If "axes" is None, all dimensions are reduced, and a
  525. * tensor with a single element is returned.
  526. *
  527. *@attention Constraints:
  528. * Only support bool
  529. *
  530. *@par Inputs:
  531. *@li x : The boolean tensor to reduce.
  532. *@li axes: The dimensions to reduce. If "None" (default), reduces all
  533. * dimensions. Must be in the range "[-rank(x), rank(x))".
  534. *
  535. *@par Attributes:
  536. * keep_dims: If true, retains reduced dimensions with length 1.
  537. *
  538. *@par Outputs:
  539. * y: The reduced tensor
  540. *
  541. *@par Third-party framework compatibility
  542. *Compatible with the TensorFlow operator reduce_any.
  543. *
  544. */
  545. REG_OP(ReduceAny)
  546. .INPUT(x, TensorType({DT_BOOL}))
  547. .INPUT(axes, TensorType::IndexNumberType())
  548. .OUTPUT(y, TensorType({DT_BOOL}))
  549. .ATTR(keep_dims, Bool, false)
  550. .OP_END_FACTORY_REG(ReduceAny)
  551. /**
  552. *@brief Computes the "logical or" of elements across dimensions of a tensor.
  553. * Reduces "x" along the dimensions given in "axes".
  554. * Unless "keep_dims" is true, the rank of the tensor is reduced by 1 for each
  555. * entry in "axes". If "keep_dims" is true, the reduced dimensions
  556. * are retained with length 1.
  557. *
  558. * If "axis" is None, all dimensions are reduced, and a
  559. * tensor with a single element is returned.
  560. *
  561. *@attention Constraints:
  562. * Only support bool
  563. *
  564. *@par Inputs:
  565. * x: The boolean tensor to reduce.
  566. *
  567. *@par Attributes:
  568. *@li axes: The dimensions to reduce. Must be in the range "[-rank(x), rank(x))".
  569. *@li keep_dims: If true, retains reduced dimensions with length 1.
  570. *
  571. *@par Outputs:
  572. * y: The reduced tensor
  573. *
  574. *@par Third-party framework compatibility
  575. *Compatible with the TensorFlow operator reduce_any.
  576. *
  577. */
  578. REG_OP(ReduceAnyD)
  579. .INPUT(x, TensorType({DT_BOOL}))
  580. .OUTPUT(y, TensorType({DT_BOOL}))
  581. .REQUIRED_ATTR(axes, ListInt)
  582. .ATTR(keep_dims, Bool, false)
  583. .OP_END_FACTORY_REG(ReduceAnyD)
  584. /**
  585. *@brief Compute reduction on dimensions specified by "axis".
  586. *Four reduction operations are provided:
  587. *SUM Computes the sum of elements across specified dimensions of a tensor.
  588. *ASUM Computes the sum of absolute values of elements across specified dimensions of a tensor.
  589. *SUMSQ Computes the sum of squares of elements across specified dimensions of a tensor.
  590. *SUMSQ Computes the mean values of elements across specified dimensions of a tensor.
  591. *@par Inputs:
  592. *x: A Tensor of type float16 or float32
  593. *@par Attributes:
  594. *@li operation: An optional int32 from 1(SUM), 2(ASUM), 3(SUMSQ), and 4(MEAN),
  595. *specifying the reduction algorithm. Defaults to "1".
  596. *@li axis: An optional int32, specifying the first axis to reduce. Defaults to "0".
  597. *The value range is [-N, N-1], where N is the input tensor rank.
  598. *@li coeff: An optional float32, specifying the scale coefficient. Defaults to "1.0".
  599. *@par Outputs:
  600. *y: A Tensor. Has the same type as "x".
  601. *@attention Constraints: The Reduction operator supports type float16 only on the device chip.
  602. *@par Third-party framework compatibility
  603. * Compatible with the Caffe operator Reduction.
  604. */
  605. REG_OP(Reduction)
  606. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  607. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  608. .ATTR(operation, Int, 1)
  609. .ATTR(axis, Int, 0)
  610. .ATTR(coeff, Float, 1.0)
  611. .OP_END_FACTORY_REG(Reduction);
  612. /**
  613. *@brief Computes the euclidean norm of elements across dimensions of a tensor.
  614. *@par Inputs:
  615. *@li input_tensor: A Tensor. Must be one of the following types: float16, float32, int32.
  616. *@li axes: A Tensor of type int8 or int32. Specifies the dimensions to reduce. Defaults to "None".
  617. *@par Attributes:\n
  618. *keep_dims: An optional bool. If "True", reduced dimensions will be retained. Defaults to "False".
  619. *@par Outputs:\n
  620. *output_tensor: A Tensor. Must be one of the following types: float16, float32, int32.
  621. *@attention Constraints:\n
  622. * If "axes = None", all dimensions will be reduced. "axes" must be in the range [-rank(input_shape), rank(input_shape)).
  623. *@par Third-party framework compatibility
  624. * Compatible with the TensorFlow operator EuclideanNorm.
  625. */
  626. REG_OP(EuclideanNorm)
  627. .INPUT(x, TensorType::NumberType())
  628. .INPUT(axes, TensorType::IndexNumberType())
  629. .OUTPUT(y, TensorType::NumberType())
  630. .ATTR(keep_dims, Bool, false)
  631. .OP_END_FACTORY_REG(EuclideanNorm)
  632. /**
  633. *@brief Computes the euclidean norm of elements across dimensions of a tensor.
  634. *@par Inputs:\n
  635. *input_min: A Tensor. Must be one of the following types: float16, float32, int32.
  636. *@par Attributes:
  637. *@li axes: An optional int32, list, tuple, or NoneType value. Specifies the dimensions to reduce. Defaults to "None".
  638. *@li keep_dims: An optional bool or NoneType value. If "True", reduced dimensions will be retained. Defaults to "None" (equivalent to "False").
  639. *@par Outputs:\n
  640. *output_min: A Tensor. Must be one of the following types: float16, float32, int32.
  641. *@attention Constraints:\n
  642. * If "axes = None", all dimensions will be reduced. "axes" must be in the range [-rank(input_shape), rank(input_shape)).
  643. *@par Third-party framework compatibility
  644. * Compatible with the TensorFlow operator EuclideanNorm.
  645. */
  646. REG_OP(EuclideanNormD)
  647. .INPUT(x, TensorType({DT_FLOAT, DT_INT32, DT_FLOAT16}))
  648. .OUTPUT(y, TensorType({DT_FLOAT, DT_INT32, DT_FLOAT16}))
  649. .ATTR(axes, ListInt, {})
  650. .ATTR(keep_dims, Bool, false)
  651. .OP_END_FACTORY_REG(EuclideanNormD)
  652. /**
  653. *@brief Performs instance normalization for inference.
  654. *@par Inputs:\n
  655. * Five inputs, including: (NC1HWC0 supported)
  656. *@li x: A Tensor of type float16 or float32.
  657. *@li gamma: A [N, C1, 1, 1, C0] Tensor of type float32, for the scaling gamma.
  658. *@li beta: A [N, C1, 1, 1, C0] Tensor of type float32, for the scaling beta.
  659. *@li mean: A [N, C1, 1, 1, C0] ensor of type float32, for the mean.
  660. *@li variance: A [N, C1, 1, 1, C0] Tensor of type float32, for the variance.
  661. *@par Attributes:
  662. *epsilon: An optional float32, specifying the small value added to variance to avoid dividing by zero.
  663. Defaults to "0.00001".
  664. *@par Outputs:\n
  665. *y: A Tensor of type float16 or float32 for the normalized "x".
  666. *batch_mean: A Tensor of type float32 for the result mean.
  667. *batch_ variance: A Tensor of type float32 for the result variance.
  668. *@attention Constraints:
  669. *For Ascend 310, the result accuracy fails to reach 1 due to the square root instruction.
  670. */
  671. REG_OP(INInferV2)
  672. .INPUT(x, TensorType({DT_FLOAT16,DT_FLOAT}))
  673. .OPTIONAL_INPUT(gamma, TensorType({DT_FLOAT}))
  674. .OPTIONAL_INPUT(beta, TensorType({DT_FLOAT}))
  675. .OPTIONAL_INPUT(mean, TensorType({DT_FLOAT}))
  676. .OPTIONAL_INPUT(variance, TensorType({DT_FLOAT}))
  677. .ATTR(epsilon, Float, 0.00001)
  678. .OUTPUT(y, TensorType({DT_FLOAT16,DT_FLOAT}))
  679. .OUTPUT(batch_mean, TensorType({DT_FLOAT}))
  680. .OUTPUT(batch_variance, TensorType({DT_FLOAT}))
  681. .OP_END_FACTORY_REG(INInferV2)
  682. /**
  683. *@brief Performs reduced instance normalization.
  684. *@par Inputs:\n
  685. *x: A Tensor of type float16 or float32, with format NC1HWC0.
  686. *@par Outputs:
  687. *@li sum: A Tensor of type float32 for SUM reduced "x".
  688. *@li square_sum: A Tensor of type float32 for SUMSQ reduced "x".
  689. *@attention Constraints:\n
  690. * This operator is a InstanceNorm fusion operator for updating the moving averages for training. \n
  691. * This operator is used in conjunction with INTrainingUpdateV2.
  692. */
  693. REG_OP(INTrainingReduceV2)
  694. .INPUT(x, TensorType({DT_FLOAT16,DT_FLOAT}))
  695. .OUTPUT(sum, TensorType({DT_FLOAT}))
  696. .OUTPUT(square_sum, TensorType({DT_FLOAT}))
  697. .OP_END_FACTORY_REG(INTrainingReduceV2)
  698. /**
  699. *@brief Performs update instance normalization.
  700. *@par Inputs:\n
  701. * Seven inputs, including: (NC1HWC0supported)
  702. *@li x: A Tensor of type float16 or float32.
  703. *@li sum: A T [N, C1, 1, 1, C0] ensor of type float32 for the output of operator INTrainingReduceV2.
  704. *@li square_sum: A [N, C1, 1, 1, C0] Tensor of type float32 for the output of operator INTrainingReduceV2.
  705. *@li gamma: A [N, C1, 1, 1, C0] Tensor of type float32, for the scaling gamma.
  706. *@li beta: A [N, C1, 1, 1, C0] Tensor of type float32, for the scaling beta.
  707. *@li mean: A [N, C1, 1, 1, C0] Tensor of type float32, for the updated mean.
  708. *@li variance: A [N, C1, 1, 1, C0] Tensor of type float32, for the updated variance.
  709. *@par Attributes:
  710. *@li momentum: A required float32, specifying the momentum to update mean and var.
  711. *@li epsilon: A required float32, specifying the small value added to variance to avoid dividing by zero.
  712. *@par Outputs:\n
  713. * Three outputs, including: (NC1HWC0 supported)
  714. *@li y: A Tensor of type float16 or float32, for normalized "x".
  715. *@li batch_mean: A Tensor of type float32, for the updated mean.
  716. *@li batch_variance: A Tensor of type float32, for the updated variance.
  717. *@attention Constraints:
  718. *@li This operator is a InstanceNorm fusion operator for updating the moving averages for training. \n
  719. * This operator is used in conjunction with INTrainingReduceV2.
  720. *@li For Ascend 310, the result accuracy fails to reach 1 due to the square root instruction.
  721. */
  722. REG_OP(INTrainingUpdateV2)
  723. .INPUT(x, TensorType({DT_FLOAT16,DT_FLOAT}))
  724. .INPUT(sum, TensorType({DT_FLOAT}))
  725. .INPUT(square_sum, TensorType({DT_FLOAT}))
  726. .OPTIONAL_INPUT(gamma, TensorType({DT_FLOAT}))
  727. .OPTIONAL_INPUT(beta, TensorType({DT_FLOAT}))
  728. .OPTIONAL_INPUT(mean, TensorType({DT_FLOAT}))
  729. .OPTIONAL_INPUT(variance, TensorType({DT_FLOAT}))
  730. .ATTR(momentum, Float, 0.1)
  731. .ATTR(epsilon, Float, 0.00001)
  732. .OUTPUT(y, TensorType({DT_FLOAT16,DT_FLOAT}))
  733. .OUTPUT(batch_mean, TensorType({DT_FLOAT}))
  734. .OUTPUT(batch_variance, TensorType({DT_FLOAT}))
  735. .OP_END_FACTORY_REG(INTrainingUpdateV2)
  736. /**
  737. *@brief Performs reduced group normalization.
  738. *@par Inputs:\n
  739. *x: A Tensor of type float16 or float32, with format NCHW NHWC.
  740. *@par Outputs:
  741. *@li sum: A Tensor of type float32 for SUM reduced "x".
  742. *@li square_sum: A Tensor of type float32 for SUMSQ reduced "x".
  743. *@par Attributes:
  744. *@li num_groups: Int, specifying the num of groups. required, same to GNTrainingUpdate.
  745. *@attention Constraints:\n
  746. * This operator is a GroupNorm fusion operator for updating the moving averages for training. \n
  747. * This operator is used in conjunction with GNTrainingUpdate.
  748. */
  749. REG_OP(GNTrainingReduce)
  750. .INPUT(x, TensorType({DT_FLOAT16,DT_FLOAT}))
  751. .OUTPUT(sum, TensorType({DT_FLOAT}))
  752. .OUTPUT(square_sum, TensorType({DT_FLOAT}))
  753. .ATTR(num_groups, Int, 2)
  754. .OP_END_FACTORY_REG(GNTrainingReduce)
  755. /**
  756. *@brief Performs update group normalization.
  757. *@par Inputs:\n
  758. * Eight inputs, including: (NCHW NHWC supported)
  759. *@li x: A Tensor of type float16 or float32.
  760. *@li sum: A 5D Tensor of type float32,
  761. shape is [N, G, 1, 1, 1] for NCHW, [N, 1, 1, G, 1] for NHWC
  762. for the output of operator GNTrainingReduce.
  763. *@li square_sum: A 5D Tensor of type float32,
  764. shape is [N, G, 1, 1, 1] for NCHW, [N, 1, 1, G, 1] for NHWC
  765. for the output of operator GNTrainingReduce.
  766. *@li scale: A 5D Tensor of type float32,
  767. shape is [1, G, 1, 1, 1] for NCHW, [1, 1, 1, G, 1] for NHWC
  768. is for the scaling gamma.
  769. *@li offset: A 5D Tensor of type float32,
  770. shape is [1, G, 1, 1, 1] for NCHW, [1, 1, 1, G, 1] for NHWC
  771. for the scaling beta.
  772. *@li mean: A 5D Tensor of type float32,
  773. shape is [N, G, 1, 1, 1] for NCHW, [N, 1, 1, G, 1] for NHWC
  774. for the updated mean.
  775. *@li variance: A 5D Tensor of type float32,
  776. shape is [N, G, 1, 1, 1] for NCHW, [N, 1, 1, G, 1] for NHWC
  777. for the updated variance.
  778. *@par Attributes:
  779. *@li epsilon: A float32, specifying the small value added to variance to avoid dividing by zero.
  780. *@li num_groups: Int, specifying the num of groups. required, same to GNTrainingReduce
  781. *@par Outputs:\n
  782. * Three outputs, including: (NC1HWC0 supported)
  783. *@li y: A Tensor of type float16 or float32, for normalized "x".
  784. *@li batch_mean: A Tensor of type float32, for the updated mean.
  785. *@li batch_variance: A Tensor of type float32, for the updated variance.
  786. *@attention Constraints:
  787. *@li This operator is a InstanceNorm fusion operator for updating the moving averages for training. \n
  788. * This operator is used in conjunction with GNTrainingUpdate.
  789. *@li For Ascend 310, the result accuracy fails to reach 1 due to the square root instruction.
  790. */
  791. REG_OP(GNTrainingUpdate)
  792. .INPUT(x, TensorType({DT_FLOAT16,DT_FLOAT}))
  793. .INPUT(sum, TensorType({DT_FLOAT}))
  794. .INPUT(square_sum, TensorType({DT_FLOAT}))
  795. .OPTIONAL_INPUT(scale, TensorType({DT_FLOAT}))
  796. .OPTIONAL_INPUT(offset, TensorType({DT_FLOAT}))
  797. .OPTIONAL_INPUT(mean, TensorType({DT_FLOAT}))
  798. .OPTIONAL_INPUT(variance, TensorType({DT_FLOAT}))
  799. .ATTR(num_groups, Int, 2)
  800. .ATTR(epsilon, Float, 0.0001)
  801. .OUTPUT(y, TensorType({DT_FLOAT16,DT_FLOAT}))
  802. .OUTPUT(batch_mean, TensorType({DT_FLOAT}))
  803. .OUTPUT(batch_variance, TensorType({DT_FLOAT}))
  804. .OP_END_FACTORY_REG(GNTrainingUpdate)
  805. } //namespace ge
  806. #endif /* GE_OP_REDUCE_OPS_H */

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