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.

nn_other_ops.h 4.8 kB

5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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_NN_OTHER_OPS_H
  17. #define GE_OP_NN_OTHER_OPS_H
  18. #include "../graph/operator_reg.h"
  19. namespace ge {
  20. REG_OP(Erf)
  21. .INPUT(x, TensorType::FloatingDataType())
  22. .OUTPUT(y, TensorType::FloatingDataType())
  23. .OP_END_FACTORY_REG(Erf)
  24. REG_OP(Erfc)
  25. .INPUT(x, TensorType::FloatingDataType())
  26. .OUTPUT(y, TensorType::FloatingDataType())
  27. .OP_END_FACTORY_REG(Erfc)
  28. /**
  29. *@brief This operation returns a rank 1 histogram counting the number of entries in `values` \n
  30. * that fell into every bin.The bins are equal width and determined by the arguments \n
  31. * 'value_range' and 'nbins'. \n
  32. *@par Inputs:
  33. *Three inputs, including: \n
  34. *@li x: A Tensor of type float32,float16,int32.
  35. *@li range: A Tensor of type float32,float16,int32.
  36. *@li nbins: A Tensor of type int32.
  37. *@par Attributes:
  38. * dtype: An optional attribute. Defaults to "int32".
  39. *@par Outputs:
  40. *y: A Tensor. A Tensor of type int32.
  41. */
  42. REG_OP(HistogramFixedWidth)
  43. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32}))
  44. .INPUT(range, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32}))
  45. .INPUT(nbins, TensorType({DT_INT32}))
  46. .OUTPUT(y, TensorType({DT_INT32}))
  47. .ATTR(dtype, String, "int32")
  48. .OP_END_FACTORY_REG(HistogramFixedWidth)
  49. /**
  50. *@brief This operation returns a rank 1 histogram counting the number of entries in `values` \n
  51. * that fell into every bin.The bins are equal width and determined by the arguments \n
  52. * 'value_range' and 'nbins'. \n
  53. *@par Inputs:
  54. *Two inputs, including: \n
  55. *@li x: A Tensor of type float32,float16,int32.
  56. *@li range: A Tensor of type float32,float16,int32.
  57. *@par Attributes:
  58. *@li dtype: An optional attribute. Defaults to "int32".
  59. *@li nbins: A required attribute,the type is int32.
  60. *@par Outputs:
  61. *y: A Tensor. A Tensor of type int32.
  62. */
  63. REG_OP(HistogramFixedWidthD)
  64. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32}))
  65. .INPUT(range, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32}))
  66. .OUTPUT(y, TensorType({DT_INT32}))
  67. .REQUIRED_ATTR(nbins, Int)
  68. .ATTR(dtype, String, "int32")
  69. .OP_END_FACTORY_REG(HistogramFixedWidthD)
  70. REG_OP(LayerNorm)
  71. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16}))
  72. .INPUT(gamma, TensorType({DT_FLOAT, DT_FLOAT16}))
  73. .INPUT(beta, TensorType({DT_FLOAT, DT_FLOAT16}))
  74. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16}))
  75. .OUTPUT(mean, TensorType({DT_FLOAT, DT_FLOAT16}))
  76. .OUTPUT(variance, TensorType({DT_FLOAT, DT_FLOAT16}))
  77. .ATTR(begin_norm_axis, Int, 0)
  78. .ATTR(begin_params_axis, Int, 0)
  79. .OP_END_FACTORY_REG(LayerNorm)
  80. REG_OP(LayerNormGrad)
  81. .INPUT(dy, TensorType({DT_FLOAT, DT_FLOAT16}))
  82. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16}))
  83. .INPUT(variance, TensorType({DT_FLOAT, DT_FLOAT16}))
  84. .INPUT(mean, TensorType({DT_FLOAT, DT_FLOAT16}))
  85. .INPUT(gamma, TensorType({DT_FLOAT, DT_FLOAT16}))
  86. .OUTPUT(pd_x, TensorType({DT_FLOAT, DT_FLOAT16}))
  87. .OUTPUT(pd_gamma, TensorType({DT_FLOAT, DT_FLOAT16}))
  88. .OUTPUT(pd_beta, TensorType({DT_FLOAT, DT_FLOAT16}))
  89. .OP_END_FACTORY_REG(LayerNormGrad)
  90. REG_OP(LayerNormXBackprop)
  91. .INPUT(dy, TensorType({DT_FLOAT, DT_FLOAT16}))
  92. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16}))
  93. .INPUT(variance, TensorType({DT_FLOAT, DT_FLOAT16}))
  94. .INPUT(mean, TensorType({DT_FLOAT, DT_FLOAT16}))
  95. .INPUT(gamma, TensorType({DT_FLOAT, DT_FLOAT16}))
  96. .OUTPUT(pd_x, TensorType({DT_FLOAT, DT_FLOAT16}))
  97. .OP_END_FACTORY_REG(LayerNormXBackprop)
  98. REG_OP(LayerNormBetaGammaBackprop)
  99. .INPUT(dy, TensorType({DT_FLOAT, DT_FLOAT16}))
  100. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16}))
  101. .INPUT(variance, TensorType({DT_FLOAT, DT_FLOAT16}))
  102. .INPUT(mean, TensorType({DT_FLOAT, DT_FLOAT16}))
  103. .OUTPUT(pd_gamma, TensorType({DT_FLOAT, DT_FLOAT16}))
  104. .OUTPUT(pd_beta, TensorType({DT_FLOAT, DT_FLOAT16}))
  105. .REQUIRED_ATTR(shape_gamma, ListInt)
  106. .OP_END_FACTORY_REG(LayerNormBetaGammaBackprop)
  107. REG_OP(DropOutDoMask)
  108. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16}))
  109. .INPUT(mask, TensorType({DT_UINT8}))
  110. .INPUT(keep_prob, TensorType({DT_FLOAT, DT_FLOAT16}))
  111. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16}))
  112. .OP_END_FACTORY_REG(DropOutDoMask)
  113. } // namespace ge
  114. #endif // GE_OP_NN_OTHER_OPS_H

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