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.

set_ops.h 7.0 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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_SET_OPS_H_
  17. #define GE_OP_SET_OPS_H_
  18. #include "graph/operator.h"
  19. #include "graph/operator_reg.h"
  20. namespace ge {
  21. /**
  22. *@brief Applies set operation along last dimension of 2 Tensor inputs.
  23. *@par Inputs:
  24. *Inputs include: \n
  25. * @li x1: A Tensor. Must be one of the following types: int8, int16, int32, int64, uint8, uint16, string.
  26. * @li x2: A Tensor. Must have the same type as x1.
  27. *@par Attributes:
  28. *@li set_operation: A string.
  29. *@li validate_indices: An optional bool. Defaults to True.
  30. *@par Outputs:
  31. *@li y_indices: A Tensor of type int64.
  32. *@li y_values: A Tensor. Has the same type as x1.
  33. *@li y_shape: A Tensor of type int64.
  34. *@attention Constraints:\n
  35. *-The implementation for DenseToDenseSetOperation on Ascend uses AICPU, with bad performance.\n
  36. *@par Third-party framework compatibility
  37. *@li compatible with tensorflow DenseToDenseSetOperation operator.
  38. */
  39. REG_OP(DenseToDenseSetOperation)
  40. .INPUT(x1, TensorType({DT_INT8, DT_INT16, DT_UINT16, DT_UINT8, \
  41. DT_INT32, DT_INT64, DT_STRING}))
  42. .INPUT(x2, TensorType({DT_INT8, DT_INT16, DT_UINT16, DT_UINT8, \
  43. DT_INT32, DT_INT64, DT_STRING}))
  44. .OUTPUT(y_indices, TensorType({DT_INT64}))
  45. .OUTPUT(y_values, TensorType({DT_INT8, DT_INT16, DT_UINT16, DT_UINT8, \
  46. DT_INT32, DT_INT64, DT_STRING}))
  47. .OUTPUT(y_shape, TensorType({DT_INT64}))
  48. .ATTR(set_operation, String, "")
  49. .ATTR(validate_indices, Bool, true)
  50. .OP_END_FACTORY_REG(DenseToDenseSetOperation)
  51. /**
  52. *@brief Applies set operation along last dimension of Tensor and SparseTensor.
  53. *@par Inputs:
  54. *Inputs include: \n
  55. * @li x1: A Tensor. Must be one of the following types: int8, int16, int32, int64, uint8, uint16, string.
  56. * @li x2_indices: A Tensor of type int64. 2D Tensor, indices of a SparseTensor.
  57. * @li x2_values: A Tensor. Must have the same type as set1. 1D Tensor, values of a SparseTensor.
  58. * @li x2_shape: A Tensor of type int64. 1D Tensor, shape of a SparseTensor.
  59. *@par Attributes:
  60. *@li set_operation: A string.
  61. *@li validate_indices: An optional bool. Defaults to True.
  62. *@par Outputs:
  63. *@li y_indices: A Tensor of type int64.
  64. *@li y_values: A Tensor. Has the same type as x1.
  65. *@li y_shape: A Tensor of type int64.
  66. *@attention Constraints:\n
  67. *-The implementation for DenseToSparseSetOperation on Ascend uses AICPU, with bad performance.\n
  68. *@par Third-party framework compatibility
  69. *@li compatible with tensorflow DenseToSparseSetOperation operator.
  70. */
  71. REG_OP(DenseToSparseSetOperation)
  72. .INPUT(x1, TensorType({DT_INT8, DT_INT16, DT_UINT16, DT_UINT8, \
  73. DT_INT32, DT_INT64, DT_STRING}))
  74. .INPUT(x2_indices, TensorType({DT_INT64}))
  75. .INPUT(x2_values, TensorType({DT_INT8, DT_INT16, DT_UINT16, DT_UINT8, \
  76. DT_INT32, DT_INT64, DT_STRING}))
  77. .INPUT(x2_shape, TensorType({DT_INT64}))
  78. .OUTPUT(y_indices, TensorType({DT_INT64}))
  79. .OUTPUT(y_values, TensorType({DT_INT8, DT_INT16, DT_UINT16, DT_UINT8, \
  80. DT_INT32, DT_INT64, DT_STRING}))
  81. .OUTPUT(y_shape, TensorType({DT_INT64}))
  82. .ATTR(set_operation, String, "")
  83. .ATTR(validate_indices, Bool, true)
  84. .OP_END_FACTORY_REG(DenseToSparseSetOperation)
  85. /**
  86. *@brief Applies set operation along last dimension of 2 SparseTensor inputs.
  87. *@par Inputs:
  88. *Inputs include: \n
  89. * @li x1_indices: A Tensor of type int64. 2D Tensor, indices of a SparseTensor.
  90. * @li x1_values: A Tensor. Must be one of the following types: int8, int16, \n
  91. int32, int64, uint8, uint16, string. 1D Tensor, values of a SparseTensor.
  92. * @li x1_shape: A Tensor of type int64. 1D Tensor, shape of a SparseTensor.
  93. * @li x2_indices: A Tensor of type int64. 2D Tensor, indices of a SparseTensor.
  94. * @li x2_values: A Tensor. Must have the same type as set1_values. 1D Tensor, values of a SparseTensor.
  95. * @li x2_shape: A Tensor of type int64. 1D Tensor, shape of a SparseTensor.
  96. *@par Attributes:
  97. *@li set_operation: A string.
  98. *@li validate_indices: An optional bool. Defaults to True.
  99. *@par Outputs:
  100. *@li y_indices: A Tensor of type int64.
  101. *@li y_values: A Tensor. Has the same type as x1_values.
  102. *@li y_shape: A Tensor of type int64.
  103. *@attention Constraints:\n
  104. *-The implementation for SparseToSparseSetOperation on Ascend uses AICPU, with bad performance.\n
  105. *@par Third-party framework compatibility
  106. *@li compatible with tensorflow SparseToSparseSetOperation operator.
  107. */
  108. REG_OP(SparseToSparseSetOperation)
  109. .INPUT(x1_indices, TensorType({DT_INT64}))
  110. .INPUT(x1_values, TensorType({DT_INT8, DT_INT16, DT_UINT16, DT_UINT8, \
  111. DT_INT32, DT_INT64, DT_STRING}))
  112. .INPUT(x1_shape, TensorType({DT_INT64}))
  113. .INPUT(x2_indices, TensorType({DT_INT64}))
  114. .INPUT(x2_values, TensorType({DT_INT8, DT_INT16, DT_UINT16, DT_UINT8, \
  115. DT_INT32, DT_INT64, DT_STRING}))
  116. .INPUT(x2_shape, TensorType({DT_INT64}))
  117. .OUTPUT(y_indices, TensorType({DT_INT64}))
  118. .OUTPUT(y_values, TensorType({DT_INT8, DT_INT16, DT_UINT16, DT_UINT8, \
  119. DT_INT32, DT_INT64, DT_STRING}))
  120. .OUTPUT(y_shape, TensorType({DT_INT64}))
  121. .ATTR(set_operation, String, "")
  122. .ATTR(validate_indices, Bool, true)
  123. .OP_END_FACTORY_REG(SparseToSparseSetOperation)
  124. /**
  125. *@brief Number of unique elements along last dimension of input set.
  126. *@par Inputs:
  127. *Inputs include: \n
  128. * @li set_indices: A Tensor of type int64. 2D Tensor, indices of a SparseTensor.
  129. * @li set_values: A Tensor. Must be one of the following types: int8, int16, int32, int64, uint8, uint16.
  130. * @li set_shape: A Tensor of type int64. 1D Tensor, shape of a SparseTensor.
  131. *@par Attributes:
  132. *validate_indices: An optional bool. Defaults to True.
  133. *@par Outputs:
  134. *size: A Tensor of type int32.
  135. *@attention Constraints:\n
  136. *-The implementation for SetSize on Ascend uses AICPU, with bad performance.\n
  137. *@par Third-party framework compatibility
  138. *@li compatible with tensorflow SetSize operator.
  139. */
  140. REG_OP(SetSize)
  141. .INPUT(set_indices, TensorType({DT_INT64}))
  142. .INPUT(set_values, TensorType({DT_INT8, DT_INT16, \
  143. DT_UINT8, DT_UINT16, DT_INT32, DT_INT64, DT_STRING}))
  144. .INPUT(set_shape, TensorType({DT_INT64}))
  145. .OUTPUT(size, TensorType({DT_INT32}))
  146. .ATTR(validate_indices, Bool, true)
  147. .OP_END_FACTORY_REG(SetSize)
  148. } // namespace ge
  149. #endif // GE_OP_SET_OPS_H_

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