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

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. /**
  2. * Copyright 2019-2020 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef GE_OP_NONLINEAR_FUC_OPS_H
  17. #define GE_OP_NONLINEAR_FUC_OPS_H
  18. #include "graph/operator_reg.h"
  19. namespace ge {
  20. /**
  21. *@brief Computes the for the gelu of "x".
  22. *@par Inputs:
  23. *Two inputs, including:
  24. * @li x: A Tensor. Must be one of the following types: float16, float32
  25. *@par Outputs:
  26. *y: A Tensor. Has the same type as "x".
  27. *@par Third-party framework compatibility
  28. *Compatible with the TensorFlow operator Gelu
  29. */
  30. REG_OP(Gelu)
  31. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  32. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  33. .OP_END_FACTORY_REG(Gelu)
  34. /**
  35. *@brief Computes the gradient for the gelu of "x".
  36. *@par Inputs:
  37. *Three inputs, including:
  38. * @li dy: A Tensor. Must be one of the following types: float16, float32
  39. * @li x: A Tensor of the same type as "dy".
  40. * @li y: A Tensor of the same type as "dy".
  41. *@par Outputs:
  42. *z: A Tensor. Has the same type as "dy".
  43. *@par Third-party framework compatibility
  44. *Compatible with the TensorFlow operator GeluGrad
  45. */
  46. REG_OP(GeluGrad)
  47. .INPUT(dy, TensorType({DT_FLOAT16, DT_FLOAT}))
  48. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  49. .INPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  50. .OUTPUT(z, TensorType({DT_FLOAT16, DT_FLOAT}))
  51. .OP_END_FACTORY_REG(GeluGrad)
  52. /**
  53. *@brief Computes the gradient for the tanh of "x".
  54. *@par Inputs:
  55. *Two inputs, including:
  56. * @li y: A Tensor. Must be one of the following types: float16, float32,
  57. * double, complex64, complex128.
  58. * @li dy: A Tensor of the same type as "y".
  59. *@par Outputs:
  60. *z: A Tensor. Has the same type as "y".
  61. *@par Third-party framework compatibility
  62. *Compatible with the TensorFlow operator TanhGrad.
  63. */
  64. REG_OP(TanhGrad)
  65. .INPUT(y, TensorType::UnaryDataType())
  66. .INPUT(dy, TensorType::UnaryDataType())
  67. .OUTPUT(z, TensorType::UnaryDataType())
  68. .OP_END_FACTORY_REG(TanhGrad)
  69. /**
  70. *@brief: Computes hyperbolic tangent of "x" element-wise.
  71. *@par Inputs:
  72. *One input:
  73. *x: A Tensor. Must be one of the following types: float16, float32, complex64, complex128, int32, int64
  74. *@par Outputs:
  75. *y: A Tensor. Has the same type as "x".
  76. *@par Third-party framework compatibility
  77. * Compatible with TensorFlow operator Tanh.
  78. */
  79. REG_OP(Tanh)
  80. .INPUT(x, TensorType::UnaryDataType())
  81. .OUTPUT(y, TensorType::UnaryDataType())
  82. .OP_END_FACTORY_REG(Tanh)
  83. /**
  84. * @brief Computes rectified linear: "max(x, 0)".
  85. *
  86. * @par Inputs:
  87. * x: A tensor. Must be one of the following types: float32, float64, int32, uint8,\n
  88. * int16, int8, int64, uint16, float16, qint8.
  89. *
  90. * @par Outputs:
  91. * y: A tensor. Has the same type as "x".
  92. *
  93. * @par Third-party framework compatibility
  94. * @li Compatible with the TensorFlow operator Relu.
  95. * @li Compatible with the Caffe operator ReLULayer.
  96. *
  97. */
  98. REG_OP(Relu)
  99. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16, DT_DOUBLE,
  100. DT_INT8, DT_INT32, DT_INT16, DT_INT64,
  101. DT_UINT8, DT_UINT16, DT_QINT8}))
  102. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_DOUBLE,
  103. DT_INT8, DT_INT32, DT_INT16, DT_INT64,
  104. DT_UINT8, DT_UINT16, DT_QINT8}))
  105. .OP_END_FACTORY_REG(Relu)
  106. /**
  107. * @brief Computes rectified linear 6.
  108. * activations = min(max(x, 0), 6).
  109. * @par Inputs:
  110. * x: A Tensor of type RealNumberType.
  111. * @par Outputs:
  112. * y: A Tensor of type RealNumberType.
  113. * @par Third-party framework compatibility
  114. * Compatible with the TensorFlow operator Relu6.
  115. */
  116. REG_OP(Relu6)
  117. .INPUT(x, TensorType::RealNumberType())
  118. .OUTPUT(y, TensorType::RealNumberType())
  119. .OP_END_FACTORY_REG(Relu6)
  120. /**
  121. * @brief Computes rectified linear 6*scale.
  122. * activations = min(max(x, 0), 6*scale).
  123. * @par Inputs:
  124. * x: A Tensor of type RealNumberType.
  125. * @par Attributes:
  126. * epsilon: A required scalar. The data type is float32.
  127. * @par Outputs:
  128. * y: A Tensor of type RealNumberType.
  129. * @par Third-party framework compatibility
  130. * Compatible with the TensorFlow operator Relu6.
  131. */
  132. REG_OP(Relu6D)
  133. .INPUT(x, TensorType::RealNumberType())
  134. .OUTPUT(y, TensorType::RealNumberType())
  135. .ATTR(scale, Float, 1.0)
  136. .OP_END_FACTORY_REG(Relu6D)
  137. /**
  138. * @brief Computes rectified linear 6 gradients for a Relu6 operation.
  139. * backprops = gradients * (features > 0) * (features < 6).
  140. * @par Inputs:
  141. * @li features: A Tensor of type RealNumberType.
  142. * @li gradients: A Tensor of type RealNumberType.
  143. * @par Outputs:
  144. * backprops: A Tensor of type RealNumberType.
  145. * @par Third-party framework compatibility
  146. * Compatible with the TensorFlow operator Relu6Grad.
  147. */
  148. REG_OP(Relu6Grad)
  149. .INPUT(gradients, TensorType::RealNumberType())
  150. .INPUT(features, TensorType::RealNumberType())
  151. .OUTPUT(backprops, TensorType::RealNumberType())
  152. .OP_END_FACTORY_REG(Relu6Grad)
  153. /**
  154. * @brief Compute sigmoid of "x" element-wise.
  155. * @par Inputs:
  156. * A Tensor of type UnaryDataType.
  157. * @par Outputs:
  158. * A Tensor. Has the same type as "x".
  159. * @see Relu()
  160. * @par Third-party framework compatibility
  161. * Compatible with the TensorFlow operator Sigmoid.
  162. */
  163. REG_OP(Sigmoid)
  164. .INPUT(x, TensorType::UnaryDataType())
  165. .OUTPUT(y, TensorType::UnaryDataType())
  166. .OP_END_FACTORY_REG(Sigmoid)
  167. /**
  168. * @brief Computes z = (y - y*y)*dy.
  169. * @par Inputs:
  170. * @li y: The input is Tensor, dtype is UnaryDataType.
  171. * @li dy: The input is Tensor, dtype is UnaryDataType.
  172. * @par Outputs:
  173. * z: The shape of output, dtype is UnaryDataType.
  174. */
  175. REG_OP(SigmoidGrad)
  176. .INPUT(y, TensorType(UnaryDataType))
  177. .INPUT(dy, TensorType(UnaryDataType))
  178. .OUTPUT(z, TensorType(UnaryDataType))
  179. .OP_END_FACTORY_REG(SigmoidGrad)
  180. /**
  181. *@brief Computes the binomial normal log likelihood (BNLL) output:\n
  182. *if x>0, x+log(1+exp(-x)); otherwise log(1+exp(x)).
  183. *@par Inputs:
  184. *x: A Tensor of type float16 or float32.
  185. *@par Outputs:
  186. *y: A tensor. Has the same type and format as input "x".
  187. *@par Third-party framework compatibility
  188. * Compatible with the Caffe operator BNLL.
  189. */
  190. REG_OP(BNLL)
  191. .INPUT(x, TensorType::FloatingDataType())
  192. .OUTPUT(y, TensorType::FloatingDataType())
  193. .OP_END_FACTORY_REG(BNLL)
  194. /**
  195. *@brief Computes softplus: log(exp(x) + 1).
  196. *@par Inputs:
  197. * One input:\n
  198. *x: A Tensor of type float16 or float32. Up to 8D.
  199. *@par Outputs:
  200. *y: The activations tensor. Has the same type and format as input "x"
  201. *@par Third-party framework compatibility
  202. * Compatible with the TensorFlow operator Softplus.
  203. */
  204. REG_OP(Softplus)
  205. .INPUT(x, TensorType::FloatingDataType())
  206. .OUTPUT(y, TensorType::FloatingDataType())
  207. .OP_END_FACTORY_REG(Softplus)
  208. /**
  209. *@brief Computes softplus gradients for a softplus operation.
  210. *@par Inputs:
  211. *Two inputs:
  212. * @li gradients: An NC1HWC0 or ND Tensor of type float16 or float32.
  213. * @li features: An NC1HWC0 or ND Tensor of type float16 or float32.
  214. *@par Outputs:
  215. *backprops: A Tensor. Has the same type and format as input "gradients".
  216. *@par Third-party framework compatibility
  217. * Compatible with the TensorFlow operator SoftplusGrad.
  218. */
  219. REG_OP(SoftplusGrad)
  220. .INPUT(gradients, TensorType::FloatingDataType())
  221. .INPUT(features, TensorType::FloatingDataType())
  222. .OUTPUT(backprops, TensorType::FloatingDataType())
  223. .OP_END_FACTORY_REG(SoftplusGrad)
  224. /**
  225. *@brief Computes softsign: x/(abs(x) + 1).
  226. *@par Inputs:
  227. * One input:\n
  228. *x: A Tensor of type float16 or float32. Up to 8D.
  229. *@par Outputs:
  230. *y: The activations tensor. Has the same type and format as "x"
  231. *@par Third-party framework compatibility
  232. * Compatible with the TensorFlow operator Softsign.
  233. */
  234. REG_OP(Softsign)
  235. .INPUT(x, TensorType::FloatingDataType())
  236. .OUTPUT(y, TensorType::FloatingDataType())
  237. .OP_END_FACTORY_REG(Softsign)
  238. /**
  239. *@brief Computes scaled exponential linear: scale * alpha * (exp(x) - 1).
  240. *@par Inputs:
  241. * One input:
  242. *x: A Tensor. Must be one of the following types: float16, float, double
  243. * int32, int8. format:ND, NC1HWC0.
  244. *@par Outputs:
  245. *y: A Tensor. Has the same type and format as input "x". format:ND, NC1HWC0.
  246. *@see Region()
  247. *@par Third-party framework compatibility
  248. * Compatible with the TensorFlow operator Selu.
  249. */
  250. REG_OP(Selu)
  251. .INPUT(x, TensorType({DT_FLOAT16,DT_FLOAT,DT_DOUBLE,
  252. DT_INT8,DT_INT32}))
  253. .OUTPUT(y, TensorType({DT_FLOAT16,DT_FLOAT,DT_DOUBLE,
  254. DT_INT8,DT_INT32}))
  255. .OP_END_FACTORY_REG(Selu)
  256. /**
  257. *@brief Computes rectified linear gradients for a ReLU operation.
  258. *@par Inputs:
  259. * Two inputs, including:
  260. *@li gradients: A Tensor. Must be one of the following types: float32, double,
  261. * int32, int8, int16, int64, uint16, float16, uint32, uint64
  262. *@li features: A Tensor. Must be one of the following types: float32, double,
  263. * int32, int8, int16, int64, uint16, float16, uint32, uint64
  264. *@par Outputs:
  265. *backprops: A Tensor. Must have the same type as"gradients".
  266. *@attention Constraints:
  267. * The corresponding Relu operator needs to be called before using this operator on the network.
  268. *@see Relu
  269. *@par Third-party framework compatibility
  270. * Compatible with TensorFlow operator ReluGrad.
  271. */
  272. REG_OP(ReluGrad)
  273. .INPUT(gradients, TensorType::RealNumberType())
  274. .INPUT(features, TensorType::RealNumberType())
  275. .OUTPUT(backprops, TensorType::RealNumberType())
  276. .OP_END_FACTORY_REG(ReluGrad)
  277. /**
  278. *@brief Computes rectified linear gradients for a ReLU operation.
  279. *@par Inputs:
  280. * Two inputs, including:
  281. *@li gradients: A Tensor. Must be one of the following types: float32, double, int32, int8, int16,\n int8, int64, uint16, float16, uint32, uint64
  282. *@li mask: A Tensor. Must be the following types: uint8
  283. *@par Outputs:
  284. *backprops: A Tensor. Must have the same type as"gradients".
  285. *@attention Constraints:
  286. * The corresponding Relu operator needs to be called before using this operator on the network.
  287. *@see Relu
  288. *@par Third-party framework compatibility
  289. * Compatible with TensorFlow operator ReluGradV2.
  290. */
  291. REG_OP(ReluGradV2)
  292. .INPUT(gradients, TensorType::RealNumberType())
  293. .INPUT(mask, TensorType({DT_UINT8}))
  294. .OUTPUT(backprops, TensorType::RealNumberType())
  295. .OP_END_FACTORY_REG(ReluGradV2)
  296. /**
  297. *@brief Computes rectified linear: "max(x, 0)".
  298. *
  299. *@attention Constraints:\n
  300. * The last dimension must be divisible by 8.
  301. * The second output "mask" is "1" (for y >= 0) or "0" ( for y < 0).
  302. *
  303. *@par Inputs:
  304. * x: A tensor. Must be one of the following types: float32, float64, int32, uint8,
  305. * int16, int8, int64, uint16, float16, qint8.
  306. *
  307. *@par Outputs:
  308. *@li y: A tensor. Has the same type as "x".
  309. *@li mask: A tensor of type uint8.
  310. *
  311. *@par Third-party framework compatibility
  312. * Incompatible with TensorFlow or Caffe.
  313. *
  314. */
  315. REG_OP(ReluV2)
  316. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16, DT_DOUBLE, DT_INT8, DT_INT32, DT_INT16, DT_INT64, DT_UINT8, DT_UINT16, DT_QINT8}))
  317. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_DOUBLE, DT_INT8, DT_INT32, DT_INT16, DT_INT64, DT_UINT8, DT_UINT16, DT_QINT8}))
  318. .OUTPUT(mask, TensorType({DT_UINT8}))
  319. .OP_END_FACTORY_REG(ReluV2)
  320. /**
  321. *@brief Performs parametric ReLU.
  322. *@par Inputs:
  323. * Two inputs, including: \n
  324. *@li x: A multi-dimensional Tensor of type float16 or float32.
  325. *@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.
  326. *@par Outputs:
  327. *y: An activated Tensor. Has the same dimensions with "x".
  328. *@par Third-party framework compatibility
  329. * Compatible with PyTorch and Caffe operator PReLU.
  330. */
  331. REG_OP(PRelu)
  332. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16}))
  333. .INPUT(weight, TensorType({DT_FLOAT, DT_FLOAT16}))
  334. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16}))
  335. .OP_END_FACTORY_REG(PRelu)
  336. /**
  337. *@brief Performs the backpropagation of PRelu for training scenarios.
  338. *@par Inputs:
  339. * Three inputs, including: \n
  340. *@li grads: Input gradient. Multi-dimensional Tensors are supported. The data type can be float16 or float32.
  341. *@li features: A multi-dimensional Tensor of type float16 or float32.
  342. *@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.
  343. *@par Outputs:
  344. *@li dx: Reverse gradient of "features". Has the same dimensions and type as "features".
  345. *@li da: Reverse gradient of "weight". Has the same dimensions and type as "features".
  346. *@par Third-party framework compatibility
  347. * Compatible with PyTorch operator PReluGrad.
  348. */
  349. REG_OP(PReluGrad)
  350. .INPUT(grads, TensorType({DT_FLOAT16, DT_FLOAT}))
  351. .INPUT(features, TensorType({DT_FLOAT16, DT_FLOAT}))
  352. .INPUT(weights, TensorType({DT_FLOAT16, DT_FLOAT}))
  353. .OUTPUT(dx, TensorType({DT_FLOAT16, DT_FLOAT}))
  354. .OUTPUT(da, TensorType({DT_FLOAT16, DT_FLOAT}))
  355. .OP_END_FACTORY_REG(PReluGrad)
  356. /**
  357. *@brief Activation function fused from sigmoid and ReLU, with soft saturation
  358. * on the left and no saturation on the right.
  359. *@par Inputs:
  360. *x: A float16, float32 or double, for the input data type.
  361. *@par Attributes:
  362. *alpha: A float. Defines at which negative value the ELU saturates. Defaults to "1.0".
  363. *@par Outputs:
  364. *y: A float16, float32 or double, for the normalized result.
  365. *@attention Constraints:
  366. *@li The input is of type float16 or float32.
  367. *@par Multiple batches supported or not
  368. *Supported
  369. *@par Third-party framework compatibility
  370. *@li Compatible with Tensorflow's Elu operator
  371. *@li Compatible with Caffe's ELULayer operator
  372. *
  373. *@since V100R001C33
  374. */
  375. REG_OP(Elu)
  376. .INPUT(x, TensorType::FloatingDataType())
  377. .OUTPUT(y, TensorType::FloatingDataType())
  378. .ATTR(alpha, Float, 1.0)
  379. .OP_END_FACTORY_REG(Elu)
  380. /**
  381. *@brief Computes gradients for the exponential linear (Elu) operation.
  382. *
  383. *@par Inputs:
  384. *@li grads: A tensor. Must be one of the following types: float16, float32, float64.
  385. * The backpropagated gradients to the corresponding Elu operation.
  386. *@li activations: A tensor. Has the same type as "grads".
  387. * The outputs of the corresponding Elu operation.
  388. *
  389. *@par Outputs:
  390. * y: A tensor. Has the same type as "grads".
  391. *
  392. *@par Third-party framework compatibility
  393. *Compatible with the TensorFlow operator EluGrad.
  394. *
  395. */
  396. REG_OP(EluGrad)
  397. .INPUT(grads, TensorType::FloatingDataType())
  398. .INPUT(activations, TensorType::FloatingDataType())
  399. .OUTPUT(y, TensorType::FloatingDataType())
  400. .OP_END_FACTORY_REG(EluGrad)
  401. /**
  402. *@brief Computes the output as x if x > 0 and negative_slope * x if x <= 0.
  403. *@par Inputs:
  404. * One input:
  405. * x: A Tensor. Must be one of the following types: float32, float16, double.
  406. *
  407. *@par Attributes:
  408. *negative_slope: A float32. Defaults to "0.0".
  409. *
  410. *@par Outputs:
  411. *y: A Tensor. Has the same type as "x".
  412. *@par Third-party framework compatibility
  413. * Compatible with the Caffe operator ReLU.
  414. */
  415. REG_OP(LeakyRelu)
  416. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16, DT_DOUBLE}))
  417. .ATTR(negative_slope, Float, 0.0)
  418. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_DOUBLE}))
  419. .OP_END_FACTORY_REG(LeakyRelu)
  420. /**
  421. *@brief Computes the output as gradients if features > 0 and negative_slope * gradients if features <= 0.
  422. *@par Inputs:
  423. * Two inputs, including:
  424. * @li gradients: A Tensor. Must be one of the following types: float16, float32, double.
  425. * @li features: A Tensor. Has the same type as "gradients".
  426. *@par Attributes:
  427. *negative_slope: A float32. Defaults to "0.0".
  428. *@par Outputs:
  429. *backprops: A Tensor. Has the same type as "gradients".
  430. *@par Third-party framework compatibility
  431. * Compatible with the TensorFlow operator LeakyReluGrad.
  432. */
  433. REG_OP(LeakyReluGrad)
  434. .INPUT(gradients, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  435. .INPUT(features, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  436. .ATTR(negative_slope, Float, 0.0)
  437. .OUTPUT(backprops, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  438. .OP_END_FACTORY_REG(LeakyReluGrad)
  439. REG_OP(ThresholdGradV2D)
  440. .INPUT(gradients, TensorType({DT_INT32, DT_FLOAT16}))
  441. .INPUT(features, TensorType({DT_INT32, DT_FLOAT16}))
  442. .OUTPUT(backprops, TensorType({DT_INT32, DT_FLOAT16}))
  443. .REQUIRED_ATTR(threshold, Float)
  444. .OP_END_FACTORY_REG(ThresholdGradV2D)
  445. REG_OP(ThresholdV2D)
  446. .INPUT(x, TensorType::RealNumberType())
  447. .OUTPUT(y, TensorType::RealNumberType())
  448. .REQUIRED_ATTR(threshold, Float)
  449. .REQUIRED_ATTR(value, Float)
  450. .OP_END_FACTORY_REG(ThresholdV2D)
  451. } // namespace ge
  452. #endif // GE_OP_NONLINEAR_FUC_OPS_H

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