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 24 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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  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:\n
  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:\n
  28. * This operator is a BatchNorm fusion operator for updating the moving averages for training. \n This operator is used in conjunction with BNTrainingUpdate.
  29. */
  30. REG_OP(BNTrainingReduce)
  31. .INPUT(x, TensorType({DT_FLOAT16,DT_FLOAT}))
  32. .OUTPUT(sum, TensorType({DT_FLOAT}))
  33. .OUTPUT(square_sum, TensorType({DT_FLOAT}))
  34. .OP_END_FACTORY_REG(BNTrainingReduce)
  35. /**
  36. *@brief Performs the backpropagation of BatchNorm.
  37. *@par Inputs:
  38. * Seven inputs, including: \n
  39. *@li grads: A 5D Tensor of type float16 or float32, with format NC1HWC0, for the gradient.
  40. *@li x: A 5D Tensor of type float16 or float32, with format NC1HWC0.
  41. *@li diff_scale: A 5D Tensor of type float32, with format NC1HWC0, for the mean of "x".
  42. *@li diff_offset: A 5D Tensor of type float32, with format NC1HWC0, for the variance of "x".
  43. *@li scale: A 5D Tensor of type float32, with format NC1HWC0.
  44. *@li batch_mean: A 5D Tensor of type float32, with format NC1HWC0, for the mean of "x".
  45. *@li batch_variance: A 5D Tensor of type float32, with format NC1HWC0, for the variance of "x".
  46. *@par Attributes:
  47. *epsilon: An optional float32. Defaults to "0.0001". A small float number added to the variance of "x".
  48. *@par Outputs:
  49. *y: A Tensor of type float16 or float32, with format NC1HWC0, for the offset of "x".
  50. *@attention Constraints:
  51. * The preceding layer of this operator must be BNTrainingUpdateGrad.
  52. *@see BNTrainingUpdateGrad
  53. */
  54. REG_OP(BNTrainingReduceGrad)
  55. .INPUT(grads, TensorType({DT_FLOAT16,DT_FLOAT}))
  56. .INPUT(x, TensorType({DT_FLOAT16,DT_FLOAT}))
  57. .INPUT(diff_scale, TensorType({DT_FLOAT}))
  58. .INPUT(diff_offset, TensorType({DT_FLOAT}))
  59. .INPUT(scale, TensorType({DT_FLOAT}))
  60. .INPUT(batch_mean, TensorType({DT_FLOAT}))
  61. .INPUT(batch_variance, TensorType({DT_FLOAT}))
  62. .OUTPUT(y, TensorType({DT_FLOAT16,DT_FLOAT}))
  63. .ATTR(epsilon, Float, 0.0001)
  64. .OP_END_FACTORY_REG(BNTrainingReduceGrad)
  65. /**
  66. *@brief Performs reduced batch normalization.
  67. *@par Inputs:\n
  68. * Seven inputs, including: (NC1HWC0 supported)
  69. *@li x: A 5D Tensor of type float16 or float32.
  70. *@li sum: A 1D Tensor of type float32 for the output of operator BNTrainingReduce.
  71. *@li square_sum: A 1D Tensor of type float32 for the output of operator BNTrainingReduce.
  72. *@li scale: A 1D Tensor of type float32, for the scaling factor.
  73. *@li offset: A 1D Tensor of type float32, for the scaling offset.
  74. *@li mean: A 1D Tensor of type float32, for the updated mean.
  75. *@li variance: A 1D Tensor of type float32, for the updated variance.
  76. *@par Attributes:
  77. *@li epsilon: A required float32, specifying the small value added to variance to avoid dividing by zero.
  78. *@li factor: A required float32, specifying the weight for updating the mean and variance.
  79. *@par Outputs:\n
  80. * Five outputs, including: (NC1HWC0 supported)
  81. *@li y: A 5D Tensor of type float16 or float32, for normalized "x".
  82. *@li mean: A 5D Tensor of type float32, for the updated mean.
  83. *@li variance: A 5D Tensor of type float32, for the updated variance.
  84. *@li batch_mean: A 1D Tensor of type float32, for the mean of "x".
  85. *@li batch_variance: A 1D Tensor of type float32, for the variance of "x".
  86. *@attention Constraints:
  87. *@li This operator is a BatchNorm fusion operator for updating the moving averages for training. \n This operator is used in conjunction with BNTrainingReduce.
  88. *@li For Ascend 310, the result accuracy fails to reach 1‰ due to the square root instruction.
  89. */
  90. REG_OP(BNTrainingUpdate)
  91. .INPUT(x, TensorType({DT_FLOAT16,DT_FLOAT}))
  92. .INPUT(sum, TensorType({DT_FLOAT}))
  93. .INPUT(square_sum, TensorType({DT_FLOAT}))
  94. .INPUT(scale, TensorType({DT_FLOAT}))
  95. .INPUT(offset, TensorType({DT_FLOAT}))
  96. .INPUT(mean, TensorType({DT_FLOAT}))
  97. .INPUT(variance, TensorType({DT_FLOAT}))
  98. .REQUIRED_ATTR(factor, Float)
  99. .REQUIRED_ATTR(epsilon, Float)
  100. .OUTPUT(y, TensorType({DT_FLOAT16,DT_FLOAT}))
  101. .OUTPUT(mean, TensorType({DT_FLOAT}))
  102. .OUTPUT(variance, TensorType({DT_FLOAT}))
  103. .OUTPUT(batch_mean, TensorType({DT_FLOAT}))
  104. .OUTPUT(batch_variance, TensorType({DT_FLOAT}))
  105. .OP_END_FACTORY_REG(BNTrainingUpdate)
  106. /**
  107. *@brief Performs batch normalization for inference.
  108. *@par Inputs:\n
  109. * Five inputs, including: (NC1HWC0 supported)
  110. *@li x: A 5D Tensor of type float16 or float32.
  111. *@li scale: A 5D Tensor of type float32, for the scaling factor.
  112. *@li offset: A 5D Tensor of type float32, for the scaling offset.
  113. *@li mean: A 5D Tensor of type float32, for the mean.
  114. *@li variance: A 5D Tensor of type float32, for the variance.
  115. *@par Attributes:
  116. *epsilon: An optional float32, specifying the small value added to variance to avoid dividing by zero. Defaults to "0.0001".
  117. *@par Outputs:\n
  118. *y: A 5D Tensor of type float16 or float32 for the normalized "x".
  119. *@attention Constraints:
  120. *For Ascend 310, the result accuracy fails to reach 1‰ due to the square root instruction.
  121. */
  122. REG_OP(BNInfer)
  123. .INPUT(x, TensorType({DT_FLOAT16,DT_FLOAT}))
  124. .INPUT(scale, TensorType({DT_FLOAT}))
  125. .INPUT(offset, TensorType({DT_FLOAT}))
  126. .INPUT(mean, TensorType({DT_FLOAT}))
  127. .INPUT(variance, TensorType({DT_FLOAT}))
  128. .REQUIRED_ATTR(epsilon, Float)
  129. .OUTPUT(y, TensorType({DT_FLOAT16,DT_FLOAT}))
  130. .OP_END_FACTORY_REG(BNInfer)
  131. /**
  132. *@brief Performs reduced batch normalization. For some scene which don't contain
  133. assignmoving average.
  134. *@par Inputs:\n
  135. * Five inputs, including: (NC1HWC0 supported)
  136. *@li x: A 5D Tensor of type float16 or float32.
  137. *@li sum: A 5D Tensor of type float32 for the output of operator BNTrainingReduce.
  138. *@li square_sum: A 5D Tensor of type float32 for the output of operator BNTrainingReduce.
  139. *@li scale: A 5D Tensor of type float32, for the scaling factor.
  140. *@li offset: A 5D Tensor of type float32, for the scaling offset.
  141. *@par Attributes:
  142. *epsilon: A required float32, specifying the small value added to variance to avoid dividing by zero.
  143. *@par Outputs:\n
  144. * Three outputs, including: (NC1HWC0 supported)
  145. *@li y: A 5D Tensor of type float16 or float32, for normalized "x".
  146. *@li batch_mean: A 5D Tensor of type float32, for the mean of "x".
  147. *@li batch_variance: A 5D Tensor of type float32, for the variance of "x".
  148. *@attention Constraints:
  149. *@li This operator is used in conjunction with BNTrainingReduce.
  150. *@li For Ascend 310, the result accuracy fails to reach 1‰ due to the square root instruction.
  151. */
  152. REG_OP(BNTrainingUpdateV2)
  153. .INPUT(x, TensorType({DT_FLOAT16,DT_FLOAT}))
  154. .INPUT(sum, TensorType({DT_FLOAT}))
  155. .INPUT(square_sum, TensorType({DT_FLOAT}))
  156. .INPUT(scale, TensorType({DT_FLOAT}))
  157. .INPUT(offset, TensorType({DT_FLOAT}))
  158. .REQUIRED_ATTR(epsilon, Float)
  159. .OUTPUT(y, TensorType({DT_FLOAT16,DT_FLOAT}))
  160. .OUTPUT(batch_mean, TensorType({DT_FLOAT}))
  161. .OUTPUT(batch_variance, TensorType({DT_FLOAT}))
  162. .OP_END_FACTORY_REG(BNTrainingUpdateV2)
  163. REG_OP(BNTrainingUpdateV3)
  164. .INPUT(x, TensorType({DT_FLOAT16,DT_FLOAT}))
  165. .INPUT(sum, TensorType({DT_FLOAT}))
  166. .INPUT(square_sum, TensorType({DT_FLOAT}))
  167. .INPUT(scale, TensorType({DT_FLOAT}))
  168. .INPUT(offset, TensorType({DT_FLOAT}))
  169. .REQUIRED_ATTR(epsilon, Float)
  170. .OUTPUT(y, TensorType({DT_FLOAT16,DT_FLOAT}))
  171. .OUTPUT(batch_mean, TensorType({DT_FLOAT}))
  172. .OUTPUT(batch_variance, TensorType({DT_FLOAT}))
  173. .OUTPUT(reserve_1, TensorType({DT_FLOAT}))
  174. .OUTPUT(reserve_2, TensorType({DT_FLOAT}))
  175. .OP_END_FACTORY_REG(BNTrainingUpdateV3)
  176. /**
  177. *@brief Performs the backpropagation of BatchNorm.
  178. *@par Inputs:
  179. * Four inputs, including: \n
  180. *@li grads: A 5D Tensor of type float16 or float32, with format NC1HWC0, for the gradient.
  181. *@li x: A 5D Tensor of type float16 or float32, with format NC1HWC0.
  182. *@li batch_mean: A 5D Tensor of type float32, with format NC1HWC0, for the mean of "x".
  183. *@li batch_variance: A 5D Tensor of type float32, with format NC1HWC0, for the variance of "x".
  184. *@par Attributes:
  185. *epsilon: An optional float32. Defaults to "0.0001". A small float number added to the variance of "x".
  186. *@par Outputs:
  187. *@li diff_scale: A Tensor of type float32, with format NC1HWC0, for the offset of "scale".
  188. *@li diff_offset: A Tensor of type float32, with format NC1HWC0, for the offset of "offset".
  189. */
  190. REG_OP(BNTrainingUpdateGrad)
  191. .INPUT(grads, TensorType({DT_FLOAT16,DT_FLOAT}))
  192. .INPUT(x, TensorType({DT_FLOAT16,DT_FLOAT}))
  193. .INPUT(batch_mean, TensorType({DT_FLOAT}))
  194. .INPUT(batch_variance, TensorType({DT_FLOAT}))
  195. .ATTR(epsilon, Float, 0.0001)
  196. .OUTPUT(diff_scale, TensorType({DT_FLOAT}))
  197. .OUTPUT(diff_offset, TensorType({DT_FLOAT}))
  198. .OP_END_FACTORY_REG(BNTrainingUpdateGrad)
  199. /**
  200. *@brief Performs the backpropagation of BatchNorm for inference.
  201. *@par Inputs:
  202. * Three inputs, including: \n
  203. *@li grads: A 5D Tensor of type loat16 or float32, with format NC1HWC0, for the gradient.
  204. *@li scale: A 5D Tensor of type float32, with format NC1HWC0.
  205. *@li batch_variance: A 5D Tensor of type float32, with format NC1HWC0. It is an output of BatchNorm.
  206. *@par Attributes:
  207. *epsilon: An optional float32. Defaults to "0.0001". A small float number added to the variance of "x".
  208. *@par Outputs:
  209. *x_backprop: A Tensor of type float16 or float32, with format NC1HWC0, for the offset of "x".
  210. *@attention Constraints:
  211. * The preceding layer of this operator must be operator BatchNorm.
  212. */
  213. REG_OP(BNInferGrad)
  214. .INPUT(grads, TensorType({DT_FLOAT16,DT_FLOAT}))
  215. .INPUT(scale, TensorType({DT_FLOAT}))
  216. .INPUT(batch_variance, TensorType({DT_FLOAT}))
  217. .OUTPUT(x_backprop, TensorType({DT_FLOAT16,DT_FLOAT}))
  218. .ATTR(epsilon, Float, 0.0001)
  219. .OP_END_FACTORY_REG(BNInferGrad)
  220. /**
  221. *@brief Computes the sum of elements across dimensions of a tensor.
  222. *@par Inputs:
  223. * Two inputs, including: \n
  224. *@li x: A Tensor of type float16 or float32. Up to 8D.
  225. *@li axes: A 1D list or tuple of int32 or int64. Specifies the dimensions to reduce.
  226. *@par Attributes:
  227. *keep_dims: An optional bool. If "true", retains reduced dimensions with length 1. Defaults to "false".
  228. *@par Outputs:
  229. *y: The reduced tensor. Has the same type and format as input "x".
  230. */
  231. REG_OP(ReduceSum)
  232. .INPUT(x, TensorType::NumberType())
  233. .INPUT(axes, TensorType::IndexNumberType())
  234. .OUTPUT(y, TensorType::NumberType())
  235. .ATTR(keep_dims, Bool, false)
  236. .OP_END_FACTORY_REG(ReduceSum)
  237. /**
  238. *@brief Computes the sum of elements across dimensions of a tensor.
  239. *@par Inputs:
  240. * One input: \n
  241. *x: A Tensor. Up to 8D. Must be one of the following types: float16, float32, int32, int8, uint8.
  242. *@par Attributes:
  243. *@li axes: A required 1D list or tuple of int32 or int64. Specifies the dimensions to reduce.
  244. *@li keep_dims: An optional bool. If "true", retains reduced dimensions with length 1. Defaults to "false".
  245. *@par Outputs:
  246. *y: The reduced tensor. Has the same type and format as input "x".
  247. */
  248. REG_OP(ReduceSumD)
  249. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT8, DT_UINT8, DT_INT32}))
  250. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT8, DT_UINT8, DT_INT32}))
  251. .REQUIRED_ATTR(axes, ListInt)
  252. .ATTR(keep_dims, Bool, false)
  253. .OP_END_FACTORY_REG(ReduceSumD)
  254. /**
  255. *@brief Calculates the "logical sum" of elements of a tensor in a dimension.
  256. *@par Inputs:
  257. *One input:
  258. *x: A mutable Tensor. Must be one of the following types: float16,
  259. * float32, double. Should be a Variable Tensor.
  260. *@par Attributes:
  261. *@li keep_dims: A bool. If true, retains reduced dimensions with length 1.
  262. *@li axis: The dimensions to reduce. If None, reduces all dimensions.
  263. *Must be in the range [- rank (input_sensor), rank (input_sensor)).
  264. *@par Outputs:
  265. *y: The reduced tensor.
  266. */
  267. REG_OP(ReduceAllD)
  268. .INPUT(x, TensorType({DT_BOOL}))
  269. .OUTPUT(y, TensorType({DT_BOOL}))
  270. .REQUIRED_ATTR(axes, ListInt)
  271. .ATTR(keep_dims, Bool, false)
  272. .OP_END_FACTORY_REG(ReduceAllD)
  273. /**
  274. *@brief Calculates the "logical sum" of elements of a tensor in a dimension.
  275. *@par Inputs:
  276. *Two inputs, including:
  277. *@li x: A mutable Tensor. Must be one of the following types: float16, float32, double. Should be a Variable Tensor.
  278. *@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)).
  279. *@par Attributes:
  280. *keep_dims: A bool. If true, retains reduced dimensions with length 1.
  281. *@par Outputs:
  282. *y: The reduced tensor.
  283. */
  284. REG_OP(ReduceAll)
  285. .INPUT(x, TensorType({DT_BOOL}))
  286. .INPUT(axes, TensorType::IndexNumberType())
  287. .OUTPUT(y, TensorType({DT_BOOL}))
  288. .ATTR(keep_dims, Bool, false)
  289. .OP_END_FACTORY_REG(ReduceAll)
  290. /**
  291. *@brief Reduce a tensor on a certain axis based on product..
  292. *@par Inputs:
  293. *Two inputs, including:
  294. *@li x: A mutable Tensor. Must be the type of NumberType.
  295. *@li axis: A mutable Tensor. The dimensions to reduce.
  296. *@par Attributes:
  297. *@li keep_dims: A bool. If true, retains reduced dimensions with length 1. Defaults to "False".
  298. *@par Outputs:
  299. *y: A Tensor. Has the same type and format as input "x".
  300. */
  301. REG_OP(ReduceProd)
  302. .INPUT(x,TensorType::NumberType())
  303. .INPUT(axes, TensorType::IndexNumberType())
  304. .OUTPUT(y,TensorType::NumberType())
  305. .ATTR(keep_dims, Bool, false)
  306. .OP_END_FACTORY_REG(ReduceProd)
  307. /**
  308. *@brief Computes the product of elements across dimensions of a tensor.
  309. *@par Inputs:
  310. * One input: \n
  311. *x: A Tensor. Must be one of the following types: float16, float, int8, uint8.
  312. *@par Attributes:
  313. *@li axes: A required int8, int16, int32, or int64. Specifies the dimensions to reduce. No default value.
  314. *@li keep_dims: An optional bool. If "True", retains reduced dimensions with length 1. Defaults to "False".
  315. *@par Outputs:
  316. *y: A Tensor. Has the same type and format as input "x".
  317. *@attention Constraints:
  318. * "keep_dims" is in the range [-rank(input_tensor), rank(input_tensor)].
  319. */
  320. REG_OP(ReduceProdD)
  321. .INPUT(x,TensorType({DT_FLOAT, DT_UINT8, DT_INT8, DT_INT32, DT_FLOAT16}))
  322. .OUTPUT(y,TensorType({DT_FLOAT, DT_UINT8, DT_INT8, DT_INT32, DT_FLOAT16}))
  323. .REQUIRED_ATTR(axes, ListInt)
  324. .ATTR(keep_dims, Bool, false)
  325. .OP_END_FACTORY_REG(ReduceProdD)
  326. /**
  327. *@brief Reduces "x" along the dimensions according to "axis".
  328. *@par Inputs:
  329. *Two inputs, including:
  330. * @li x: A Tensor. Must be one of the following types: float16, float32, int8, uint8.
  331. * @li axes: The dimensions to reduce. Must be one of the following types: int, list, tuple, NoneType.\n
  332. * - If None (the default), reduces all dimensions.\n
  333. * - Must be in the range [-rank(x), rank(x)).
  334. *@par Attributes:
  335. *keep_dims: A bool or NoneType. \n
  336. * - If true, retains reduced dimensions with length 1. \n
  337. * - If false, the rank of the tensor is reduced by 1 for each entry in axis.
  338. *@par Outputs:
  339. *y: A Tensor. Has the same type as "x".
  340. */
  341. REG_OP(ReduceMean)
  342. .INPUT(x, TensorType::NumberType())
  343. .INPUT(axes, TensorType::IndexNumberType())
  344. .OUTPUT(y, TensorType::NumberType())
  345. .ATTR(keep_dims, Bool, false)
  346. .OP_END_FACTORY_REG(ReduceMean)
  347. /**
  348. *@brief Reduces "x" along the dimensions according to "axis".
  349. *@par Inputs:
  350. *One input:
  351. * @li x: A Tensor. Must be one of the following types: float16, float32, int8, uint8.
  352. *@par Attributes:
  353. *@li axes: The dimensions to reduce. Must be one of the following types: int, list, tuple, NoneType. \n
  354. * If None (the default), reduces all dimensions. \n
  355. * Must be in the range [-rank(x), rank(x)). \n
  356. *@li keep_dims: A bool or NoneType. \n
  357. * - If true, retains reduced dimensions with length 1. \n
  358. * - If false, the rank of the tensor is reduced by 1 for each entry in axis.
  359. *@par Outputs:
  360. *y: A Tensor. Has the same type as "x".
  361. */
  362. REG_OP(ReduceMeanD)
  363. .INPUT(x, TensorType({DT_FLOAT16, DT_INT32, DT_FLOAT, DT_INT8, DT_UINT8}))
  364. .OUTPUT(y, TensorType({DT_FLOAT16, DT_INT32, DT_FLOAT, DT_INT8, DT_UINT8}))
  365. .REQUIRED_ATTR(axes, ListInt)
  366. .ATTR(keep_dims, Bool, false)
  367. .OP_END_FACTORY_REG(ReduceMeanD)
  368. /**
  369. *@brief Returns the maximum of elements across dimensions of a Tensor.
  370. *@par Inputs:
  371. * Two inputs, including: \n
  372. *@li x: A multi-dimensional Tensor of type float16, float32, or int16.
  373. *@li axes: A Scalar of type int32, specifying the axes information of the index with the maximum value.
  374. *@par Attributes:
  375. *keep_dims: A bool, specifying whether to keep dimensions for the output Tensor. Defaults to "false".
  376. *@par Outputs:
  377. *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".)
  378. *@attention Constraints:
  379. * The value range of "axes" is [-dims, dims - 1]. "dims" indicates the dimension length of "x".
  380. */
  381. REG_OP(ReduceMax)
  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(ReduceMax)
  387. /**
  388. *@brief Returns the maximum of elements across dimensions of a Tensor.
  389. *@par Inputs:
  390. *x: A multi-dimensional Tensor of type float16, float32, or int16.
  391. *@par Attributes:
  392. * Two attributes, including: \n
  393. *@li axes: A required listint, specifying the axes information of the index with the maximum value.
  394. *@li keep_dims: A bool, specifying whether to keep dimensions for the output Tensor. Defaults to "false".
  395. *@par Outputs:
  396. *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".)
  397. *@attention Constraints:
  398. * The value range of "axis" is [-dims, dims - 1]. "dims" indicates the dimension length of "x".
  399. */
  400. REG_OP(ReduceMaxD)
  401. .INPUT(x, TensorType({DT_FLOAT, DT_UINT8, DT_INT8,
  402. DT_FLOAT16, DT_INT32}))
  403. .OUTPUT(y, TensorType({DT_FLOAT, DT_UINT8, DT_INT8,
  404. DT_FLOAT16, DT_INT32}))
  405. .REQUIRED_ATTR(axes, ListInt)
  406. .ATTR(keep_dims, Bool, false)
  407. .OP_END_FACTORY_REG(ReduceMaxD)
  408. /**
  409. *@brief Computes the minimum of elements across dimensions of a tensor.
  410. *@par Inputs:
  411. *@li input_tensor: A Tensor. Must be one of the following types: float16, float32, int8, uint8.
  412. *@li axes: A Tensor of type int8 or int32. Specifies the dimensions to reduce. Defaults to "None".
  413. *@par Attributes:\n
  414. *keep_dims: An optional bool. If "True", reduced dimensions will be retained. Defaults to "False".
  415. *@par Outputs:\n
  416. *output_tensor: A Tensor. Must be one of the following types: float16, float32, int8, uint8.
  417. *@attention Constraints:\n
  418. * If "axes = None", all dimensions will be reduced. "axes" must be in the range [-rank(input_shape), rank(input_shape)).
  419. */
  420. REG_OP(ReduceMin)
  421. .INPUT(x, TensorType::NumberType())
  422. .INPUT(axes, TensorType::IndexNumberType())
  423. .OUTPUT(y, TensorType::NumberType())
  424. .ATTR(keep_dims, Bool, false)
  425. .OP_END_FACTORY_REG(ReduceMin)
  426. /**
  427. *@brief Computes the minimum of elements across dimensions of a tensor.
  428. *@par Inputs:\n
  429. *input_min: A Tensor. Must be one of the following types: float16, float32, int8, uint8.
  430. *@par Attributes:
  431. *@li axes: An optional int32, list, tuple, or NoneType value. Specifies the dimensions to reduce. Defaults to "None".
  432. *@li keep_dims: An optional bool or NoneType value. If "True", reduced dimensions will be retained. Defaults to "None" (equivalent to "False").
  433. *@par Outputs:\n
  434. *output_min: A Tensor. Must be one of the following types: float16, float32, int8, uint8.
  435. *@attention Constraints:\n
  436. * If "axes = None", all dimensions will be reduced. "axes" must be in the range [-rank(input_shape), rank(input_shape)).
  437. */
  438. REG_OP(ReduceMinD)
  439. .INPUT(x, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT8,DT_UINT8}))
  440. .OUTPUT(y, TensorType({DT_FLOAT16,DT_FLOAT,DT_INT8,DT_UINT8}))
  441. .REQUIRED_ATTR(axes, ListInt)
  442. .ATTR(keep_dims, Bool, false)
  443. .OP_END_FACTORY_REG(ReduceMinD)
  444. /**
  445. *@brief Computes the "logical or" of elements across dimensions of a tensor.\n
  446. * Reduces "x" along the dimensions given in "axes".
  447. * Unless "keep_dims" is true, the rank of the tensor is reduced by 1 for each
  448. * entry in "axes". If "keep_dims" is true, the reduced dimensions
  449. * are retained with length 1.
  450. *
  451. * If "axes" is None, all dimensions are reduced, and a
  452. * tensor with a single element is returned.
  453. *
  454. *@attention Constraints:\n
  455. * Only support bool
  456. *
  457. *@par Inputs:
  458. *@li x : The boolean tensor to reduce.
  459. *@li axes: The dimensions to reduce. If "None" (default), reduces all
  460. * dimensions. Must be in the range "[-rank(x), rank(x))".
  461. *
  462. *@par Attributes:
  463. * keep_dims: If true, retains reduced dimensions with length 1.
  464. *
  465. *@par Outputs:
  466. * y: The reduced tensor
  467. *
  468. */
  469. REG_OP(ReduceAny)
  470. .INPUT(x, TensorType({DT_BOOL}))
  471. .INPUT(axes, TensorType::IndexNumberType())
  472. .OUTPUT(y, TensorType({DT_BOOL}))
  473. .ATTR(keep_dims, Bool, false)
  474. .OP_END_FACTORY_REG(ReduceAny)
  475. /**
  476. *@brief Computes the "logical or" of elements across dimensions of a tensor.\n
  477. * Reduces "x" along the dimensions given in "axes".
  478. * Unless "keep_dims" is true, the rank of the tensor is reduced by 1 for each
  479. * entry in "axes". If "keep_dims" is true, the reduced dimensions
  480. * are retained with length 1.
  481. *
  482. * If "axis" is None, all dimensions are reduced, and a
  483. * tensor with a single element is returned.
  484. *
  485. *@attention Constraints:\n
  486. * Only support bool
  487. *
  488. *@par Inputs:
  489. * x: The boolean tensor to reduce.
  490. *
  491. *@par Attributes:
  492. *@li axes: The dimensions to reduce. If "None" (default), reduces all
  493. * dimensions. Must be in the range "[-rank(x), rank(x))".
  494. *@li keep_dims: If true, retains reduced dimensions with length 1.
  495. *
  496. *@par Outputs:
  497. * y: The reduced tensor
  498. *
  499. */
  500. REG_OP(ReduceAnyD)
  501. .INPUT(x, TensorType({DT_BOOL}))
  502. .OUTPUT(y, TensorType({DT_BOOL}))
  503. .REQUIRED_ATTR(axes, ListInt)
  504. .ATTR(keep_dims, Bool, false)
  505. .OP_END_FACTORY_REG(ReduceAnyD)
  506. /**
  507. *@brief Compute reduction on dimensions specified by "axis".
  508. *Four reduction operations are provided:
  509. *SUM Computes the sum of elements across specified dimensions of a tensor.
  510. *ASUM Computes the sum of absolute values of elements across specified dimensions of a tensor.
  511. *SUMSQ Computes the sum of squares of elements across specified dimensions of a tensor.
  512. *SUMSQ Computes the mean values of elements across specified dimensions of a tensor.
  513. *@par Inputs:
  514. *x: A Tensor of type float16 or float32
  515. *@par Attributes:
  516. *@li operation: An optional int32 from 1(SUM), 2(ASUM), 3(SUMSQ), and 4(MEAN),
  517. *specifying the reduction algorithm. Defaults to 1.
  518. *@li axis: An optional int32, specifying the first axis to reduce. Defaults to "0".
  519. *The value range is [-N, N-1], where N is the input tensor rank.
  520. *@li coeff: An optional float32, specifying the scale coefficient. Defaults to "1.0".
  521. *@par Outputs:
  522. *y: A Tensor. Has the same type as "x".
  523. *@attention Constraints: The Reduction operator supports type float16 only on the device chip.
  524. */
  525. REG_OP(Reduction)
  526. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  527. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  528. .ATTR(operation, Int, 1)
  529. .ATTR(axis, Int, 0)
  530. .ATTR(coeff, Float, 1.0)
  531. .OP_END_FACTORY_REG(Reduction);
  532. } //namespace ge
  533. #endif /* GE_OP_REDUCE_OPS_H */

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