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.

nonlinear_fuc_ops.h 34 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
4 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
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
5 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 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
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090
  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 nonlinear_fuc_ops.h
  18. * \brief
  19. */
  20. #ifndef OPS_BUILT_IN_OP_PROTO_INC_NONLINEAR_FUC_OPS_H_
  21. #define OPS_BUILT_IN_OP_PROTO_INC_NONLINEAR_FUC_OPS_H_
  22. #include "graph/operator_reg.h"
  23. namespace ge {
  24. /**
  25. *@brief Computes the for the gelu of "x" . \n
  26. *@par Inputs:
  27. *One input, including:
  28. *x: A Tensor. Must be one of the following types: float16, float32
  29. *@par Outputs:
  30. *y: A Tensor. Has the same type as "x".
  31. *@par Third-party framework compatibility
  32. *Compatible with the TensorFlow operator Gelu
  33. */
  34. REG_OP(Gelu)
  35. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  36. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  37. .OP_END_FACTORY_REG(Gelu)
  38. /**
  39. * @brief Compute hard_swish of "x" element-wise . \n
  40. *@par Inputs:
  41. *One input, including:
  42. *x: A Tensor. Must be one of the following types: float16, float32
  43. *@par Outputs:
  44. *y: A Tensor. Has the same type as "x".
  45. *@par Third-party framework compatibility
  46. * Compatible with the Torch operator HardSwish.
  47. */
  48. REG_OP(HardSwish)
  49. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  50. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  51. .OP_END_FACTORY_REG(HardSwish)
  52. /**
  53. *@brief Computes the for the Swish of "x" . \n
  54. *@par Inputs:
  55. *One input, including:
  56. *x: A Tensor. Must be one of the following types: float16, float32
  57. *@par Outputs:
  58. *y: A Tensor. Has the same type as "x".
  59. *@par Attributes:
  60. *scale: scalar parameter, default value = 1.0
  61. *@par Third-party framework compatibility
  62. *Compatible with the Torch operator Swish
  63. */
  64. REG_OP(Swish)
  65. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  66. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  67. .ATTR(scale, Float, 1.0)
  68. .OP_END_FACTORY_REG(Swish)
  69. /**
  70. *@brief Computes the gradient for the gelu of "x" . \n
  71. *@par Inputs:
  72. *Three inputs, including:
  73. * @li dy: A Tensor. Must be one of the following types: float16, float32
  74. * @li x: A Tensor of the same type as "dy".
  75. * @li y: A Tensor of the same type as "dy" . \n
  76. *@par Outputs:
  77. *z: A Tensor. Has the same type as "dy".
  78. *@par Third-party framework compatibility
  79. *Compatible with the TensorFlow operator GeluGrad
  80. */
  81. REG_OP(GeluGrad)
  82. .INPUT(dy, TensorType({DT_FLOAT16, DT_FLOAT}))
  83. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  84. .INPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  85. .OUTPUT(z, TensorType({DT_FLOAT16, DT_FLOAT}))
  86. .OP_END_FACTORY_REG(GeluGrad)
  87. /**
  88. *@brief Computes the for the fast_gelu of "x" . \n
  89. *@par Inputs:
  90. *One input, including:
  91. *x: A Tensor. Must be one of the following types: float16, float32
  92. *@par Outputs:
  93. *y: A Tensor. Has the same type as "x".
  94. *@par Third-party framework compatibility
  95. *Compatible with the TensorFlow operator FastGelu
  96. */
  97. REG_OP(FastGelu)
  98. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  99. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  100. .OP_END_FACTORY_REG(FastGelu)
  101. /**
  102. *@brief Computes the gradient for the fast_gelu of "x" . \n
  103. *@par Inputs:
  104. *Two inputs, including:
  105. * @li dy: A Tensor. Must be one of the following types: float16, float32
  106. * @li x: A Tensor of the same type as "dy" . \n
  107. *@par Outputs:
  108. *z: A Tensor. Has the same type as "dy".
  109. *@par Third-party framework compatibility
  110. *Compatible with the TensorFlow operator FastGeluGrad
  111. */
  112. REG_OP(FastGeluGrad)
  113. .INPUT(dy, TensorType({DT_FLOAT16, DT_FLOAT}))
  114. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  115. .OUTPUT(z, TensorType({DT_FLOAT16, DT_FLOAT}))
  116. .OP_END_FACTORY_REG(FastGeluGrad)
  117. /**
  118. *@brief Computes the gradient for the tanh of "x" . \n
  119. *@par Inputs:
  120. *Two inputs, including:
  121. * @li y: A Tensor. Must be one of the following types: float16, float32,
  122. * double, complex64, complex128.
  123. * @li dy: A Tensor of the same type as "y" . \n
  124. *@par Outputs:
  125. *z: A Tensor. Has the same type as "y".
  126. *@par Third-party framework compatibility
  127. *Compatible with the TensorFlow operator TanhGrad.
  128. */
  129. REG_OP(TanhGrad)
  130. .INPUT(y, TensorType::UnaryDataType())
  131. .INPUT(dy, TensorType::UnaryDataType())
  132. .OUTPUT(z, TensorType::UnaryDataType())
  133. .OP_END_FACTORY_REG(TanhGrad)
  134. /**
  135. *@brief: Computes hyperbolic tangent of "x" element-wise . \n
  136. *@par Inputs:
  137. *One input:
  138. *x: A Tensor. Must be one of the following types: float16, float32, complex64, complex128, double . \n
  139. *@par Outputs:
  140. *y: A Tensor. Has the same type as "x" . \n
  141. *@par Third-party framework compatibility
  142. * Compatible with TensorFlow operator Tanh.
  143. */
  144. REG_OP(Tanh)
  145. .INPUT(x, TensorType::UnaryDataType())
  146. .OUTPUT(y, TensorType::UnaryDataType())
  147. .OP_END_FACTORY_REG(Tanh)
  148. /**
  149. * @brief Computes rectified linear: "max(x, 0)".
  150. *
  151. * @par Inputs:
  152. * x: A tensor. Must be one of the following types: float32, float64, int32, uint8,
  153. * int16, int8, int64, uint16, float16, qint8.
  154. *
  155. * @par Outputs:
  156. * y: A tensor. Has the same type as "x".
  157. *
  158. * @par Third-party framework compatibility
  159. * @li Compatible with the TensorFlow operator Relu.
  160. * @li Compatible with the Caffe operator ReLULayer.
  161. *
  162. */
  163. REG_OP(Relu)
  164. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16, DT_DOUBLE,
  165. DT_INT8, DT_INT32, DT_INT16, DT_INT64,
  166. DT_UINT8, DT_UINT16, DT_QINT8}))
  167. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_DOUBLE,
  168. DT_INT8, DT_INT32, DT_INT16, DT_INT64,
  169. DT_UINT8, DT_UINT16, DT_QINT8}))
  170. .OP_END_FACTORY_REG(Relu)
  171. /**
  172. * @brief Computes rectified linear 6.
  173. * activations = min(max(x, 0), 6) . \n
  174. * @par Inputs:
  175. * x: A Tensor of type RealNumberType . \n
  176. * @par Outputs:
  177. * y: A Tensor with the same type as x . \n
  178. * @par Third-party framework compatibility
  179. * Compatible with the TensorFlow operator Relu6.
  180. */
  181. REG_OP(Relu6)
  182. .INPUT(x, TensorType::RealNumberType())
  183. .OUTPUT(y, TensorType::RealNumberType())
  184. .OP_END_FACTORY_REG(Relu6)
  185. /**
  186. * @brief Computes rectified linear 6*scale.
  187. * activations = min(max(x, 0), 6*scale) . \n
  188. * @par Inputs:
  189. * x: A Tensor of type RealNumberType . \n
  190. * @par Attributes:
  191. * epsilon: A required scalar. The data type is float32 . \n
  192. * @par Outputs:
  193. * y: A Tensor of type RealNumberType . \n
  194. * @par Third-party framework compatibility
  195. * Compatible with the TensorFlow operator Relu6.
  196. *
  197. *@par Restrictions:
  198. *Warning: THIS FUNCTION IS DEPRECATED. Please use Relu6 instead.
  199. */
  200. REG_OP(Relu6D)
  201. .INPUT(x, TensorType::RealNumberType())
  202. .OUTPUT(y, TensorType::RealNumberType())
  203. .ATTR(scale, Float, 1.0)
  204. .OP_END_FACTORY_REG(Relu6D)
  205. /**
  206. * @brief Computes rectified linear 6 gradients for a Relu6 operation.
  207. * backprops = gradients * (features > 0) * (features < 6) . \n
  208. * @par Inputs:
  209. * @li gradients: A Tensor of type RealNumberType. The backpropagated
  210. gradients to the corresponding Relu6 operation.
  211. * @li features: A Tensor with the same type as gradients.he features passed
  212. as input to the corresponding Relu6 operation, or its output;
  213. using either one produces the same result. \n
  214. * @par Outputs:
  215. * backprops: A Tensor of type RealNumberType . \n
  216. * @par Third-party framework compatibility
  217. * Compatible with the TensorFlow operator Relu6Grad.
  218. */
  219. REG_OP(Relu6Grad)
  220. .INPUT(gradients, TensorType::RealNumberType())
  221. .INPUT(features, TensorType::RealNumberType())
  222. .OUTPUT(backprops, TensorType::RealNumberType())
  223. .OP_END_FACTORY_REG(Relu6Grad)
  224. /**
  225. *@brief Calculate the elu_grad_v2 function.
  226. *Applies the element-wise function:
  227. * Computes the backward for the elu: if x>0, 1; otherwise elu() + alpha .
  228. *@par Inputs:
  229. *Two inputs, including:
  230. * @li grads: A tensor. Must be one of the following types:
  231. * float16, float32.
  232. * @li activations: A tensor. Must be one of the following types:
  233. * float16, float32.
  234. *
  235. *@par Outputs:
  236. *y: A Tensor with the same type and shape of grads's.
  237. *
  238. *@par Attributes:
  239. *alpha: scalar parameter, default value = 1.0
  240. */
  241. REG_OP(EluGradV2)
  242. .INPUT(grads, TensorType({DT_FLOAT, DT_FLOAT16}))
  243. .INPUT(activations, TensorType({DT_FLOAT, DT_FLOAT16}))
  244. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16}))
  245. .ATTR(alpha, Float, 1.0)
  246. .OP_END_FACTORY_REG(EluGradV2)
  247. /**
  248. * @brief Compute sigmoid of "x" element-wise . \n
  249. * @par Inputs:
  250. * A Tensor of type complex64, complex128, float16, float32 or double . \n
  251. * @par Outputs:
  252. * A Tensor. Has the same type as "x" . \n
  253. * @see Relu()
  254. * @par Third-party framework compatibility
  255. * Compatible with the TensorFlow operator Sigmoid.
  256. */
  257. REG_OP(Sigmoid)
  258. .INPUT(x, TensorType::UnaryDataType())
  259. .OUTPUT(y, TensorType::UnaryDataType())
  260. .OP_END_FACTORY_REG(Sigmoid)
  261. /**
  262. * @brief Computes z = (y - y*y)*dy . \n
  263. * @par Inputs:
  264. * @li y: The input is Tensor, dtype is UnaryDataType.
  265. * @li dy: The input is Tensor, dtype is UnaryDataType . \n
  266. * @par Outputs:
  267. * z: The shape of output, dtype is UnaryDataType.
  268. */
  269. REG_OP(SigmoidGrad)
  270. .INPUT(y, TensorType(UnaryDataType))
  271. .INPUT(dy, TensorType(UnaryDataType))
  272. .OUTPUT(z, TensorType(UnaryDataType))
  273. .OP_END_FACTORY_REG(SigmoidGrad)
  274. /**
  275. *@brief Computes the binomial normal log likelihood (BNLL) output:
  276. *if x>0, x+log(1+exp(-x)); otherwise log(1+exp(x)) . \n
  277. *@par Inputs:
  278. *x: A Tensor of type double, float16 or float32 . \n
  279. *@par Outputs:
  280. *y: A tensor. Has the same type and format as input "x" . \n
  281. *@par Third-party framework compatibility
  282. * Compatible with the Caffe operator BNLL.
  283. */
  284. REG_OP(BNLL)
  285. .INPUT(x, TensorType::FloatingDataType())
  286. .OUTPUT(y, TensorType::FloatingDataType())
  287. .OP_END_FACTORY_REG(BNLL)
  288. /**
  289. *@brief Computes softplus: log(exp(x) + 1) . \n
  290. *@par Inputs:
  291. * One input:
  292. *x: A Tensor of type float16 or float32. Up to 8D . \n
  293. *@par Outputs:
  294. *y: The activations tensor. Has the same type and format as input "x"
  295. *@par Third-party framework compatibility
  296. * Compatible with the TensorFlow operator Softplus.
  297. */
  298. REG_OP(Softplus)
  299. .INPUT(x, TensorType::FloatingDataType())
  300. .OUTPUT(y, TensorType::FloatingDataType())
  301. .OP_END_FACTORY_REG(Softplus)
  302. /**
  303. *@brief Computes softplus gradients for a softplus operation . \n
  304. *@par Inputs:
  305. *Two inputs:
  306. * @li gradients: An NC1HWC0 or ND Tensor of type float16 or float32.
  307. * @li features: An NC1HWC0 or ND Tensor of type float16 or float32.
  308. *@par Outputs:
  309. *backprops: A Tensor. Has the same type and format as input "gradients" . \n
  310. *@par Third-party framework compatibility
  311. * Compatible with the TensorFlow operator SoftplusGrad.
  312. */
  313. REG_OP(SoftplusGrad)
  314. .INPUT(gradients, TensorType::FloatingDataType())
  315. .INPUT(features, TensorType::FloatingDataType())
  316. .OUTPUT(backprops, TensorType::FloatingDataType())
  317. .OP_END_FACTORY_REG(SoftplusGrad)
  318. /**
  319. *@brief Computes softsign: x/(abs(x) + 1) . \n
  320. *@par Inputs:
  321. * One input:
  322. *x: A Tensor of type float16 or float32. Up to 8D . \n
  323. *@par Outputs:
  324. *y: The activations tensor. Has the same type and format as "x"
  325. *@par Third-party framework compatibility
  326. * Compatible with the TensorFlow operator Softsign.
  327. */
  328. REG_OP(Softsign)
  329. .INPUT(x, TensorType::FloatingDataType())
  330. .OUTPUT(y, TensorType::FloatingDataType())
  331. .OP_END_FACTORY_REG(Softsign)
  332. /**
  333. *@brief Computes scaled exponential linear: scale * alpha * (exp(x) - 1) . \n
  334. *@par Inputs:
  335. * One input:
  336. *x: A Tensor. Must be one of the following types: float16, float, double
  337. * int32, int8. format:ND, NC1HWC0 . \n
  338. *@par Outputs:
  339. *y: A Tensor. Has the same type and format as input "x". format:ND, NC1HWC0 . \n
  340. *@see Region()
  341. *@par Third-party framework compatibility
  342. * Compatible with the TensorFlow operator Selu.
  343. */
  344. REG_OP(Selu)
  345. .INPUT(x, TensorType({DT_FLOAT16,DT_FLOAT,DT_DOUBLE,
  346. DT_INT8,DT_INT32}))
  347. .OUTPUT(y, TensorType({DT_FLOAT16,DT_FLOAT,DT_DOUBLE,
  348. DT_INT8,DT_INT32}))
  349. .OP_END_FACTORY_REG(Selu)
  350. /**
  351. *@brief Computes rectified linear gradients for a ReLU operation . \n
  352. *@par Inputs:
  353. * Two inputs, including:
  354. *@li gradients: A Tensor. Must be one of the following types: float32, double,
  355. * int32, int8, int16, int64, uint16, float16, uint32, uint64
  356. *@li features: A Tensor. Must be one of the following types: float32, double,
  357. * int32, int8, int16, int64, uint16, float16, uint32, uint64
  358. *@par Outputs:
  359. *backprops: A Tensor. Must have the same type as"gradients" . \n
  360. *@attention Constraints:
  361. * The corresponding Relu operator needs to be called before using this operator on the network . \n
  362. *@see Relu
  363. *@par Third-party framework compatibility
  364. * Compatible with TensorFlow operator ReluGrad.
  365. */
  366. REG_OP(ReluGrad)
  367. .INPUT(gradients, TensorType::RealNumberType())
  368. .INPUT(features, TensorType::RealNumberType())
  369. .OUTPUT(backprops, TensorType::RealNumberType())
  370. .OP_END_FACTORY_REG(ReluGrad)
  371. /**
  372. *@brief Computes rectified linear gradients for a ReLU operation . \n
  373. *@par Inputs:
  374. * Two inputs, including:
  375. *@li gradients: A Tensor. Must be one of the following types: float32, double, int32, int8, int16, int8, int64, uint16, float16, uint32, uint64
  376. *@li mask: A Tensor. Must be the following types: uint8
  377. *@par Outputs:
  378. *backprops: A Tensor. Must have the same type as"gradients" . \n
  379. *@attention Constraints:
  380. * The corresponding Relu operator needs to be called before using this operator on the network . \n
  381. *@see Relu
  382. *@par Third-party framework compatibility
  383. * Compatible with TensorFlow operator ReluGradV2.
  384. */
  385. REG_OP(ReluGradV2)
  386. .INPUT(gradients, TensorType::RealNumberType())
  387. .INPUT(mask, TensorType({DT_UINT8}))
  388. .OUTPUT(backprops, TensorType::RealNumberType())
  389. .OP_END_FACTORY_REG(ReluGradV2)
  390. /**
  391. *@brief Computes rectified linear: "max(x, 0)".
  392. *
  393. *@attention Constraints:
  394. * The last dimension must be divisible by 8.
  395. * The second output "mask" is "1" (for y >= 0) or "0" ( for y < 0).
  396. *
  397. *@par Inputs:
  398. * x: A tensor. Must be one of the following types: float32, float64, int32, uint8,
  399. * int16, int8, int64, uint16, float16, qint8.
  400. *
  401. *@par Outputs:
  402. *@li y: A tensor. Has the same type as "x".
  403. *@li mask: A tensor of type uint8.
  404. *
  405. *@par Third-party framework compatibility
  406. * Incompatible with TensorFlow or Caffe.
  407. *
  408. */
  409. REG_OP(ReluV2)
  410. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16, DT_DOUBLE, DT_INT8, DT_INT32, DT_INT16, DT_INT64, DT_UINT8, DT_UINT16, DT_QINT8}))
  411. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_DOUBLE, DT_INT8, DT_INT32, DT_INT16, DT_INT64, DT_UINT8, DT_UINT16, DT_QINT8}))
  412. .OUTPUT(mask, TensorType({DT_UINT8}))
  413. .OP_END_FACTORY_REG(ReluV2)
  414. /**
  415. *@brief Performs parametric ReLU . \n
  416. *@par Inputs:
  417. * Two inputs, including:
  418. *@li x: A multi-dimensional Tensor of type float16 or float32.
  419. *@li weight: A Scalar or 1D Tensor of type float16 or float32, specifying the weight, the initial value of "a". The number of dimensions must be the same as the number of channels . \n
  420. *@par Outputs:
  421. *y: An activated Tensor. Has the same dimensions with "x" . \n
  422. *@par Third-party framework compatibility
  423. * Compatible with PyTorch and Caffe operator PReLU.
  424. */
  425. REG_OP(PRelu)
  426. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16}))
  427. .INPUT(weight, TensorType({DT_FLOAT, DT_FLOAT16}))
  428. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16}))
  429. .OP_END_FACTORY_REG(PRelu)
  430. /**
  431. *@brief Performs the backpropagation of PRelu for training scenarios . \n
  432. *@par Inputs:
  433. * Three inputs, including:
  434. *@li grads: Input gradient. Multi-dimensional Tensors are supported. The data type can be float16 or float32.
  435. *@li features: A multi-dimensional Tensor of type float16 or float32.
  436. *@li weights: A Scalar or 1D Tensor of type float16 or float32, specifying the weight. The number of dimensions must be the same as the number of channels . \n
  437. *@par Outputs:
  438. *@li dx: Reverse gradient of "features". Has the same dimensions and type as "features".
  439. *@li da: Reverse gradient of "weight". Has the same dimensions and type as "features" . \n
  440. *@par Third-party framework compatibility
  441. * Compatible with PyTorch operator PReluGrad.
  442. */
  443. REG_OP(PReluGrad)
  444. .INPUT(grads, TensorType({DT_FLOAT16, DT_FLOAT}))
  445. .INPUT(features, TensorType({DT_FLOAT16, DT_FLOAT}))
  446. .INPUT(weights, TensorType({DT_FLOAT16, DT_FLOAT}))
  447. .OUTPUT(dx, TensorType({DT_FLOAT16, DT_FLOAT}))
  448. .OUTPUT(da, TensorType({DT_FLOAT16, DT_FLOAT}))
  449. .OP_END_FACTORY_REG(PReluGrad)
  450. /**
  451. *@brief Activation function fused from sigmoid and ReLU, with soft saturation
  452. * on the left and no saturation on the right . \n
  453. *@par Inputs:
  454. *x: A float16, float32 or double, for the input data type . \n
  455. *@par Attributes:
  456. *alpha: A float32. Defines at which negative value the ELU saturates. Defaults to "1.0" . \n
  457. *@par Outputs:
  458. *y: A float16, float32 or double, for the normalized result . \n
  459. *@attention Constraints:
  460. *@li The input is of type float16 or float32 . \n
  461. *@par Multiple batches supported or not
  462. *Supported
  463. *@par Third-party framework compatibility
  464. *@li Compatible with Tensorflow's Elu operator
  465. *@li Compatible with Caffe's ELULayer operator
  466. *
  467. *@since V100R001C33
  468. */
  469. REG_OP(Elu)
  470. .INPUT(x, TensorType::FloatingDataType())
  471. .OUTPUT(y, TensorType::FloatingDataType())
  472. .ATTR(alpha, Float, 1.0)
  473. .OP_END_FACTORY_REG(Elu)
  474. /**
  475. *@brief Continuously Differentiable Exponential Linear Uints:
  476. * Perform the linear uint element-wise on the input tensor X using formula:
  477. * max(0, x) + min(0, alpha * (exp(x/alpha) - 1)). \n
  478. *@par Inputs:
  479. *x: A float16, float32, for the input data type . \n
  480. *@par Attributes:
  481. *@li alpha1: A float32. Defines at which negative value the ELU saturates. Defaults to "1.0" .
  482. *@li alpha2: A float32. Defines at which negative value the ELU saturates. Defaults to "1.0" .
  483. *@li alpha3: A float32. Defines at which positive value the ELU saturates. Defaults to "1.0" . \n
  484. *@par Outputs:
  485. *y: A float16, float32, for the normalized result . \n
  486. *@attention Constraints:
  487. *@li The input is of type float16 or float32 . \n
  488. *@par Multiple batches supported or not
  489. *Supported
  490. *@par Third-party framework compatibility
  491. *@li Compatible with ONNX's Celu operator
  492. */
  493. REG_OP(Celu)
  494. .INPUT(x, TensorType({DT_FLOAT,DT_FLOAT16}))
  495. .OUTPUT(y, TensorType({DT_FLOAT,DT_FLOAT16}))
  496. .ATTR(alpha1, Float, 1.0)
  497. .ATTR(alpha2, Float, 1.0)
  498. .ATTR(alpha3, Float, 1.0)
  499. .OP_END_FACTORY_REG(Celu)
  500. /**
  501. *@brief Computes gradients for the exponential linear (Elu) operation.
  502. *
  503. *@par Inputs:
  504. *@li grads: A tensor. Must be one of the following types: float16, float32, float64.
  505. * The backpropagated gradients to the corresponding Elu operation.
  506. *@li activations: A tensor. Has the same type as "grads".
  507. * The outputs of the corresponding Elu operation.
  508. *
  509. *@par Outputs:
  510. * y: A tensor. Has the same type as "grads".
  511. *
  512. *@par Third-party framework compatibility
  513. *Compatible with the TensorFlow operator EluGrad.
  514. *
  515. */
  516. REG_OP(EluGrad)
  517. .INPUT(grads, TensorType::FloatingDataType())
  518. .INPUT(activations, TensorType::FloatingDataType())
  519. .OUTPUT(y, TensorType::FloatingDataType())
  520. .OP_END_FACTORY_REG(EluGrad)
  521. /**
  522. *@brief Computes the output as x if x > 0 and negative_slope * x if x <= 0 . \n
  523. *@par Inputs:
  524. * One input:
  525. * x: A Tensor. Must be one of the following types: float32, float16, double.
  526. *
  527. *@par Attributes:
  528. *negative_slope: A float32. Defaults to "0.0".
  529. *
  530. *@par Outputs:
  531. *y: A Tensor. Has the same type as "x".
  532. *@par Third-party framework compatibility
  533. * Compatible with the Caffe operator ReLU.
  534. */
  535. REG_OP(LeakyRelu)
  536. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16, DT_DOUBLE}))
  537. .ATTR(negative_slope, Float, 0.0)
  538. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_DOUBLE}))
  539. .OP_END_FACTORY_REG(LeakyRelu)
  540. /**
  541. *@brief Computes the output as gradients if features > 0 and negative_slope * gradients if features <= 0 . \n
  542. *@par Inputs:
  543. * Two inputs, including:
  544. * @li gradients: A Tensor. Must be one of the following types: float16, float32, double.
  545. * @li features: A Tensor. Has the same type as "gradients" . \n
  546. *@par Attributes:
  547. *negative_slope: A float32. Defaults to "0.0" . \n
  548. *@par Outputs:
  549. *backprops: A Tensor. Has the same type as "gradients" . \n
  550. *@par Third-party framework compatibility
  551. * Compatible with the TensorFlow operator LeakyReluGrad.
  552. */
  553. REG_OP(LeakyReluGrad)
  554. .INPUT(gradients, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  555. .INPUT(features, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  556. .ATTR(negative_slope, Float, 0.0)
  557. .OUTPUT(backprops, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  558. .OP_END_FACTORY_REG(LeakyReluGrad)
  559. /**
  560. *@brief Thresholds grad each element of the input Tensor . \n
  561. *@par Inputs:
  562. * @li gradients: A Tensor shape and dtype of input gradients. Support float16, int32.
  563. * @li features: A Tensor shape and dtype of input features. Support float16, int32 . \n
  564. *@par Attributes:
  565. *threshold: A float32 scale value to threshold at . \n
  566. *@par Outputs:
  567. *backprops: A Tensor of shape and dtype of output backprops, should be same shape and type as inputs . \n
  568. *@par Restrictions:
  569. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  570. */
  571. REG_OP(ThresholdGradV2D)
  572. .INPUT(gradients, TensorType({DT_INT32, DT_FLOAT16}))
  573. .INPUT(features, TensorType({DT_INT32, DT_FLOAT16}))
  574. .OUTPUT(backprops, TensorType({DT_INT32, DT_FLOAT16}))
  575. .REQUIRED_ATTR(threshold, Float)
  576. .OP_END_FACTORY_REG(ThresholdGradV2D)
  577. /**
  578. *@brief Thresholds each element of the input Tensor y = (x > threshold) ? x : value . \n
  579. *@par Inputs:
  580. *x: A Tensor dtype of real number . \n
  581. *@par Attributes:
  582. *@li threshold: A float32 scale value to threshold at.
  583. *@li value: A float32 scale value to replace with . \n
  584. *@par Outputs:
  585. *y: A Tensor of shape and dtype of output, should be same shape and type as input . \n
  586. *@par Restrictions:
  587. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  588. */
  589. REG_OP(ThresholdV2D)
  590. .INPUT(x, TensorType::RealNumberType())
  591. .OUTPUT(y, TensorType::RealNumberType())
  592. .REQUIRED_ATTR(threshold, Float)
  593. .REQUIRED_ATTR(value, Float)
  594. .OP_END_FACTORY_REG(ThresholdV2D)
  595. /**
  596. *@brief: Computes hyperbolic tangent of "x" element-wise . \n
  597. *@par Inputs:
  598. *One input:
  599. *x: A Tensor. Must be one of the following types: float16, float32 . \n
  600. *@par Outputs:
  601. *y: A Tensor. Has the same type as "x" . \n
  602. *@par Third-party framework compatibility
  603. * Compatible with TensorFlow operator Mish.
  604. */
  605. REG_OP(Mish)
  606. .INPUT(x, TensorType({ DT_FLOAT,DT_FLOAT16 }))
  607. .OUTPUT(y, TensorType({ DT_FLOAT,DT_FLOAT16 }))
  608. .OP_END_FACTORY_REG(Mish)
  609. /**
  610. * @brief: pytorch mish_grad operator.
  611. * @par Inputs:
  612. * three input, including:
  613. * @li grad: A Tensor. shape, datatype and format is same as x
  614. * @li x: A Tensor. Must be one of the following types: float16, float32
  615. * @li tanhx: A Tensor. shape, datatype and format is same as x
  616. * @par Outputs:
  617. * One output, including:
  618. * x_grad: A Tensor. shape, datatype and format is same as x
  619. */
  620. REG_OP(MishGrad)
  621. .INPUT(grad, TensorType({ DT_FLOAT,DT_FLOAT16 }))
  622. .INPUT(x, TensorType({ DT_FLOAT,DT_FLOAT16 }))
  623. .OPTIONAL_INPUT(tanhx, TensorType({ DT_FLOAT,DT_FLOAT16 }))
  624. .OUTPUT(x_grad, TensorType({ DT_FLOAT,DT_FLOAT16 }))
  625. .OP_END_FACTORY_REG(MishGrad)
  626. /**
  627. * @brief pytorch hardtanh_backward operator.
  628. *
  629. * @par Inputs:
  630. * Two inputs, including:
  631. * @li result, minimum tensor of the linear region range,
  632. * datatype: float16/float32, format:ND/5HD.
  633. * @li grad, maximum tensor of the linear region range,
  634. * datatype:float16/float32, format:ND/5HD. \n
  635. * @par Attributes:
  636. * Two attributes, including:
  637. * @li min_val, minimum value of the linear region range, datatype:float.
  638. * @li max_val, maximum value of the linear region range, datatype:float. \n
  639. * @par Outputs:
  640. * One output, including:
  641. * y, hardtanh_backward output tensor, datatype and format is same as
  642. * input result. \n
  643. * @attention Constraints:
  644. * This operator only supports dataType: float16/float32, format: ND/5HD. \n
  645. * @par Third-party framework compatibility
  646. * Compatible with the Pytorch operator HardtanhGrad.
  647. */
  648. REG_OP(HardtanhGrad)
  649. .INPUT(result, TensorType({ DT_FLOAT16, DT_FLOAT })) /* "First operand." */
  650. .INPUT(grad, TensorType({ DT_FLOAT16, DT_FLOAT })) /* "Second operand." */
  651. .OUTPUT(y, TensorType({ DT_FLOAT16, DT_FLOAT })) /* "Result, has same element type as two inputs" */
  652. .ATTR(min_val, Float, -1.0)
  653. .ATTR(max_val, Float, 1.0)
  654. .OP_END_FACTORY_REG(HardtanhGrad)
  655. /**
  656. * @brief Calculates the softplus loss function with attributes of beta and threshold. \n
  657. * @par Inputs:
  658. * One inputs, including:
  659. * x: A mutable Tensor. Must be one of the following types:
  660. * float16, float32. \n
  661. * @par Attributes:
  662. * @li beta: An optional float. Defaults to "1.0" \n
  663. * @li threshold: An optional float. Defaults to "20.0" \n
  664. * @par Outputs:
  665. * y: A mutable Tensor. Has the same type as "x" \n
  666. * @par Third-party framework compatibility
  667. * Compatible with the Pytorch operator Softplus.
  668. */
  669. REG_OP(SoftplusV2)
  670. .INPUT(x, TensorType({ DT_FLOAT, DT_FLOAT16 }))
  671. .OUTPUT(y, TensorType({ DT_FLOAT, DT_FLOAT16 }))
  672. .ATTR(beta, Float, 1.0)
  673. .ATTR(threshold, Float, 20.0)
  674. .OP_END_FACTORY_REG(SoftplusV2)
  675. /**
  676. * @brief Calculates the reversed outputs of the function "softplus_v2". \n
  677. * @par Inputs:
  678. * Two inputs, including:
  679. * @li input_gradients: A mutable Tensor. Must be one of the following types:
  680. * float16, float32.
  681. * @li input_features: A mutable Tensor of the same type as "input_gradients" \n
  682. * @par Attributes:
  683. * @li beta: An optional float. Defaults to "1.0" \n
  684. * @li threshold: An optional float. Defaults to "20.0" \n
  685. * @par Outputs:
  686. * output_backprops: A mutable Tensor. Has the same type as "input_gradients" \n
  687. * @par Third-party framework compatibility
  688. * Compatible with the Pytorch operator SoftplusGrad.
  689. */
  690. REG_OP(SoftplusV2Grad)
  691. .INPUT(input_gradients, TensorType({ DT_FLOAT, DT_FLOAT16 }))
  692. .INPUT(input_features, TensorType({ DT_FLOAT, DT_FLOAT16 }))
  693. .OUTPUT(output_backprops, TensorType({ DT_FLOAT, DT_FLOAT16 }))
  694. .ATTR(beta, Float, 1.0)
  695. .ATTR(threshold, Float, 20.0)
  696. .OP_END_FACTORY_REG(SoftplusV2Grad)
  697. /**
  698. * @brief ThresholdedRelu takes one input data (Tensor) and produces one output data (Tensor)
  699. * where the rectified linear function, y = x for x > alpha, y = 0 otherwise, is applied to the tensor elementwise.
  700. *
  701. * @par Inputs:
  702. * one input including:
  703. * x: input A Tensor. Must be one of the following types: float32, float16
  704. *
  705. * @par Attributes:
  706. * alpha: An optional float. Defaults to 1.0. \n
  707. * @par Outputs:
  708. * one output including:
  709. * y:A Tensor of the same type as x
  710. *
  711. */
  712. REG_OP(ThresholdedRelu)
  713. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  714. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  715. .ATTR(alpha, Float, 1.0)
  716. .OP_END_FACTORY_REG(ThresholdedRelu)
  717. /**
  718. * @brief Calculate the hard shrinkage function. \n
  719. * @par Inputs:
  720. * One inputs, including:
  721. * input_x: A tensor. Must be one of the following types:
  722. * float16, float32. \n
  723. * @par Attributes:
  724. * lambd: An optional float. Defaults to 0.5. \n
  725. * @par Outputs:
  726. * output_y: A Tensor with the same dtype and shape of input_x's. \n
  727. * @par Third-party framework compatibility
  728. * Compatible with the Pytorch operator Hardshrink. \n
  729. */
  730. REG_OP(HardShrink)
  731. .INPUT(input_x, TensorType({DT_FLOAT16, DT_FLOAT}))
  732. .OUTPUT(output_y, TensorType({DT_FLOAT16, DT_FLOAT}))
  733. .ATTR(lambd, Float, 0.5)
  734. .OP_END_FACTORY_REG(HardShrink)
  735. /**
  736. *@brief Calculate the hard shrink grad function. \n
  737. *
  738. * Computes the gradient for the HardShrink: if x > lambda or x < -lambda, x,otherwise 0
  739. *
  740. *@par Inputs:
  741. *Two inputs, including:
  742. * @li gradients: A tensor. Must be one of the following types:
  743. * float16, float32. \n
  744. * @li features: A tensor. Must be one of the following types:
  745. * float16, float32. \n
  746. *
  747. *@par Outputs:
  748. *backprops: A Tensor with the same type and shape of features's. \n
  749. *
  750. *@par Attributes:
  751. *lambd: An optional float.Defaults to 0.5. \n
  752. *
  753. *@par Third-party framework compatibility
  754. *Compatible with the Pytorch operator Hardshrink_backward. \n
  755. */
  756. REG_OP(HardShrinkGrad)
  757. .INPUT(gradients, TensorType({DT_FLOAT16, DT_FLOAT}))
  758. .INPUT(features, TensorType({DT_FLOAT16, DT_FLOAT}))
  759. .OUTPUT(backprops, TensorType({DT_FLOAT16, DT_FLOAT}))
  760. .ATTR(lambd, Float, 0.5)
  761. .OP_END_FACTORY_REG(HardShrinkGrad)
  762. /**
  763. * @brief Calculate the hard sigmoid function. \n
  764. * @par Inputs:
  765. * One inputs, including:
  766. * input_x: A tensor. Must be one of the following types:
  767. * float16, float32, int32. \n
  768. * @par Attributes:
  769. * @li alpha: An optional float. Defaults to 0.16666666. \n
  770. * @li beta: An optional float. Defaults to 0.5. \n
  771. * @par Outputs:
  772. * y: A Tensor with the same dtype and shape of input_x's. \n
  773. * @par Third-party framework compatibility
  774. * Compatible with the Pytorch operator Hardsigmoid. \n
  775. */
  776. REG_OP(HardSigmoid)
  777. .INPUT(input_x, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
  778. .OUTPUT(output_y, TensorType({DT_FLOAT, DT_FLOAT16}))
  779. .ATTR(alpha, Float, 0.16666666)
  780. .ATTR(beta, Float, 0.5)
  781. .OP_END_FACTORY_REG(HardSigmoid)
  782. /**
  783. * @brief Calculate the soft shrinkage function. \n
  784. * @par Inputs:
  785. * One inputs, including:
  786. * input_x: A tensor. Must be one of the following types:
  787. * float16, float32. \n
  788. * @par Attributes:
  789. * lambd: An optional float. Defaults to 0.5. \n
  790. * @par Outputs:
  791. * y: A Tensor with the same dtype and shape of input_x's. \n
  792. * @par Third-party framework compatibility
  793. * Compatible with the Pytorch operator Softshrink. \n
  794. */
  795. REG_OP(SoftShrink)
  796. .INPUT(input_x, TensorType({DT_FLOAT16, DT_FLOAT}))
  797. .OUTPUT(output_y, TensorType({DT_FLOAT16, DT_FLOAT}))
  798. .ATTR(lambd, Float, 0.5)
  799. .OP_END_FACTORY_REG(SoftShrink)
  800. /**
  801. * @brief Calculate the reversed outputs of the function "soft_shrink". \n
  802. * @par Inputs:
  803. * Two inputs, including:
  804. * @li input_grad: A tensor. Must be one of the following types:
  805. * float16, float32. \n
  806. * @li input_x: A tensor of the same dtype as "input_grad". \n
  807. * @par Attributes:
  808. * lambd: An optional float. Defaults to 0.5. \n
  809. * @par Outputs:
  810. * y: A Tensor of the same dtype and shape as "input_graxd". \n
  811. * @par Third-party framework compatibility
  812. * Compatible with the Pytorch operator SoftShrinkGrad. \n
  813. */
  814. REG_OP(SoftShrinkGrad)
  815. .INPUT(input_grad, TensorType({DT_FLOAT16, DT_FLOAT}))
  816. .INPUT(input_x, TensorType({DT_FLOAT16, DT_FLOAT}))
  817. .OUTPUT(output_y, TensorType({DT_FLOAT16, DT_FLOAT}))
  818. .ATTR(lambd, Float, 0.5)
  819. .OP_END_FACTORY_REG(SoftShrinkGrad)
  820. /**
  821. *@brief Calculate the gradient of log simoid. \n
  822. *@par Inputs:
  823. *Two inputs, including:
  824. * @li grads: A tensor, gradient of previous layer. Must be one of the following types:
  825. * float16, float32. \n
  826. * @li features: A tensor, input of log sigmoid. Must be one of the following types:
  827. * float16, float32. \n
  828. *@par Outputs:
  829. *One outputs, including:
  830. * @li backprops: A tensor with the same type of and shape of grads. \n
  831. *@par Third-party framework compatibility
  832. *Compatible with the Pytorch operator LogSigmoidBackward. \n
  833. */
  834. REG_OP(LogSigmoidGrad)
  835. .INPUT(grads, TensorType({DT_FLOAT16, DT_FLOAT}))
  836. .INPUT(features, TensorType({DT_FLOAT16, DT_FLOAT}))
  837. .OUTPUT(backprops, TensorType({DT_FLOAT16, DT_FLOAT}))
  838. .OP_END_FACTORY_REG(LogSigmoidGrad)
  839. /**
  840. *@brief Calculate -ln(1+e^(-x)). \n
  841. *@par Inputs:
  842. *One inputs, including:
  843. * x: A tensor. Must be one of the following types:
  844. * float16, float32. \n
  845. *@par Outputs:
  846. *One outputs, including:
  847. * y: A tensor with the same type and shape of x's. \n
  848. *@par Third-party framework compatibility
  849. *Compatible with the Pytorch operator LogSigmoid. \n
  850. */
  851. REG_OP(LogSigmoid)
  852. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT})) /* "input:x" */
  853. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT})) /* "output:y" */
  854. .OP_END_FACTORY_REG(LogSigmoid)
  855. /**
  856. *@brief Calculate the backward outputs of the function "hard_sigmoid" \n
  857. *@par Inputs:
  858. *One inputs, including:
  859. * @li grads: A tensor. Must be one of the following types:
  860. * float16, float32. \n
  861. * @li input_x: A tensor. Must be one of the following types:
  862. * float16, float32. \n
  863. *@par Outputs:
  864. *One outputs, including:
  865. * y: A tensor with the same type and shape of x's. \n
  866. * @par Attributes:
  867. * @li alpha: An optional float. Defaults to 0.16666666. \n
  868. * @li beta: An optional float. Defaults to 0.5. \n
  869. *@par Third-party framework compatibility
  870. *Compatible with the Pytorch operator LogSigmoidGrad. \n
  871. */
  872. REG_OP(HardSigmoidGrad)
  873. .INPUT(grads, TensorType({DT_FLOAT, DT_FLOAT16}))
  874. .INPUT(input_x, TensorType({DT_FLOAT, DT_FLOAT16}))
  875. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16}))
  876. .ATTR(alpha, Float, 0.16666666)
  877. .ATTR(beta, Float, 0.5)
  878. .OP_END_FACTORY_REG(HardSigmoidGrad)
  879. /**
  880. * @brief Calculate the shrink function. \n
  881. * @par Inputs:
  882. * One inputs, including:
  883. * @li input_x: A tensor. Must be one of the following types:
  884. * float16, float32. \n
  885. * @par Attributes:
  886. * @li lambd: An optional float. Defaults to 0.5. \n
  887. * @li bias: An optional float. Defaults to 0.0. \n
  888. * @par Outputs:
  889. * y: A Tensor with the same dtype and shape of input_x's. \n
  890. * @par Third-party framework compatibility
  891. * Compatible with the ONNX operator Shrink. \n
  892. */
  893. REG_OP(Shrink)
  894. .INPUT(input_x, TensorType({DT_FLOAT16, DT_FLOAT}))
  895. .OUTPUT(output_y, TensorType({DT_FLOAT16, DT_FLOAT}))
  896. .ATTR(lambd, Float, 0.5)
  897. .ATTR(bias, Float, 0.0)
  898. .OP_END_FACTORY_REG(Shrink)
  899. } // namespace ge
  900. #endif // OPS_BUILT_IN_OP_PROTO_INC_NONLINEAR_FUC_OPS_H_

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