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 46 kB

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

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