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

5 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
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
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
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
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
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331
  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. /*!
  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/1000 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/1000 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/1000 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/1000 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/1000 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. *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. *@li y: A Tensor of type float16 or float32 for the normalized "x".
  823. *@li batch_mean: A Tensor of type float32 for the result mean.
  824. *@li 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 reduce 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:
  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. * This operator is a InstanceNorm fusion operator for updating the moving averages for training.
  876. * This operator is used in conjunction with INTrainingReduceV2.
  877. */
  878. REG_OP(INTrainingUpdateV2)
  879. .INPUT(x, TensorType({DT_FLOAT16,DT_FLOAT}))
  880. .INPUT(sum, TensorType({DT_FLOAT}))
  881. .INPUT(square_sum, TensorType({DT_FLOAT}))
  882. .OPTIONAL_INPUT(gamma, TensorType({DT_FLOAT}))
  883. .OPTIONAL_INPUT(beta, TensorType({DT_FLOAT}))
  884. .OPTIONAL_INPUT(mean, TensorType({DT_FLOAT}))
  885. .OPTIONAL_INPUT(variance, TensorType({DT_FLOAT}))
  886. .ATTR(momentum, Float, 0.1)
  887. .ATTR(epsilon, Float, 0.00001)
  888. .OUTPUT(y, TensorType({DT_FLOAT16,DT_FLOAT}))
  889. .OUTPUT(batch_mean, TensorType({DT_FLOAT}))
  890. .OUTPUT(batch_variance, TensorType({DT_FLOAT}))
  891. .OP_END_FACTORY_REG(INTrainingUpdateV2)
  892. /**
  893. *@brief Performs the backpropagation of InstanceNorm. \n
  894. *@par Inputs:
  895. * Seven inputs, including:
  896. *@li dy: A Tensor of type float16 or float32.
  897. *@li x: A Tensor of type float16 or float32.
  898. *@li variance: A Tensor of type float32, for the variance of "x".
  899. *@li mean: A Tensor of type float32, for the mean of "x".
  900. *@li res_gamma: A Tensor of type float32.
  901. *@li res_beta: A Tensor of type float32.
  902. *@li gamma: A Tensor of type float32. \n
  903. *@par Outputs:
  904. *pd_x: A Tensor of type float16 or float32, for the offset of "x". \n
  905. *@attention Constraints:
  906. * The preceding layer of this operator must be INTrainingUpdateGrad. \n
  907. */
  908. REG_OP(INTrainingReduceGrad)
  909. .INPUT(dy, TensorType({DT_FLOAT16,DT_FLOAT}))
  910. .INPUT(x, TensorType({DT_FLOAT16,DT_FLOAT}))
  911. .INPUT(variance, TensorType({DT_FLOAT}))
  912. .INPUT(mean, TensorType({DT_FLOAT}))
  913. .INPUT(res_gamma, TensorType({DT_FLOAT}))
  914. .INPUT(res_beta, TensorType({DT_FLOAT}))
  915. .INPUT(gamma, TensorType({DT_FLOAT}))
  916. .OUTPUT(pd_x, TensorType({DT_FLOAT16,DT_FLOAT}))
  917. .OP_END_FACTORY_REG(INTrainingReduceGrad)
  918. /**
  919. *@brief Performs the backpropagation of InstanceNorm. \n
  920. *@par Inputs:
  921. * Four inputs, including:
  922. *@li dy: A Tensor of type float16 or float32, for the gradient.
  923. *@li x: A Tensor of type float16 or float32.
  924. *@li variance: A Tensor of type float32, for the variance of "x".
  925. *@li mean: A Tensor of type float32, for the mean of "x". \n
  926. *@par Outputs:
  927. *@li res_gamma: A Tensor of type float32.
  928. *@li res_beta: A Tensor of type float32. \n
  929. */
  930. REG_OP(INTrainingUpdateGrad)
  931. .INPUT(dy, TensorType({DT_FLOAT16,DT_FLOAT}))
  932. .INPUT(x, TensorType({DT_FLOAT16,DT_FLOAT}))
  933. .INPUT(variance, TensorType({DT_FLOAT}))
  934. .INPUT(mean, TensorType({DT_FLOAT}))
  935. .OUTPUT(res_gamma, TensorType({DT_FLOAT}))
  936. .OUTPUT(res_beta, TensorType({DT_FLOAT}))
  937. .OP_END_FACTORY_REG(INTrainingUpdateGrad)
  938. /**
  939. *@brief Performs the backpropagation of InstanceNorm. \n
  940. *@par Inputs:
  941. * Two inputs, including:
  942. *@li res_gamma: A Tensor of type float32.
  943. *@li res_beta: A Tensor of type float32. \n
  944. *@par Outputs:
  945. *@li pd_gamma: A Tensor of type float32.
  946. *@li pd_beta: A Tensor of type float32. \n
  947. */
  948. REG_OP(INTrainingUpdateGradGammaBeta)
  949. .INPUT(res_gamma, TensorType({DT_FLOAT}))
  950. .INPUT(res_beta, TensorType({DT_FLOAT}))
  951. .OUTPUT(pd_gamma, TensorType({DT_FLOAT}))
  952. .OUTPUT(pd_beta, TensorType({DT_FLOAT}))
  953. .OP_END_FACTORY_REG(INTrainingUpdateGradGammaBeta)
  954. /**
  955. *@brief Performs reduced group normalization . \n
  956. *@par Inputs:
  957. *x: A Tensor of type float16 or float32, with format NCHW NHWC . \n
  958. *@par Outputs:
  959. *@li sum: A Tensor of type float32 for SUM reduced "x".
  960. *@li square_sum: A Tensor of type float32 for SUMSQ reduced "x".
  961. *@par Attributes:
  962. *num_groups: Int, specifying the num of groups. required, same to GNTrainingUpdate . \n
  963. *@attention Constraints:
  964. * This operator is a GroupNorm fusion operator for updating the moving averages for training.
  965. * This operator is used in conjunction with GNTrainingUpdate.
  966. */
  967. REG_OP(GNTrainingReduce)
  968. .INPUT(x, TensorType({DT_FLOAT16,DT_FLOAT}))
  969. .OUTPUT(sum, TensorType({DT_FLOAT}))
  970. .OUTPUT(square_sum, TensorType({DT_FLOAT}))
  971. .ATTR(num_groups, Int, 2)
  972. .OP_END_FACTORY_REG(GNTrainingReduce)
  973. /**
  974. *@brief Performs update group normalization . \n
  975. *@par Inputs:
  976. * Seven inputs, including: (NCHW NHWC supported)
  977. *@li x: A Tensor of type float16 or float32.
  978. *@li sum: A 5D Tensor of type float32,
  979. shape is [N, G, 1, 1, 1] for NCHW, [N, 1, 1, G, 1] for NHWC
  980. for the output of operator GNTrainingReduce.
  981. *@li square_sum: A 5D Tensor of type float32,
  982. shape is [N, G, 1, 1, 1] for NCHW, [N, 1, 1, G, 1] for NHWC
  983. for the output of operator GNTrainingReduce.
  984. *@li scale: A 5D Tensor of type float32,
  985. shape is [1, G, 1, 1, 1] for NCHW, [1, 1, 1, G, 1] for NHWC
  986. is for the scaling gamma.
  987. *@li offset: A 5D Tensor of type float32,
  988. shape is [1, G, 1, 1, 1] for NCHW, [1, 1, 1, G, 1] for NHWC
  989. for the scaling beta.
  990. *@li mean: A 5D Tensor of type float32,
  991. shape is [N, G, 1, 1, 1] for NCHW, [N, 1, 1, G, 1] for NHWC
  992. for the updated mean.
  993. *@li variance: A 5D Tensor of type float32,
  994. shape is [N, G, 1, 1, 1] for NCHW, [N, 1, 1, G, 1] for NHWC
  995. for the updated variance.
  996. *@par Attributes:
  997. *@li epsilon: A float32, specifying the small value added to variance to avoid dividing by zero.
  998. *@li num_groups: Int, specifying the num of groups. required, same to GNTrainingReduce
  999. *@par Outputs:
  1000. * Three outputs, including: (NC1HWC0 supported)
  1001. *@li y: A Tensor of type float16 or float32, for normalized "x".
  1002. *@li batch_mean: A Tensor of type float32, for the updated mean.
  1003. *@li batch_variance: A Tensor of type float32, for the updated variance . \n
  1004. *@attention Constraints:
  1005. *@li This operator is a InstanceNorm fusion operator for updating the moving averages for training.
  1006. * This operator is used in conjunction with GNTrainingUpdate.
  1007. *@li For Ascend 310, the result accuracy fails to reach 1/1000 due to the square root instruction.
  1008. */
  1009. REG_OP(GNTrainingUpdate)
  1010. .INPUT(x, TensorType({DT_FLOAT16,DT_FLOAT}))
  1011. .INPUT(sum, TensorType({DT_FLOAT}))
  1012. .INPUT(square_sum, TensorType({DT_FLOAT}))
  1013. .OPTIONAL_INPUT(scale, TensorType({DT_FLOAT}))
  1014. .OPTIONAL_INPUT(offset, TensorType({DT_FLOAT}))
  1015. .OPTIONAL_INPUT(mean, TensorType({DT_FLOAT}))
  1016. .OPTIONAL_INPUT(variance, TensorType({DT_FLOAT}))
  1017. .ATTR(num_groups, Int, 2)
  1018. .ATTR(epsilon, Float, 0.0001)
  1019. .OUTPUT(y, TensorType({DT_FLOAT16,DT_FLOAT}))
  1020. .OUTPUT(batch_mean, TensorType({DT_FLOAT}))
  1021. .OUTPUT(batch_variance, TensorType({DT_FLOAT}))
  1022. .OP_END_FACTORY_REG(GNTrainingUpdate)
  1023. /**
  1024. *@brief Joins a string Tensor across the given dimensions. \n
  1025. *@par Inputs:
  1026. include:
  1027. *@li input:A Tensor of type string. The text to be processed.
  1028. *@li reduction_indices:A Tensor of type int. The text to be processed.
  1029. *@par Attributes:
  1030. *@li keep_dims:A bool, An optional bool. Defaults to False. If True, retain reduced dimensions with length 1..
  1031. *@li separator:string.
  1032. *@par Outputs:
  1033. *output:A Tensor of type string.
  1034. */
  1035. REG_OP(ReduceJoin)
  1036. .INPUT(input, TensorType({DT_STRING}))
  1037. .INPUT(reduction_indices, TensorType({DT_INT32}))
  1038. .OUTPUT(output, TensorType({DT_STRING}))
  1039. .ATTR(keep_dims, Bool, true)
  1040. .ATTR(separator, String, "")
  1041. .OP_END_FACTORY_REG(ReduceJoin)
  1042. /**
  1043. * @brief Calculates the standard deviation and average value of Tensors.
  1044. * @par Inputs:
  1045. * x: A Tensor. Must be one of the following types:
  1046. * float16, float32. \n
  1047. * @par Attributes:
  1048. * Three Attributes, including:
  1049. * @li dim: An optional listint, Defaults to "None". \n
  1050. * @li unbiased: An optional bool. Defaults to "True".
  1051. * If "True", Use Bessel Correction.
  1052. * If "False", Do not use Bessel Correction. \n
  1053. * @li keepdim: An optional bool. Defaults to "False".
  1054. * If "True", Keep the original tensor dimension.
  1055. * If "False", Do not keep the original tensor dimension. \n
  1056. * @par Outputs:
  1057. * Two Outputs, including:
  1058. * @li y1: A Tensor. Has the same type as "x".
  1059. * @li y2: A Tensor. Has the same type as "x". \n
  1060. * @par Third-party framework compatibility
  1061. * Compatible with the Pytorch operator ReduceStd.
  1062. */
  1063. REG_OP(ReduceStd)
  1064. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16}))
  1065. .OUTPUT(y1, TensorType({DT_FLOAT, DT_FLOAT16}))
  1066. .OUTPUT(y2, TensorType({DT_FLOAT, DT_FLOAT16}))
  1067. .ATTR(dim, ListInt, {})
  1068. .ATTR(unbiased, Bool, true)
  1069. .ATTR(keepdim, Bool, false)
  1070. .OP_END_FACTORY_REG(ReduceStd)
  1071. /**
  1072. * @brief Calculates the standard deviation of Tensors.
  1073. * @par Inputs:
  1074. * include:
  1075. * @li x: A Tensor. Must be one of the following types: float16, float32. \n
  1076. * @li mean: A Tensor. It's the mean of X. Must be one of the following types: float16, float32. \n
  1077. * @par Attributes:
  1078. * Five Attributes, including:
  1079. * @li dim: An optional listint, Defaults to "None". \n
  1080. * @li unbiased: An optional bool. Defaults to "True".
  1081. * If "True", Use Bessel Correction.
  1082. * If "False", Do not use Bessel Correction. \n
  1083. * @li keepdim: An optional bool. Defaults to "False".
  1084. * If "True", Keep the original tensor dimension.
  1085. * If "False", Do not keep the original tensor dimension. \n
  1086. * @li invert: An optional bool, Defaults to "False".
  1087. * If "True", the output is inverse of variance.
  1088. * If "False", the output is variance.
  1089. * @li epsilon: An optional floar, Defaults to 0.001.
  1090. * Prevent division by 0.
  1091. * @par Outputs:
  1092. * @li y: A Tensor. It's the variance of X or reciprocal of vaiance of X. Has the same type as "x".
  1093. * @par Third-party framework compatibility
  1094. * Compatible with the Pytorch operator ReduceStdWithMean.
  1095. */
  1096. REG_OP(ReduceStdWithMean)
  1097. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16}))
  1098. .INPUT(mean, TensorType({DT_FLOAT, DT_FLOAT16}))
  1099. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16}))
  1100. .ATTR(dim, ListInt, {})
  1101. .ATTR(unbiased, Bool, true)
  1102. .ATTR(keepdim, Bool, false)
  1103. .ATTR(invert, Bool, false)
  1104. .ATTR(epsilon, Float, 0.001)
  1105. .OP_END_FACTORY_REG(ReduceStdWithMean)
  1106. /**
  1107. *@brief Performs reduced batch normalization . \n
  1108. *@par Inputs:
  1109. *x: A 5D Tensor of type float16 or float32, with format NC1HWC0 . \n
  1110. *@par Outputs:
  1111. *@li mean: A Tensor of type float32 for SUM reduced "x".
  1112. *@li variance: A Tensor of type float32 for square sum reduced "x" . \n
  1113. *@par Restrictions:
  1114. * Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  1115. */
  1116. REG_OP(ReduceMeanVariance)
  1117. .INPUT(x, TensorType({DT_FLOAT16,DT_FLOAT}))
  1118. .OUTPUT(mean, TensorType({DT_FLOAT16,DT_FLOAT}))
  1119. .OUTPUT(variance, TensorType({DT_FLOAT16,DT_FLOAT}))
  1120. .ATTR(axes, ListInt, {})
  1121. .ATTR(keep_dims, Bool, true)
  1122. .OP_END_FACTORY_REG(ReduceMeanVariance)
  1123. } //namespace ge
  1124. #endif // OPS_BUILT_IN_OP_PROTO_INC_REDUCE_OPS_H_

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