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_ops.h 7.8 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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_OPS_H_
  17. #define GE_OP_NN_OPS_H_
  18. #include "graph/operator_reg.h"
  19. #include "graph/operator.h"
  20. namespace ge {
  21. /**
  22. *@brief Computes gradient of the FractionalMaxPool function.
  23. *@par Inputs:
  24. *Inputs include: \n
  25. * @li orig_input: A Tensor. Must be one of the following types: float32, float64, int32, int64.
  26. * @li orig_output: A Tensor. Must have the same type as orig_input.
  27. * @li out_backprop: A Tensor. Must have the same type as orig_input. \n
  28. 4-D with shape [batch, height, width, channels].
  29. * @li row_pooling_sequence: A Tensor of type int64.
  30. * @li col_pooling_sequence: A Tensor of type int64.
  31. *@par Attributes:
  32. *overlapping: An optional bool. Defaults to False.
  33. *@par Outputs:
  34. *y: A Tensor. Has the same type as orig_input.
  35. *@attention Constraints:\n
  36. *-The implementation for FractionalMaxPoolGrad on Ascend uses AICPU, with bad performance.\n
  37. */
  38. REG_OP(FractionalMaxPoolGrad)
  39. .INPUT(orig_input, TensorType({DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64}))
  40. .INPUT(orig_output, TensorType({DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64}))
  41. .INPUT(out_backprop, TensorType({DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64}))
  42. .INPUT(row_pooling_sequence, TensorType({ DT_INT64 }))
  43. .INPUT(col_pooling_sequence, TensorType({ DT_INT64 }))
  44. .OUTPUT(y, TensorType({ DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64 }))
  45. .ATTR(overlapping, Bool, false)
  46. .OP_END_FACTORY_REG(FractionalMaxPoolGrad)
  47. /**
  48. *@brief Performs fractional average pooling on the input.
  49. *@par Inputs:
  50. *Inputs include: \n
  51. *x: A Tensor. Must be one of the following types: float32, float64, int32, int64. \n
  52. 4-D with shape [batch, height, width, channels].
  53. *@par Attributes:
  54. *@li pooling_ratio: A list of floats that has length >= 4.
  55. *@li pseudo_random: An optional bool. Defaults to False.
  56. *@li overlapping: An optional bool. Defaults to False. When set to True, it means when pooling.
  57. *@li deterministic: An optional bool. Defaults to False.
  58. *@li seed: An optional int. Defaults to 0.
  59. *@li seed2: An optional int. Defaults to 0.
  60. *@par Outputs:
  61. *@li y: A Tensor. Has the same type as x.
  62. *@li row_pooling_sequence: A Tensor of type int64.
  63. *@li col_pooling_sequence: A Tensor of type int64.
  64. *@attention Constraints:\n
  65. *-The implementation for FractionalAvgPool on Ascend uses AICPU, with bad performance.\n
  66. */
  67. REG_OP(FractionalAvgPool)
  68. .INPUT(x, TensorType({DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64}))
  69. .OUTPUT(y, TensorType({DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64}))
  70. .OUTPUT(row_pooling_sequence, TensorType({DT_INT64}))
  71. .OUTPUT(col_pooling_sequence, TensorType({DT_INT64}))
  72. .ATTR(pooling_ratio, ListFloat, {})
  73. .ATTR(pseudo_random, Bool, false)
  74. .ATTR(overlapping, Bool, false)
  75. .ATTR(deterministic, Bool, false)
  76. .ATTR(seed, Int, 0)
  77. .ATTR(seed2, Int, 0)
  78. .OP_END_FACTORY_REG(FractionalAvgPool)
  79. /**
  80. *@brief Performs fractional max pooling on the input.
  81. *@par Inputs:
  82. *Inputs include: \n
  83. *x: A Tensor. Must be one of the following types: float32, float64, int32, int64. \n
  84. 4-D with shape [batch, height, width, channels].
  85. *@par Attributes:
  86. *@li pooling_ratio: A list of floats that has length >= 4. Pooling ratio for each dimension of value.
  87. *@li pseudo_random: An optional bool. Defaults to False.
  88. *@li overlapping: An optional bool. Defaults to False.
  89. *@li deterministic: An optional bool. Defaults to False.
  90. *@li seed: An optional int. Defaults to 0.
  91. *@li seed2: An optional int. Defaults to 0.
  92. *@par Outputs:
  93. *@li y: A Tensor. Has the same type as x.
  94. *@li row_pooling_sequence: A Tensor of type int64.
  95. *@li col_pooling_sequence: A Tensor of type int64.
  96. *@attention Constraints:\n
  97. *-The implementation for FractionalMaxPool on Ascend uses AICPU, with bad performance.\n
  98. */
  99. REG_OP(FractionalMaxPool)
  100. .INPUT(x, TensorType({DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64}))
  101. .OUTPUT(y, TensorType({DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64}))
  102. .OUTPUT(row_pooling_sequence, TensorType({DT_INT64}))
  103. .OUTPUT(col_pooling_sequence, TensorType({DT_INT64}))
  104. .ATTR(pooling_ratio, ListFloat, {})
  105. .ATTR(pseudo_random, Bool, false)
  106. .ATTR(overlapping, Bool, false)
  107. .ATTR(deterministic, Bool, false)
  108. .ATTR(seed, Int, 0)
  109. .ATTR(seed2, Int, 0)
  110. .OP_END_FACTORY_REG(FractionalMaxPool)
  111. /**
  112. *@brief Finds values of the n-th order statistic for the last dimension.
  113. *@par Inputs:
  114. *Inputs include: \n
  115. * @li x: A Tensor. Must be one of the following types: float32, float64, int32, uint8, \n
  116. int16, int8, int64, bfloat16, uint16, half, uint32, uint64.
  117. * @li n: A Tensor of type int32. 0-D.
  118. *@par Attributes:
  119. *reverse: An optional bool. Defaults to False.
  120. *@par Outputs:
  121. *y: A Tensor. Has the same type as x.
  122. *@attention Constraints:\n
  123. *-The implementation for NthElement on Ascend uses AICPU, with bad performance.\n
  124. */
  125. REG_OP(NthElement)
  126. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16,
  127. DT_UINT16, DT_UINT8, DT_INT32, DT_INT64, DT_DOUBLE}))
  128. .INPUT(n, TensorType({DT_INT32}))
  129. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16,
  130. DT_UINT16, DT_UINT8, DT_INT32, DT_INT64, DT_DOUBLE}))
  131. .ATTR(reverse, Bool, false)
  132. .OP_END_FACTORY_REG(NthElement)
  133. /**
  134. *@brief Computes gradient of the FractionalAvgPool function.
  135. *@par Inputs:
  136. *Inputs include: \n
  137. * @li orig_input_tensor_shape: A Tensor of type int64.
  138. * @li out_backprop: A Tensor. Must be one of the following types: float32, float64, \n
  139. int32, int64. 4-D with shape [batch, height, width, channels].
  140. * @li row_pooling_sequence: A Tensor of type int64.
  141. * @li col_pooling_sequence: A Tensor of type int64.
  142. *@par Attributes:
  143. *overlapping: An optional bool. Defaults to False.
  144. *@par Outputs:
  145. *y: A Tensor. Has the same type as out_backprop.
  146. *@attention Constraints:\n
  147. *-The implementation for FractionalAvgPoolGrad on Ascend uses AICPU, with bad performance.\n
  148. */
  149. REG_OP(FractionalAvgPoolGrad)
  150. .INPUT(orig_input_tensor_shape, TensorType({DT_INT64}))
  151. .INPUT(out_backprop, TensorType({DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64}))
  152. .INPUT(row_pooling_sequence, TensorType({DT_INT64}))
  153. .INPUT(col_pooling_sequence, TensorType({DT_INT64}))
  154. .OUTPUT(y, TensorType({DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64}))
  155. .ATTR(overlapping, Bool, false)
  156. .OP_END_FACTORY_REG(FractionalAvgPoolGrad)
  157. /**
  158. *@brief Returns the permuted vector/tensor in the destination data format given the.
  159. *@par Inputs:
  160. *Inputs include: \n
  161. *x: A Tensor. Must be one of the following types: int32, int64. Vector of size 4 \n
  162. or Tensor of shape (4, 2) in source data format.
  163. *@par Attributes:
  164. *@li src_format: An optional string. Defaults to "NHWC". source data format.
  165. *@li dst_format: An optional string. Defaults to "NCHW". destination data format.
  166. *@par Outputs:
  167. *y: A Tensor. Has the same type as x.
  168. *@attention Constraints:\n
  169. *-The implementation for DataFormatVecPermute on Ascend uses AICPU, with bad performance.\n
  170. */
  171. REG_OP(DataFormatVecPermute)
  172. .INPUT(x, TensorType({ DT_INT32, DT_INT64 }))
  173. .OUTPUT(y, TensorType({ DT_INT32, DT_INT64 }))
  174. .ATTR(src_format, String, "NHWC")
  175. .ATTR(dst_format, String, "NCHW")
  176. .OP_END_FACTORY_REG(DataFormatVecPermute)
  177. } // namespace ge
  178. #endif // GE_OP_NN_OPS_H_

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