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

5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. REG_OP(Pad)
  107. .INPUT(x, TensorType::BasicType())
  108. .INPUT(paddings, TensorType::IndexNumberType())
  109. .OUTPUT(y, TensorType::BasicType())
  110. .OP_END_FACTORY_REG(Pad)
  111. REG_OP(PadD)
  112. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT8, DT_UINT8, DT_FLOAT}))
  113. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT8, DT_UINT8, DT_FLOAT}))
  114. .ATTR(paddings, ListListInt, {})
  115. .OP_END_FACTORY_REG(PadD)
  116. /**
  117. *@brief Create a diagonal tensor
  118. *@par Inputs:
  119. *Two inputs, including:
  120. * @li x: A mutable Tensor. Must be one of the following types:
  121. * float16, float32, int32.
  122. * @li assist: A mutable Tensor of the same type as "x".
  123. *@par Outputs:
  124. *y: A mutable Tensor. Has the same type as "x".
  125. */
  126. REG_OP(DiagD)
  127. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32}))
  128. .INPUT(assist, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32}))
  129. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32}))
  130. .OP_END_FACTORY_REG(DiagD)
  131. /**
  132. *@brief Create a diagonal tensor
  133. *@par Inputs:
  134. *One input, include:
  135. * x: A mutable Tensor. Must be one of the following types:
  136. * float16, float32, double, int32, int64, complex64, complex128.
  137. *@par Outputs:
  138. *y: A mutable Tensor. Has the same type as "x".
  139. */
  140. REG_OP(Diag)
  141. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT32,
  142. DT_INT64, DT_COMPLEX64, DT_COMPLEX128}))
  143. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT32,
  144. DT_INT64, DT_COMPLEX64, DT_COMPLEX128}))
  145. .OP_END_FACTORY_REG(Diag)
  146. } // namespace ge
  147. #endif //GE_OP_PAD_OPS_H

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

Contributors (1)