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

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