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.

pad_ops.h 6.2 kB

5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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_PAD_OPS_H
  17. #define GE_OP_PAD_OPS_H
  18. #include "../graph/operator_reg.h"
  19. namespace ge {
  20. /**
  21. *@brief Creates a tensor filled with a scalar value.\n
  22. * This operation creates a tensor of shape "dims" and fills it with "value".
  23. *
  24. *@par Inputs:
  25. *@li dims: A 1D tensor of types int32 or int64. Represents the shape of the output tensor.
  26. *@li value: A 0D scalar. Specifies the value to fill the returned tensor.
  27. *
  28. *@par Outputs:
  29. * y: A tensor. Has the same type as "value".
  30. *
  31. */
  32. REG_OP(Fill)
  33. .INPUT(dims, TensorType::IndexNumberType())
  34. .INPUT(value, TensorType::BasicType())
  35. .OUTPUT(y, TensorType::BasicType())
  36. .OP_END_FACTORY_REG(Fill)
  37. /**
  38. *@brief Creates a tensor filled with a scalar value.\n
  39. * This operation creates a tensor of shape "dims" and fills it with "value".
  40. *
  41. *@par Inputs:
  42. * value: A 0D scalar for the value to fill the returned tensor.
  43. *
  44. *@par Attributes:
  45. * dims: A tensor. Must be one of the following types:"int32"
  46. * 1-D. Represents the shape of the output tensor.
  47. *
  48. *@par Outputs:
  49. * y: A tensor. Has the same type as "value".
  50. *
  51. */
  52. REG_OP(FillD)
  53. .INPUT(value, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16,
  54. DT_UINT16, DT_UINT8, DT_INT32, DT_INT64,
  55. DT_UINT32, DT_UINT64, DT_BOOL, DT_DOUBLE}))
  56. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, DT_UINT16,
  57. DT_UINT8, DT_INT32, DT_INT64, DT_UINT32,
  58. DT_UINT64, DT_BOOL, DT_DOUBLE}))
  59. .REQUIRED_ATTR(dims, ListInt)
  60. .OP_END_FACTORY_REG(FillD)
  61. /**
  62. *@brief Broadcasts an array for a compatible shape.\n
  63. * Broadcasting is the process of making arrays to have compatible shapes
  64. * for arithmetic operations. Two shapes are compatible if for each
  65. * dimension pair they are either equal or one of them is one. When trying
  66. * to broadcast a Tensor to a shape, it starts with the trailing dimensions,
  67. * and works its way forward.
  68. *
  69. *@par Inputs:
  70. *@li x: A tensor.
  71. *@li shape: A tensor of type int32 or int64.
  72. * A 1D tensor of type int32, for the shape of the desired output.
  73. *
  74. *@par Outputs:
  75. * y: A tensor. Has the same type as "x".
  76. */
  77. REG_OP(BroadcastTo)
  78. .INPUT(x, TensorType::BasicType())
  79. .INPUT(shape, TensorType({DT_INT32}))
  80. .OUTPUT(y, TensorType::BasicType())
  81. .OP_END_FACTORY_REG(BroadcastTo)
  82. /**
  83. *@brief Broadcasts an array for a compatible shape.\n
  84. * Broadcasting is the process of making arrays to have compatible shapes
  85. * for arithmetic operations. Two shapes are compatible if for each
  86. * dimension pair they are either equal or one of them is one. When trying
  87. * to broadcast a Tensor to a shape, it starts with the trailing dimensions,
  88. * and works its way forward.
  89. *
  90. *@par Inputs:
  91. * x: A tensor. A tensor to broadcast.
  92. *
  93. *@par Attributes:
  94. * shape: A tensor of type int32.
  95. * A 1D tensor of type int32, for the shape of the desired output.
  96. *
  97. *@par Outputs:
  98. * y: A tensor. Has the same type as "x".
  99. *
  100. */
  101. REG_OP(BroadcastToD)
  102. .INPUT(x, TensorType::BasicType())
  103. .OUTPUT(y, TensorType::BasicType())
  104. .REQUIRED_ATTR(shape, ListInt)
  105. .OP_END_FACTORY_REG(BroadcastToD)
  106. /**
  107. *@brief Pads a tensor.
  108. *@par Inputs:
  109. *Two inputs, including:
  110. * @li x: A Tensor. Must be one of the following types: float16, float32, double, int32,
  111. * uint8, int16, int8, complex64, int64, qint8, quint8, qint32, qint16, quint16, uint16,
  112. * complex128, uint32, uint64.
  113. * @li paddings: A Tensor of type int32 or int64.
  114. *@par Outputs:
  115. *y: A Tensor of the same type as "x".
  116. */
  117. REG_OP(Pad)
  118. .INPUT(x, TensorType::BasicType())
  119. .INPUT(paddings, TensorType::IndexNumberType())
  120. .OUTPUT(y, TensorType::BasicType())
  121. .OP_END_FACTORY_REG(Pad)
  122. /**
  123. *@brief Pads a tensor.
  124. *@par Inputs:
  125. *x: A Tensor. Must be one of the following types: float16, float32, int8, uint8, int32.
  126. *@par Attributes:
  127. *paddings: An optional "vector<vector<int>>". Defaults to "{}".
  128. * For each dimension D of input, paddings[D, 0] indicates how many
  129. * values to add before the contents of tensor in that dimension,
  130. * and paddings[D, 1] indicates how many values to add after the
  131. * contents of tensor in that dimension.
  132. *@par Outputs:
  133. *y: A Tensor of the same type as "x".
  134. */
  135. REG_OP(PadD)
  136. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT8, DT_UINT8, DT_FLOAT}))
  137. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT8, DT_UINT8, DT_FLOAT}))
  138. .ATTR(paddings, ListListInt, {})
  139. .OP_END_FACTORY_REG(PadD)
  140. /**
  141. *@brief Create a diagonal tensor
  142. *@par Inputs:
  143. *Two inputs, including:
  144. * @li x: A mutable Tensor. Must be one of the following types:
  145. * float16, float32, int32.
  146. * @li assist: A mutable Tensor of the same type as "x".
  147. *@par Outputs:
  148. *y: A mutable Tensor. Has the same type as "x".
  149. */
  150. REG_OP(DiagD)
  151. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32}))
  152. .INPUT(assist, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32}))
  153. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32}))
  154. .OP_END_FACTORY_REG(DiagD)
  155. /**
  156. *@brief Create a diagonal tensor
  157. *@par Inputs:
  158. *One input, include:
  159. * x: A mutable Tensor. Must be one of the following types:
  160. * float16, float32, double, int32, int64, complex64, complex128.
  161. *@par Outputs:
  162. *y: A mutable Tensor. Has the same type as "x".
  163. */
  164. REG_OP(Diag)
  165. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT32,
  166. DT_INT64, DT_COMPLEX64, DT_COMPLEX128}))
  167. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT32,
  168. DT_INT64, DT_COMPLEX64, DT_COMPLEX128}))
  169. .OP_END_FACTORY_REG(Diag)
  170. } // namespace ge
  171. #endif //GE_OP_PAD_OPS_H

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