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
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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963
  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. REG_OP(ReduceSumD)
  306. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  307. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  308. .REQUIRED_ATTR(axes, ListInt)
  309. .ATTR(keep_dims, Bool, false)
  310. .OP_END_FACTORY_REG(ReduceSumD)
  311. /**
  312. *@brief Calculates the "logical sum" of elements of a tensor in a dimension . \n
  313. *@par Inputs:
  314. *One input:
  315. *x: The boolean tensor to reduce . \n
  316. *@par Attributes:
  317. *@li keep_dims: A bool. If true, retains reduced dimensions with length 1.
  318. *@li axis: The dimensions to reduce. If None, reduces all dimensions.
  319. *Must be in the range [- rank (input_sensor), rank (input_sensor)) . \n
  320. *@par Outputs:
  321. *y: The reduced tensor . \n
  322. *@par Third-party framework compatibility
  323. * Compatible with the TensorFlow operator ReduceAll.
  324. */
  325. REG_OP(ReduceAllD)
  326. .INPUT(x, TensorType({DT_BOOL}))
  327. .OUTPUT(y, TensorType({DT_BOOL}))
  328. .REQUIRED_ATTR(axes, ListInt)
  329. .ATTR(keep_dims, Bool, false)
  330. .OP_END_FACTORY_REG(ReduceAllD)
  331. /**
  332. *@brief Calculates the "logical sum" of elements of a tensor in a dimension . \n
  333. *@par Inputs:
  334. *Two inputs, including:
  335. *@li x: The boolean tensor to reduce.
  336. *@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
  337. *@par Attributes:
  338. *keep_dims: A bool. If true, retains reduced dimensions with length 1 . \n
  339. *@par Outputs:
  340. *y: The reduced tensor . \n
  341. *@par Third-party framework compatibility
  342. * Compatible with the TensorFlow operator ReduceAll.
  343. */
  344. REG_OP(ReduceAll)
  345. .INPUT(x, TensorType({DT_BOOL}))
  346. .INPUT(axes, TensorType::IndexNumberType())
  347. .OUTPUT(y, TensorType({DT_BOOL}))
  348. .ATTR(keep_dims, Bool, false)
  349. .OP_END_FACTORY_REG(ReduceAll)
  350. /**
  351. *@brief Reduce a tensor on a certain axis based on product. . \n
  352. *@par Inputs:
  353. *Two inputs, including:
  354. *@li x: A mutable Tensor. Must be the type of NumberType.
  355. *@li axis: A mutable Tensor. The dimensions to reduce . \n
  356. *@par Attributes:
  357. *@li keep_dims: A bool. If true, retains reduced dimensions with length 1. Defaults to "False" . \n
  358. *@par Outputs:
  359. *y: A Tensor. Has the same type and format as input "x" . \n
  360. *@par Third-party framework compatibility
  361. * Compatible with the TensorFlow operator ReduceProd.
  362. */
  363. REG_OP(ReduceProd)
  364. .INPUT(x,TensorType::NumberType())
  365. .INPUT(axes, TensorType::IndexNumberType())
  366. .OUTPUT(y,TensorType::NumberType())
  367. .ATTR(keep_dims, Bool, false)
  368. .OP_END_FACTORY_REG(ReduceProd)
  369. /**
  370. *@brief Computes the product of elements across dimensions of a tensor . \n
  371. *@par Inputs:
  372. * One input:
  373. *x: A Tensor. Must be one of the following types: float16, float, int8, uint8 . \n
  374. *@par Attributes:
  375. *@li axes: A required int8, int16, int32, or int64. Specifies the dimensions to reduce. No default value.
  376. *@li keep_dims: An optional bool. If "True", retains reduced dimensions with length 1. Defaults to "False" . \n
  377. *@par Outputs:
  378. *y: A Tensor. Has the same type and format as input "x" . \n
  379. *@attention Constraints:
  380. * "keep_dims" is in the range [-rank(input_tensor), rank(input_tensor)] . \n
  381. *@par Third-party framework compatibility
  382. * Compatible with the TensorFlow operator ReduceProd.
  383. */
  384. REG_OP(ReduceProdD)
  385. .INPUT(x,TensorType({DT_FLOAT, DT_UINT8, DT_INT8, DT_INT32, DT_FLOAT16}))
  386. .OUTPUT(y,TensorType({DT_FLOAT, DT_UINT8, DT_INT8, DT_INT32, DT_FLOAT16}))
  387. .REQUIRED_ATTR(axes, ListInt)
  388. .ATTR(keep_dims, Bool, false)
  389. .OP_END_FACTORY_REG(ReduceProdD)
  390. /**
  391. *@brief Reduces "x" along the dimensions according to "axis" . \n
  392. *@par Inputs:
  393. *Two inputs, including:
  394. * @li x: A Tensor. Must be one of the following types: float16, float32, int8, uint8.
  395. * @li axes: The dimensions to reduce. Must be one of the following types: int, list, tuple, NoneType.
  396. * - If None (the default), reduces all dimensions.
  397. * - Must be in the range [-rank(x), rank(x)) . \n
  398. *@par Attributes:
  399. *keep_dims: A bool or NoneType.
  400. * - If true, retains reduced dimensions with length 1.
  401. * - If false, the rank of the tensor is reduced by 1 for each entry in axis.
  402. *@par Outputs:
  403. *y: A Tensor. Has the same type as "x" . \n
  404. *@par Third-party framework compatibility:
  405. * Compatible with the TensorFlow operator ReduceMean.
  406. */
  407. REG_OP(ReduceMean)
  408. .INPUT(x, TensorType::NumberType())
  409. .INPUT(axes, TensorType::IndexNumberType())
  410. .OUTPUT(y, TensorType::NumberType())
  411. .ATTR(keep_dims, Bool, false)
  412. .OP_END_FACTORY_REG(ReduceMean)
  413. /**
  414. *@brief Reduces "x" along the dimensions according to "axis" . \n
  415. *@par Inputs:
  416. *One input:
  417. * @li x: A Tensor. Must be one of the following types: float16, float32 . \n
  418. *@par Attributes:
  419. *@li axes: The dimensions to reduce. Must be one of the following types: int, list, tuple, NoneType.
  420. * If None (the default), reduces all dimensions.
  421. * Must be in the range [-rank(x), rank(x)).
  422. *@li keep_dims: A bool or NoneType.
  423. * - If true, retains reduced dimensions with length 1.
  424. * - If false, the rank of the tensor is reduced by 1 for each entry in axis.
  425. *@par Outputs:
  426. *y: A Tensor. Has the same type as "x" . \n
  427. *@par Third-party framework compatibility:
  428. * Compatible with the TensorFlow operator ReduceMean.
  429. */
  430. REG_OP(ReduceMeanD)
  431. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  432. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  433. .REQUIRED_ATTR(axes, ListInt)
  434. .ATTR(keep_dims, Bool, false)
  435. .OP_END_FACTORY_REG(ReduceMeanD)
  436. /**
  437. *@brief Returns the maximum of elements across dimensions of a Tensor . \n
  438. *@par Inputs:
  439. * Two inputs, including:
  440. *@li x: A multi-dimensional Tensor of type float16, float32, or int16.
  441. *@li axes: A Scalar of type int32, specifying the axes information of the index with the maximum value . \n
  442. *@par Attributes:
  443. *keep_dims: A bool, specifying whether to keep dimensions for the output Tensor. Defaults to "false" . \n
  444. *@par Outputs:
  445. *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".)
  446. *@attention Constraints:
  447. * The value range of "axes" is [-dims, dims - 1]. "dims" indicates the dimension length of "x" . \n
  448. *@par Third-party framework compatibility
  449. * Compatible with TensorFlow operator Max.
  450. */
  451. REG_OP(ReduceMax)
  452. .INPUT(x, TensorType::NumberType())
  453. .INPUT(axes, TensorType::IndexNumberType())
  454. .OUTPUT(y, TensorType::NumberType())
  455. .ATTR(keep_dims, Bool, false)
  456. .OP_END_FACTORY_REG(ReduceMax)
  457. /**
  458. *@brief Returns the maximum of elements across dimensions of a Tensor . \n
  459. *@par Inputs:
  460. *x: A multi-dimensional Tensor of type float16, float32, or int16 . \n
  461. *@par Attributes:
  462. * Two attributes, including:
  463. *@li axes: A required listint, specifying the axes information of the index with the maximum value.
  464. *@li keep_dims: A bool, specifying whether to keep dimensions for the output Tensor. Defaults to "false" . \n
  465. *@par Outputs:
  466. *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".)
  467. *@attention Constraints:
  468. * The value range of "axis" is [-dims, dims - 1]. "dims" indicates the dimension length of "x" . \n
  469. *@par Third-party framework compatibility
  470. * Compatible with TensorFlow operator Max.
  471. */
  472. REG_OP(ReduceMaxD)
  473. .INPUT(x, TensorType({DT_FLOAT, DT_UINT8, DT_INT8,
  474. DT_FLOAT16, DT_INT32}))
  475. .OUTPUT(y, TensorType({DT_FLOAT, DT_UINT8, DT_INT8,
  476. DT_FLOAT16, DT_INT32}))
  477. .REQUIRED_ATTR(axes, ListInt)
  478. .ATTR(keep_dims, Bool, false)
  479. .OP_END_FACTORY_REG(ReduceMaxD)
  480. /**
  481. *@brief Computes the minimum of elements across dimensions of a tensor . \n
  482. *@par Inputs:
  483. *@li input_tensor: A Tensor. Must be one of the following types: float16, float32, int8, uint8.
  484. *@li axes: A Tensor of type int8 or int32. Specifies the dimensions to reduce. Defaults to "None".
  485. *@par Attributes:
  486. *keep_dims: An optional bool. If "True", reduced dimensions will be retained. Defaults to "False".
  487. *@par Outputs:
  488. *output_tensor: A Tensor. Must be one of the following types: float16, float32, int8, uint8 . \n
  489. *@attention Constraints:
  490. * If "axes = None", all dimensions will be reduced. "axes" must be in the range [-rank(input_shape), rank(input_shape)) . \n
  491. *@par Third-party framework compatibility
  492. * Compatible with the TensorFlow operator reduce_min.
  493. */
  494. REG_OP(ReduceMin)
  495. .INPUT(x, TensorType::NumberType())
  496. .INPUT(axes, TensorType::IndexNumberType())
  497. .OUTPUT(y, TensorType::NumberType())
  498. .ATTR(keep_dims, Bool, false)
  499. .OP_END_FACTORY_REG(ReduceMin)
  500. /**
  501. *@brief Computes the minimum of elements across dimensions of a tensor . \n
  502. *@par Inputs:
  503. *input_min: A Tensor. Must be one of the following types: float16, float32, int8, uint8 . \n
  504. *@par Attributes:
  505. *@li axes: An optional int32, list, tuple, or NoneType value. Specifies the dimensions to reduce. Defaults to "None".
  506. *@li keep_dims: An optional bool or NoneType value. If "True", reduced dimensions will be retained. Defaults to "None" (equivalent to "False").
  507. *@par Outputs:
  508. *output_min: A Tensor. Must be one of the following types: float16, float32, int8, uint8 . \n
  509. *@attention Constraints:
  510. * If "axes = None", all dimensions will be reduced. "axes" must be in the range [-rank(input_shape), rank(input_shape)) . \n
  511. *@par Third-party framework compatibility
  512. * Compatible with the TensorFlow operator reduce_min.
  513. */
  514. REG_OP(ReduceMinD)
  515. .INPUT(x, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT8,DT_UINT8}))
  516. .OUTPUT(y, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT8,DT_UINT8}))
  517. .REQUIRED_ATTR(axes, ListInt)
  518. .ATTR(keep_dims, Bool, false)
  519. .OP_END_FACTORY_REG(ReduceMinD)
  520. /**
  521. *@brief Computes the "logical or" of elements across dimensions of a tensor.
  522. * Reduces "x" along the dimensions given in "axes".
  523. * Unless "keep_dims" is true, the rank of the tensor is reduced by 1 for each
  524. * entry in "axes". If "keep_dims" is true, the reduced dimensions
  525. * are retained with length 1.
  526. *
  527. * If "axes" is None, all dimensions are reduced, and a
  528. * tensor with a single element is returned.
  529. *
  530. *@attention Constraints:
  531. * Only support bool
  532. *
  533. *@par Inputs:
  534. *@li x : The boolean tensor to reduce.
  535. *@li axes: The dimensions to reduce. If "None" (default), reduces all
  536. * dimensions. Must be in the range "[-rank(x), rank(x))".
  537. *
  538. *@par Attributes:
  539. * keep_dims: If true, retains reduced dimensions with length 1.
  540. *
  541. *@par Outputs:
  542. * y: The reduced tensor
  543. *
  544. *@par Third-party framework compatibility
  545. *Compatible with the TensorFlow operator reduce_any.
  546. *
  547. */
  548. REG_OP(ReduceAny)
  549. .INPUT(x, TensorType({DT_BOOL}))
  550. .INPUT(axes, TensorType::IndexNumberType())
  551. .OUTPUT(y, TensorType({DT_BOOL}))
  552. .ATTR(keep_dims, Bool, false)
  553. .OP_END_FACTORY_REG(ReduceAny)
  554. /**
  555. *@brief Computes the "logical or" of elements across dimensions of a tensor.
  556. * Reduces "x" along the dimensions given in "axes".
  557. * Unless "keep_dims" is true, the rank of the tensor is reduced by 1 for each
  558. * entry in "axes". If "keep_dims" is true, the reduced dimensions
  559. * are retained with length 1.
  560. *
  561. * If "axis" is None, all dimensions are reduced, and a
  562. * tensor with a single element is returned.
  563. *
  564. *@attention Constraints:
  565. * Only support bool
  566. *
  567. *@par Inputs:
  568. * x: The boolean tensor to reduce.
  569. *
  570. *@par Attributes:
  571. *@li axes: The dimensions to reduce. Must be in the range "[-rank(x), rank(x))".
  572. *@li keep_dims: If true, retains reduced dimensions with length 1.
  573. *
  574. *@par Outputs:
  575. * y: The reduced tensor
  576. *
  577. *@par Third-party framework compatibility
  578. *Compatible with the TensorFlow operator reduce_any.
  579. */
  580. REG_OP(ReduceAnyD)
  581. .INPUT(x, TensorType({DT_BOOL}))
  582. .OUTPUT(y, TensorType({DT_BOOL}))
  583. .REQUIRED_ATTR(axes, ListInt)
  584. .ATTR(keep_dims, Bool, false)
  585. .OP_END_FACTORY_REG(ReduceAnyD)
  586. /**
  587. *@brief Compute reduction on dimensions specified by "axis".
  588. *Four reduction operations are provided:
  589. *SUM Computes the sum of elements across specified dimensions of a tensor.
  590. *ASUM Computes the sum of absolute values of elements across specified dimensions of a tensor.
  591. *SUMSQ Computes the sum of squares of elements across specified dimensions of a tensor.
  592. *SUMSQ Computes the mean values of elements across specified dimensions of a tensor . \n
  593. *@par Inputs:
  594. *x: A Tensor of type float16 or float32
  595. *@par Attributes:
  596. *@li operation: An optional int32 from 1(SUM), 2(ASUM), 3(SUMSQ), and 4(MEAN),
  597. *specifying the reduction algorithm. Defaults to "1".
  598. *@li axis: An optional int32, specifying the first axis to reduce. Defaults to "0".
  599. *The value range is [-N, N-1], where N is the input tensor rank.
  600. *@li coeff: An optional float32, specifying the scale coefficient. Defaults to "1.0" . \n
  601. *@par Outputs:
  602. *y: A Tensor. Has the same type as "x" . \n
  603. *@attention Constraints: The Reduction operator supports type float16 only on the device chip.
  604. *@par Third-party framework compatibility
  605. * Compatible with the Caffe operator Reduction.
  606. */
  607. REG_OP(Reduction)
  608. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  609. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  610. .ATTR(operation, Int, 1)
  611. .ATTR(axis, Int, 0)
  612. .ATTR(coeff, Float, 1.0)
  613. .OP_END_FACTORY_REG(Reduction);
  614. /**
  615. *@brief Computes the euclidean norm of elements across dimensions of a tensor . \n
  616. *@par Inputs:
  617. *@li input_tensor: A Tensor. Must be one of the following types: float16, float32, int32.
  618. *@li axes: A Tensor of type int8 or int32. Specifies the dimensions to reduce. Defaults to "None" . \n
  619. *@par Attributes:
  620. *keep_dims: An optional bool. If "True", reduced dimensions will be retained. Defaults to "False" . \n
  621. *@par Outputs:
  622. *output_tensor: A Tensor. Must be one of the following types: float16, float32, int32 . \n
  623. *@attention Constraints:
  624. * If "axes = None", all dimensions will be reduced. "axes" must be in the range [-rank(input_shape), rank(input_shape)) . \n
  625. *@par Third-party framework compatibility
  626. * Compatible with the TensorFlow operator EuclideanNorm.
  627. */
  628. REG_OP(EuclideanNorm)
  629. .INPUT(x, TensorType::NumberType())
  630. .INPUT(axes, TensorType::IndexNumberType())
  631. .OUTPUT(y, TensorType::NumberType())
  632. .ATTR(keep_dims, Bool, false)
  633. .OP_END_FACTORY_REG(EuclideanNorm)
  634. /**
  635. *@brief Computes the euclidean norm of elements across dimensions of a tensor . \n
  636. *@par Inputs:
  637. *input_min: A Tensor. Must be one of the following types: float16, float32, int32 . \n
  638. *@par Attributes:
  639. *@li axes: An optional int32, list, tuple, or NoneType value. Specifies the dimensions to reduce. Defaults to "None".
  640. *@li keep_dims: An optional bool or NoneType value. If "True", reduced dimensions will be retained. Defaults to "None" (equivalent to "False") . \n
  641. *@par Outputs:
  642. *output_min: A Tensor. Must be one of the following types: float16, float32, int32 . \n
  643. *@attention Constraints:
  644. * If "axes = None", all dimensions will be reduced. "axes" must be in the range [-rank(input_shape), rank(input_shape)) . \n
  645. *@par Third-party framework compatibility
  646. * Compatible with the TensorFlow operator EuclideanNorm.
  647. */
  648. REG_OP(EuclideanNormD)
  649. .INPUT(x, TensorType({DT_FLOAT, DT_INT32, DT_FLOAT16}))
  650. .OUTPUT(y, TensorType({DT_FLOAT, DT_INT32, DT_FLOAT16}))
  651. .ATTR(axes, ListInt, {})
  652. .ATTR(keep_dims, Bool, false)
  653. .OP_END_FACTORY_REG(EuclideanNormD)
  654. /**
  655. *@brief Performs instance normalization for inference . \n
  656. *@par Inputs:
  657. * Five inputs, including: (NC1HWC0 supported)
  658. *@li x: A Tensor of type float16 or float32.
  659. *@li gamma: A [N, C1, 1, 1, C0] Tensor of type float32, for the scaling gamma.
  660. *@li beta: A [N, C1, 1, 1, C0] Tensor of type float32, for the scaling beta.
  661. *@li mean: A [N, C1, 1, 1, C0] ensor of type float32, for the mean.
  662. *@li variance: A [N, C1, 1, 1, C0] Tensor of type float32, for the variance . \n
  663. *@par Attributes:
  664. *epsilon: An optional float32, specifying the small value added to variance to avoid dividing by zero.
  665. Defaults to "0.00001" . \n
  666. *@par Outputs:
  667. *y: A Tensor of type float16 or float32 for the normalized "x".
  668. *batch_mean: A Tensor of type float32 for the result mean.
  669. *batch_ variance: A Tensor of type float32 for the result variance . \n
  670. *@attention Constraints:
  671. *For Ascend 310, the result accuracy fails to reach 1 due to the square root instruction.
  672. */
  673. REG_OP(INInferV2)
  674. .INPUT(x, TensorType({DT_FLOAT16,DT_FLOAT}))
  675. .OPTIONAL_INPUT(gamma, TensorType({DT_FLOAT}))
  676. .OPTIONAL_INPUT(beta, TensorType({DT_FLOAT}))
  677. .OPTIONAL_INPUT(mean, TensorType({DT_FLOAT}))
  678. .OPTIONAL_INPUT(variance, TensorType({DT_FLOAT}))
  679. .ATTR(epsilon, Float, 0.00001)
  680. .OUTPUT(y, TensorType({DT_FLOAT16,DT_FLOAT}))
  681. .OUTPUT(batch_mean, TensorType({DT_FLOAT}))
  682. .OUTPUT(batch_variance, TensorType({DT_FLOAT}))
  683. .OP_END_FACTORY_REG(INInferV2)
  684. /**
  685. *@brief Performs reduced instance normalization . \n
  686. *@par Inputs:
  687. *x: A Tensor of type float16 or float32, with format NC1HWC0 . \n
  688. *@par Outputs:
  689. *@li sum: A Tensor of type float32 for SUM reduced "x".
  690. *@li square_sum: A Tensor of type float32 for SUMSQ reduced "x" . \n
  691. *@attention Constraints:
  692. * This operator is a InstanceNorm fusion operator for updating the moving averages for training.
  693. * This operator is used in conjunction with INTrainingUpdateV2.
  694. */
  695. REG_OP(INTrainingReduceV2)
  696. .INPUT(x, TensorType({DT_FLOAT16,DT_FLOAT}))
  697. .OUTPUT(sum, TensorType({DT_FLOAT}))
  698. .OUTPUT(square_sum, TensorType({DT_FLOAT}))
  699. .OP_END_FACTORY_REG(INTrainingReduceV2)
  700. /**
  701. *@brief Performs update instance normalization . \n
  702. *@par Inputs:
  703. * Seven inputs, including: (NC1HWC0supported)
  704. *@li x: A Tensor of type float16 or float32.
  705. *@li sum: A T [N, C1, 1, 1, C0] ensor of type float32 for the output of operator INTrainingReduceV2.
  706. *@li square_sum: A [N, C1, 1, 1, C0] Tensor of type float32 for the output of operator INTrainingReduceV2.
  707. *@li gamma: A [N, C1, 1, 1, C0] Tensor of type float32, for the scaling gamma.
  708. *@li beta: A [N, C1, 1, 1, C0] Tensor of type float32, for the scaling beta.
  709. *@li mean: A [N, C1, 1, 1, C0] Tensor of type float32, for the updated mean.
  710. *@li variance: A [N, C1, 1, 1, C0] Tensor of type float32, for the updated variance . \n
  711. *@par Attributes:
  712. *@li momentum: A required float32, specifying the momentum to update mean and var.
  713. *@li epsilon: A required float32, specifying the small value added to variance to avoid dividing by zero . \n
  714. *@par Outputs:
  715. * Three outputs, including: (NC1HWC0 supported)
  716. *@li y: A Tensor of type float16 or float32, for normalized "x".
  717. *@li batch_mean: A Tensor of type float32, for the updated mean.
  718. *@li batch_variance: A Tensor of type float32, for the updated variance . \n
  719. *@attention Constraints:
  720. *@li This operator is a InstanceNorm fusion operator for updating the moving averages for training.
  721. * This operator is used in conjunction with INTrainingReduceV2.
  722. *@li For Ascend 310, the result accuracy fails to reach 1 due to the square root instruction.
  723. */
  724. REG_OP(INTrainingUpdateV2)
  725. .INPUT(x, TensorType({DT_FLOAT16,DT_FLOAT}))
  726. .INPUT(sum, TensorType({DT_FLOAT}))
  727. .INPUT(square_sum, TensorType({DT_FLOAT}))
  728. .OPTIONAL_INPUT(gamma, TensorType({DT_FLOAT}))
  729. .OPTIONAL_INPUT(beta, TensorType({DT_FLOAT}))
  730. .OPTIONAL_INPUT(mean, TensorType({DT_FLOAT}))
  731. .OPTIONAL_INPUT(variance, TensorType({DT_FLOAT}))
  732. .ATTR(momentum, Float, 0.1)
  733. .ATTR(epsilon, Float, 0.00001)
  734. .OUTPUT(y, TensorType({DT_FLOAT16,DT_FLOAT}))
  735. .OUTPUT(batch_mean, TensorType({DT_FLOAT}))
  736. .OUTPUT(batch_variance, TensorType({DT_FLOAT}))
  737. .OP_END_FACTORY_REG(INTrainingUpdateV2)
  738. /**
  739. *@brief Performs reduced group normalization . \n
  740. *@par Inputs:
  741. *x: A Tensor of type float16 or float32, with format NCHW NHWC . \n
  742. *@par Outputs:
  743. *@li sum: A Tensor of type float32 for SUM reduced "x".
  744. *@li square_sum: A Tensor of type float32 for SUMSQ reduced "x".
  745. *@par Attributes:
  746. *@li num_groups: Int, specifying the num of groups. required, same to GNTrainingUpdate . \n
  747. *@attention Constraints:
  748. * This operator is a GroupNorm fusion operator for updating the moving averages for training.
  749. * This operator is used in conjunction with GNTrainingUpdate.
  750. */
  751. REG_OP(GNTrainingReduce)
  752. .INPUT(x, TensorType({DT_FLOAT16,DT_FLOAT}))
  753. .OUTPUT(sum, TensorType({DT_FLOAT}))
  754. .OUTPUT(square_sum, TensorType({DT_FLOAT}))
  755. .ATTR(num_groups, Int, 2)
  756. .OP_END_FACTORY_REG(GNTrainingReduce)
  757. /**
  758. *@brief Performs update group normalization . \n
  759. *@par Inputs:
  760. * Eight inputs, including: (NCHW NHWC supported)
  761. *@li x: A Tensor of type float16 or float32.
  762. *@li sum: A 5D Tensor of type float32,
  763. shape is [N, G, 1, 1, 1] for NCHW, [N, 1, 1, G, 1] for NHWC
  764. for the output of operator GNTrainingReduce.
  765. *@li square_sum: A 5D Tensor of type float32,
  766. shape is [N, G, 1, 1, 1] for NCHW, [N, 1, 1, G, 1] for NHWC
  767. for the output of operator GNTrainingReduce.
  768. *@li scale: A 5D Tensor of type float32,
  769. shape is [1, G, 1, 1, 1] for NCHW, [1, 1, 1, G, 1] for NHWC
  770. is for the scaling gamma.
  771. *@li offset: A 5D Tensor of type float32,
  772. shape is [1, G, 1, 1, 1] for NCHW, [1, 1, 1, G, 1] for NHWC
  773. for the scaling beta.
  774. *@li mean: A 5D Tensor of type float32,
  775. shape is [N, G, 1, 1, 1] for NCHW, [N, 1, 1, G, 1] for NHWC
  776. for the updated mean.
  777. *@li variance: A 5D Tensor of type float32,
  778. shape is [N, G, 1, 1, 1] for NCHW, [N, 1, 1, G, 1] for NHWC
  779. for the updated variance.
  780. *@par Attributes:
  781. *@li epsilon: A float32, specifying the small value added to variance to avoid dividing by zero.
  782. *@li num_groups: Int, specifying the num of groups. required, same to GNTrainingReduce
  783. *@par Outputs:
  784. * Three outputs, including: (NC1HWC0 supported)
  785. *@li y: A Tensor of type float16 or float32, for normalized "x".
  786. *@li batch_mean: A Tensor of type float32, for the updated mean.
  787. *@li batch_variance: A Tensor of type float32, for the updated variance . \n
  788. *@attention Constraints:
  789. *@li This operator is a InstanceNorm fusion operator for updating the moving averages for training.
  790. * This operator is used in conjunction with GNTrainingUpdate.
  791. *@li For Ascend 310, the result accuracy fails to reach 1 due to the square root instruction.
  792. */
  793. REG_OP(GNTrainingUpdate)
  794. .INPUT(x, TensorType({DT_FLOAT16,DT_FLOAT}))
  795. .INPUT(sum, TensorType({DT_FLOAT}))
  796. .INPUT(square_sum, TensorType({DT_FLOAT}))
  797. .OPTIONAL_INPUT(scale, TensorType({DT_FLOAT}))
  798. .OPTIONAL_INPUT(offset, TensorType({DT_FLOAT}))
  799. .OPTIONAL_INPUT(mean, TensorType({DT_FLOAT}))
  800. .OPTIONAL_INPUT(variance, TensorType({DT_FLOAT}))
  801. .ATTR(num_groups, Int, 2)
  802. .ATTR(epsilon, Float, 0.0001)
  803. .OUTPUT(y, TensorType({DT_FLOAT16,DT_FLOAT}))
  804. .OUTPUT(batch_mean, TensorType({DT_FLOAT}))
  805. .OUTPUT(batch_variance, TensorType({DT_FLOAT}))
  806. .OP_END_FACTORY_REG(GNTrainingUpdate)
  807. } //namespace ge
  808. #endif // OPS_BUILT_IN_OP_PROTO_INC_REDUCE_OPS_H_

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