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 28 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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751
  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:\n
  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:\n
  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. *@li This operator is used in conjunction with BNTrainingReduce.
  168. *@li 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. REG_OP(BNTrainingUpdateV3)
  182. .INPUT(x, TensorType({DT_FLOAT16,DT_FLOAT}))
  183. .INPUT(sum, TensorType({DT_FLOAT}))
  184. .INPUT(square_sum, TensorType({DT_FLOAT}))
  185. .INPUT(scale, TensorType({DT_FLOAT}))
  186. .INPUT(offset, TensorType({DT_FLOAT}))
  187. .REQUIRED_ATTR(epsilon, Float)
  188. .OUTPUT(y, TensorType({DT_FLOAT16,DT_FLOAT}))
  189. .OUTPUT(batch_mean, TensorType({DT_FLOAT}))
  190. .OUTPUT(batch_variance, TensorType({DT_FLOAT}))
  191. .OUTPUT(reserve_1, TensorType({DT_FLOAT}))
  192. .OUTPUT(reserve_2, TensorType({DT_FLOAT}))
  193. .OP_END_FACTORY_REG(BNTrainingUpdateV3)
  194. /**
  195. *@brief Performs the backpropagation of BatchNorm.
  196. *@par Inputs:
  197. * Four inputs, including: \n
  198. *@li grads: A 5D Tensor of type float16 or float32, with format NC1HWC0,
  199. * for the gradient.
  200. *@li x: A 5D Tensor of type float16 or float32, with format NC1HWC0.
  201. *@li batch_mean: A 5D Tensor of type float32, with format NC1HWC0,
  202. * for the mean of "x".
  203. *@li batch_variance: A 5D Tensor of type float32, with format NC1HWC0,
  204. * for the variance of "x".
  205. *@par Attributes:
  206. *epsilon: An optional float32. Defaults to "0.0001". A small float number
  207. * added to the variance of "x".
  208. *@par Outputs:
  209. *@li diff_scale: A Tensor of type float32, with format NC1HWC0,
  210. * for the offset of "scale".
  211. *@li diff_offset: A Tensor of type float32, with format NC1HWC0,
  212. * for the offset of "offset".
  213. */
  214. REG_OP(BNTrainingUpdateGrad)
  215. .INPUT(grads, TensorType({DT_FLOAT16,DT_FLOAT}))
  216. .INPUT(x, TensorType({DT_FLOAT16,DT_FLOAT}))
  217. .INPUT(batch_mean, TensorType({DT_FLOAT}))
  218. .INPUT(batch_variance, TensorType({DT_FLOAT}))
  219. .ATTR(epsilon, Float, 0.0001)
  220. .OUTPUT(diff_scale, TensorType({DT_FLOAT}))
  221. .OUTPUT(diff_offset, TensorType({DT_FLOAT}))
  222. .OP_END_FACTORY_REG(BNTrainingUpdateGrad)
  223. /**
  224. *@brief Performs the backpropagation of BatchNorm for inference.
  225. *@par Inputs:
  226. * Three inputs, including: \n
  227. *@li grads: A 5D Tensor of type loat16 or float32, with format NC1HWC0, for the gradient.
  228. *@li scale: A 5D Tensor of type float32, with format NC1HWC0.
  229. *@li batch_variance: A 5D Tensor of type float32, with format NC1HWC0. It is an output of BatchNorm.
  230. *@par Attributes:
  231. *epsilon: An optional float32. Defaults to "0.0001". A small float number added to the variance of "x".
  232. *@par Outputs:
  233. *x_backprop: A Tensor of type float16 or float32, with format NC1HWC0, for the offset of "x".
  234. *@attention Constraints:
  235. * The preceding layer of this operator must be operator BatchNorm.
  236. */
  237. REG_OP(BNInferGrad)
  238. .INPUT(grads, TensorType({DT_FLOAT16,DT_FLOAT}))
  239. .INPUT(scale, TensorType({DT_FLOAT}))
  240. .INPUT(batch_variance, TensorType({DT_FLOAT}))
  241. .OUTPUT(x_backprop, TensorType({DT_FLOAT16,DT_FLOAT}))
  242. .ATTR(epsilon, Float, 0.0001)
  243. .OP_END_FACTORY_REG(BNInferGrad)
  244. /**
  245. *@brief Computes the sum of elements across dimensions of a tensor.
  246. *@par Inputs:
  247. * Two inputs, including: \n
  248. *@li x: A Tensor. Must be one of the following types:
  249. * float32, float64, int32, uint8, int16, int8,
  250. * complex64, int64, qint8, quint8, qint32, uint16,
  251. * complex128, float16, uint32, uint64, complex64, complex128.
  252. *@li axes: A 1D list or tuple of int32 or int64. Specifies the dimensions to reduce.
  253. *@par Attributes:
  254. *keep_dims: An optional bool. If "true", retains reduced dimensions with length 1. Defaults to "false".
  255. *@par Outputs:
  256. *y: The reduced tensor. Has the same type and format as input "x".
  257. *@par Third-party framework compatibility
  258. * Compatible with the TensorFlow operator Sum.
  259. */
  260. REG_OP(ReduceSum)
  261. .INPUT(x, TensorType::NumberType())
  262. .INPUT(axes, TensorType::IndexNumberType())
  263. .OUTPUT(y, TensorType::NumberType())
  264. .ATTR(keep_dims, Bool, false)
  265. .OP_END_FACTORY_REG(ReduceSum)
  266. /**
  267. *@brief Computes the sum of elements across dimensions of a tensor.
  268. *@par Inputs:
  269. * One input: \n
  270. *x: A Tensor. Up to 8D. Must be one of the following types: float16, float32, int32, int8, uint8.
  271. *@par Attributes:
  272. *@li axes: A required 1D list or tuple of int32 or int64. Specifies the dimensions to reduce.
  273. *@li keep_dims: An optional bool. If "true", retains reduced dimensions with length 1. Defaults to "false".
  274. *@par Outputs:
  275. *y: The reduced tensor. Has the same type and format as input "x".
  276. *@par Third-party framework compatibility
  277. * Compatible with the TensorFlow operator Sum.
  278. */
  279. REG_OP(ReduceSumD)
  280. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT8, DT_UINT8, DT_INT32}))
  281. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT8, DT_UINT8, DT_INT32}))
  282. .REQUIRED_ATTR(axes, ListInt)
  283. .ATTR(keep_dims, Bool, false)
  284. .OP_END_FACTORY_REG(ReduceSumD)
  285. /**
  286. *@brief Calculates the "logical sum" of elements of a tensor in a dimension.
  287. *@par Inputs:
  288. *One input:
  289. *x: The boolean tensor to reduce.
  290. *@par Attributes:
  291. *@li keep_dims: A bool. If true, retains reduced dimensions with length 1.
  292. *@li axis: The dimensions to reduce. If None, reduces all dimensions.
  293. *Must be in the range [- rank (input_sensor), rank (input_sensor)).
  294. *@par Outputs:
  295. *y: The reduced tensor.
  296. *@par Third-party framework compatibility
  297. * Compatible with the TensorFlow operator ReduceAll.
  298. */
  299. REG_OP(ReduceAllD)
  300. .INPUT(x, TensorType({DT_BOOL}))
  301. .OUTPUT(y, TensorType({DT_BOOL}))
  302. .REQUIRED_ATTR(axes, ListInt)
  303. .ATTR(keep_dims, Bool, false)
  304. .OP_END_FACTORY_REG(ReduceAllD)
  305. /**
  306. *@brief Calculates the "logical sum" of elements of a tensor in a dimension.
  307. *@par Inputs:
  308. *Two inputs, including:
  309. *@li x: The boolean tensor to reduce.
  310. *@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)).
  311. *@par Attributes:
  312. *keep_dims: A bool. If true, retains reduced dimensions with length 1.
  313. *@par Outputs:
  314. *y: The reduced tensor.
  315. *@par Third-party framework compatibility
  316. * Compatible with the TensorFlow operator ReduceAll.
  317. */
  318. REG_OP(ReduceAll)
  319. .INPUT(x, TensorType({DT_BOOL}))
  320. .INPUT(axes, TensorType::IndexNumberType())
  321. .OUTPUT(y, TensorType({DT_BOOL}))
  322. .ATTR(keep_dims, Bool, false)
  323. .OP_END_FACTORY_REG(ReduceAll)
  324. /**
  325. *@brief Reduce a tensor on a certain axis based on product..
  326. *@par Inputs:
  327. *Two inputs, including:
  328. *@li x: A mutable Tensor. Must be the type of NumberType.
  329. *@li axis: A mutable Tensor. The dimensions to reduce.
  330. *@par Attributes:
  331. *@li keep_dims: A bool. If true, retains reduced dimensions with length 1. Defaults to "False".
  332. *@par Outputs:
  333. *y: A Tensor. Has the same type and format as input "x".
  334. *@par Third-party framework compatibility
  335. * Compatible with the TensorFlow operator ReduceProd.
  336. */
  337. REG_OP(ReduceProd)
  338. .INPUT(x,TensorType::NumberType())
  339. .INPUT(axes, TensorType::IndexNumberType())
  340. .OUTPUT(y,TensorType::NumberType())
  341. .ATTR(keep_dims, Bool, false)
  342. .OP_END_FACTORY_REG(ReduceProd)
  343. /**
  344. *@brief Computes the product of elements across dimensions of a tensor.
  345. *@par Inputs:
  346. * One input: \n
  347. *x: A Tensor. Must be one of the following types: float16, float, int8, uint8.
  348. *@par Attributes:
  349. *@li axes: A required int8, int16, int32, or int64. Specifies the dimensions to reduce. No default value.
  350. *@li keep_dims: An optional bool. If "True", retains reduced dimensions with length 1. Defaults to "False".
  351. *@par Outputs:
  352. *y: A Tensor. Has the same type and format as input "x".
  353. *@attention Constraints:
  354. * "keep_dims" is in the range [-rank(input_tensor), rank(input_tensor)].
  355. *@par Third-party framework compatibility
  356. * Compatible with the TensorFlow operator ReduceProd.
  357. */
  358. REG_OP(ReduceProdD)
  359. .INPUT(x,TensorType({DT_FLOAT, DT_UINT8, DT_INT8, DT_INT32, DT_FLOAT16}))
  360. .OUTPUT(y,TensorType({DT_FLOAT, DT_UINT8, DT_INT8, DT_INT32, DT_FLOAT16}))
  361. .REQUIRED_ATTR(axes, ListInt)
  362. .ATTR(keep_dims, Bool, false)
  363. .OP_END_FACTORY_REG(ReduceProdD)
  364. /**
  365. *@brief Reduces "x" along the dimensions according to "axis".
  366. *@par Inputs:
  367. *Two inputs, including:
  368. * @li x: A Tensor. Must be one of the following types: float16, float32, int8, uint8.
  369. * @li axes: The dimensions to reduce. Must be one of the following types: int, list, tuple, NoneType.\n
  370. * - If None (the default), reduces all dimensions.\n
  371. * - Must be in the range [-rank(x), rank(x)).
  372. *@par Attributes:
  373. *keep_dims: A bool or NoneType. \n
  374. * - If true, retains reduced dimensions with length 1. \n
  375. * - If false, the rank of the tensor is reduced by 1 for each entry in axis.
  376. *@par Outputs:
  377. *y: A Tensor. Has the same type as "x".
  378. *@par Third-party framework compatibility:
  379. * Compatible with the TensorFlow operator ReduceMean.
  380. */
  381. REG_OP(ReduceMean)
  382. .INPUT(x, TensorType::NumberType())
  383. .INPUT(axes, TensorType::IndexNumberType())
  384. .OUTPUT(y, TensorType::NumberType())
  385. .ATTR(keep_dims, Bool, false)
  386. .OP_END_FACTORY_REG(ReduceMean)
  387. /**
  388. *@brief Reduces "x" along the dimensions according to "axis".
  389. *@par Inputs:
  390. *One input:
  391. * @li x: A Tensor. Must be one of the following types: float16, float32, int8, uint8.
  392. *@par Attributes:
  393. *@li axes: The dimensions to reduce. Must be one of the following types: int, list, tuple, NoneType. \n
  394. * If None (the default), reduces all dimensions. \n
  395. * Must be in the range [-rank(x), rank(x)). \n
  396. *@li 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(ReduceMeanD)
  405. .INPUT(x, TensorType({DT_FLOAT16, DT_INT32, DT_FLOAT, DT_INT8, DT_UINT8}))
  406. .OUTPUT(y, TensorType({DT_FLOAT16, DT_INT32, DT_FLOAT, DT_INT8, DT_UINT8}))
  407. .REQUIRED_ATTR(axes, ListInt)
  408. .ATTR(keep_dims, Bool, false)
  409. .OP_END_FACTORY_REG(ReduceMeanD)
  410. /**
  411. *@brief Returns the maximum of elements across dimensions of a Tensor.
  412. *@par Inputs:
  413. * Two inputs, including: \n
  414. *@li x: A multi-dimensional Tensor of type float16, float32, or int16.
  415. *@li axes: A Scalar of type int32, specifying the axes information of the index with the maximum value.
  416. *@par Attributes:
  417. *keep_dims: A bool, specifying whether to keep dimensions for the output Tensor. Defaults to "false".
  418. *@par Outputs:
  419. *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".)
  420. *@attention Constraints:
  421. * The value range of "axes" is [-dims, dims - 1]. "dims" indicates the dimension length of "x".
  422. *@par Third-party framework compatibility
  423. * Compatible with TensorFlow operator Max.
  424. */
  425. REG_OP(ReduceMax)
  426. .INPUT(x, TensorType::NumberType())
  427. .INPUT(axes, TensorType::IndexNumberType())
  428. .OUTPUT(y, TensorType::NumberType())
  429. .ATTR(keep_dims, Bool, false)
  430. .OP_END_FACTORY_REG(ReduceMax)
  431. /**
  432. *@brief Returns the maximum of elements across dimensions of a Tensor.
  433. *@par Inputs:
  434. *x: A multi-dimensional Tensor of type float16, float32, or int16.
  435. *@par Attributes:
  436. * Two attributes, including: \n
  437. *@li axes: A required listint, specifying the axes information of the index with the maximum value.
  438. *@li keep_dims: A bool, specifying whether to keep dimensions for the output Tensor. Defaults to "false".
  439. *@par Outputs:
  440. *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".)
  441. *@attention Constraints:
  442. * The value range of "axis" is [-dims, dims - 1]. "dims" indicates the dimension length of "x".
  443. *@par Third-party framework compatibility
  444. * Compatible with TensorFlow operator Max.
  445. */
  446. REG_OP(ReduceMaxD)
  447. .INPUT(x, TensorType({DT_FLOAT, DT_UINT8, DT_INT8,
  448. DT_FLOAT16, DT_INT32}))
  449. .OUTPUT(y, TensorType({DT_FLOAT, DT_UINT8, DT_INT8,
  450. DT_FLOAT16, DT_INT32}))
  451. .REQUIRED_ATTR(axes, ListInt)
  452. .ATTR(keep_dims, Bool, false)
  453. .OP_END_FACTORY_REG(ReduceMaxD)
  454. /**
  455. *@brief Computes the minimum of elements across dimensions of a tensor.
  456. *@par Inputs:
  457. *@li input_tensor: A Tensor. Must be one of the following types: float16, float32, int8, uint8.
  458. *@li axes: A Tensor of type int8 or int32. Specifies the dimensions to reduce. Defaults to "None".
  459. *@par Attributes:\n
  460. *keep_dims: An optional bool. If "True", reduced dimensions will be retained. Defaults to "False".
  461. *@par Outputs:\n
  462. *output_tensor: A Tensor. Must be one of the following types: float16, float32, int8, uint8.
  463. *@attention Constraints:\n
  464. * If "axes = None", all dimensions will be reduced. "axes" must be in the range [-rank(input_shape), rank(input_shape)).
  465. *@par Third-party framework compatibility
  466. * Compatible with the TensorFlow operator reduce_min.
  467. */
  468. REG_OP(ReduceMin)
  469. .INPUT(x, TensorType::NumberType())
  470. .INPUT(axes, TensorType::IndexNumberType())
  471. .OUTPUT(y, TensorType::NumberType())
  472. .ATTR(keep_dims, Bool, false)
  473. .OP_END_FACTORY_REG(ReduceMin)
  474. /**
  475. *@brief Computes the minimum of elements across dimensions of a tensor.
  476. *@par Inputs:\n
  477. *input_min: A Tensor. Must be one of the following types: float16, float32, int8, uint8.
  478. *@par Attributes:
  479. *@li axes: An optional int32, list, tuple, or NoneType value. Specifies the dimensions to reduce. Defaults to "None".
  480. *@li keep_dims: An optional bool or NoneType value. If "True", reduced dimensions will be retained. Defaults to "None" (equivalent to "False").
  481. *@par Outputs:\n
  482. *output_min: A Tensor. Must be one of the following types: float16, float32, int8, uint8.
  483. *@attention Constraints:\n
  484. * If "axes = None", all dimensions will be reduced. "axes" must be in the range [-rank(input_shape), rank(input_shape)).
  485. *@par Third-party framework compatibility
  486. * Compatible with the TensorFlow operator reduce_min.
  487. */
  488. REG_OP(ReduceMinD)
  489. .INPUT(x, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT8,DT_UINT8}))
  490. .OUTPUT(y, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT8,DT_UINT8}))
  491. .REQUIRED_ATTR(axes, ListInt)
  492. .ATTR(keep_dims, Bool, false)
  493. .OP_END_FACTORY_REG(ReduceMinD)
  494. /**
  495. *@brief Computes the "logical or" of elements across dimensions of a tensor.
  496. * Reduces "x" along the dimensions given in "axes".
  497. * Unless "keep_dims" is true, the rank of the tensor is reduced by 1 for each
  498. * entry in "axes". If "keep_dims" is true, the reduced dimensions
  499. * are retained with length 1.
  500. *
  501. * If "axes" is None, all dimensions are reduced, and a
  502. * tensor with a single element is returned.
  503. *
  504. *@attention Constraints:
  505. * Only support bool
  506. *
  507. *@par Inputs:
  508. *@li x : The boolean tensor to reduce.
  509. *@li axes: The dimensions to reduce. If "None" (default), reduces all
  510. * dimensions. Must be in the range "[-rank(x), rank(x))".
  511. *
  512. *@par Attributes:
  513. * keep_dims: If true, retains reduced dimensions with length 1.
  514. *
  515. *@par Outputs:
  516. * y: The reduced tensor
  517. *
  518. *@par Third-party framework compatibility
  519. *Compatible with the TensorFlow operator reduce_any.
  520. *
  521. */
  522. REG_OP(ReduceAny)
  523. .INPUT(x, TensorType({DT_BOOL}))
  524. .INPUT(axes, TensorType::IndexNumberType())
  525. .OUTPUT(y, TensorType({DT_BOOL}))
  526. .ATTR(keep_dims, Bool, false)
  527. .OP_END_FACTORY_REG(ReduceAny)
  528. /**
  529. *@brief Computes the "logical or" of elements across dimensions of a tensor.
  530. * Reduces "x" along the dimensions given in "axes".
  531. * Unless "keep_dims" is true, the rank of the tensor is reduced by 1 for each
  532. * entry in "axes". If "keep_dims" is true, the reduced dimensions
  533. * are retained with length 1.
  534. *
  535. * If "axis" is None, all dimensions are reduced, and a
  536. * tensor with a single element is returned.
  537. *
  538. *@attention Constraints:
  539. * Only support bool
  540. *
  541. *@par Inputs:
  542. * x: The boolean tensor to reduce.
  543. *
  544. *@par Attributes:
  545. *@li axes: The dimensions to reduce. Must be in the range "[-rank(x), rank(x))".
  546. *@li keep_dims: If true, retains reduced dimensions with length 1.
  547. *
  548. *@par Outputs:
  549. * y: The reduced tensor
  550. *
  551. *@par Third-party framework compatibility
  552. *Compatible with the TensorFlow operator reduce_any.
  553. *
  554. */
  555. REG_OP(ReduceAnyD)
  556. .INPUT(x, TensorType({DT_BOOL}))
  557. .OUTPUT(y, TensorType({DT_BOOL}))
  558. .REQUIRED_ATTR(axes, ListInt)
  559. .ATTR(keep_dims, Bool, false)
  560. .OP_END_FACTORY_REG(ReduceAnyD)
  561. /**
  562. *@brief Compute reduction on dimensions specified by "axis".
  563. *Four reduction operations are provided:
  564. *SUM Computes the sum of elements across specified dimensions of a tensor.
  565. *ASUM Computes the sum of absolute values of elements across specified dimensions of a tensor.
  566. *SUMSQ Computes the sum of squares of elements across specified dimensions of a tensor.
  567. *SUMSQ Computes the mean values of elements across specified dimensions of a tensor.
  568. *@par Inputs:
  569. *x: A Tensor of type float16 or float32
  570. *@par Attributes:
  571. *@li operation: An optional int32 from 1(SUM), 2(ASUM), 3(SUMSQ), and 4(MEAN),
  572. *specifying the reduction algorithm. Defaults to 1.
  573. *@li axis: An optional int32, specifying the first axis to reduce. Defaults to "0".
  574. *The value range is [-N, N-1], where N is the input tensor rank.
  575. *@li coeff: An optional float32, specifying the scale coefficient. Defaults to "1.0".
  576. *@par Outputs:
  577. *y: A Tensor. Has the same type as "x".
  578. *@attention Constraints: The Reduction operator supports type float16 only on the device chip.
  579. *@par Third-party framework compatibility
  580. * Compatible with the Caffe operator Reduction.
  581. */
  582. REG_OP(Reduction)
  583. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  584. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  585. .ATTR(operation, Int, 1)
  586. .ATTR(axis, Int, 0)
  587. .ATTR(coeff, Float, 1.0)
  588. .OP_END_FACTORY_REG(Reduction);
  589. /**
  590. *@brief Computes the euclidean norm of elements across dimensions of a tensor.
  591. *@par Inputs:
  592. *@li input_tensor: A Tensor. Must be one of the following types: float16, float32, int32.
  593. *@li axes: A Tensor of type int8 or int32. Specifies the dimensions to reduce. Defaults to "None".
  594. *@par Attributes:\n
  595. *keep_dims: An optional bool. If "True", reduced dimensions will be retained. Defaults to "False".
  596. *@par Outputs:\n
  597. *output_tensor: A Tensor. Must be one of the following types: float16, float32, int32.
  598. *@attention Constraints:\n
  599. * If "axes = None", all dimensions will be reduced. "axes" must be in the range [-rank(input_shape), rank(input_shape)).
  600. *@par Third-party framework compatibility
  601. * Compatible with the TensorFlow operator EuclideanNorm.
  602. */
  603. REG_OP(EuclideanNorm)
  604. .INPUT(x, TensorType::NumberType())
  605. .INPUT(axes, TensorType::IndexNumberType())
  606. .OUTPUT(y, TensorType::NumberType())
  607. .ATTR(keep_dims, Bool, false)
  608. .OP_END_FACTORY_REG(EuclideanNorm)
  609. /**
  610. *@brief Computes the euclidean norm of elements across dimensions of a tensor.
  611. *@par Inputs:\n
  612. *input_min: A Tensor. Must be one of the following types: float16, float32, int32.
  613. *@par Attributes:
  614. *@li axes: An optional int32, list, tuple, or NoneType value. Specifies the dimensions to reduce. Defaults to "None".
  615. *@li keep_dims: An optional bool or NoneType value. If "True", reduced dimensions will be retained. Defaults to "None" (equivalent to "False").
  616. *@par Outputs:\n
  617. *output_min: A Tensor. Must be one of the following types: float16, float32, int32.
  618. *@attention Constraints:\n
  619. * If "axes = None", all dimensions will be reduced. "axes" must be in the range [-rank(input_shape), rank(input_shape)).
  620. *@par Third-party framework compatibility
  621. * Compatible with the TensorFlow operator EuclideanNorm.
  622. */
  623. REG_OP(EuclideanNormD)
  624. .INPUT(x, TensorType({DT_FLOAT, DT_INT32, DT_FLOAT16}))
  625. .OUTPUT(y, TensorType({DT_FLOAT, DT_INT32, DT_FLOAT16}))
  626. .ATTR(axes, ListInt, {})
  627. .ATTR(keep_dims, Bool, false)
  628. .OP_END_FACTORY_REG(EuclideanNormD)
  629. } //namespace ge
  630. #endif /* GE_OP_REDUCE_OPS_H */

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