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

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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. /*!
  17. * \file pad_ops.h
  18. * \brief
  19. */
  20. #ifndef GE_OP_PAD_OPS_H
  21. #define GE_OP_PAD_OPS_H
  22. #include "graph/operator_reg.h"
  23. namespace ge {
  24. /**
  25. *@brief Creates a tensor filled with a scalar value.
  26. * This operation creates a tensor of shape "dims" and fills it with "value".
  27. *
  28. *@par Inputs:
  29. *@li dims: A 1D tensor of types int32 or int64. Represents the shape of the output tensor . \n
  30. *@li value: A 0D scalar. Specifies the value to fill the returned tensor.
  31. * Must be one of the following types:
  32. * float16, float32, double, int32, uint8, int16, int8, complex64, int64,
  33. * qint8, quint8, qint32, uint16, complex128, uint32, uint64.
  34. *
  35. *@par Outputs:
  36. * y: A tensor. Has the same type as "value".
  37. *
  38. *@par Third-party framework compatibility
  39. *@li Compatible with the TensorFlow operator Fill.
  40. *@li Compatible with the Caffe operator Filler.
  41. *
  42. */
  43. REG_OP(Fill)
  44. .INPUT(dims, TensorType::IndexNumberType())
  45. .INPUT(value, TensorType::BasicType())
  46. .OUTPUT(y, TensorType::BasicType())
  47. .OP_END_FACTORY_REG(Fill)
  48. /**
  49. *@brief Creates a tensor filled with a scalar value.
  50. * This operation creates a tensor of shape "dims" and fills it with "value".
  51. *
  52. *@par Inputs:
  53. * value: A 0D scalar for the value to fill the returned tensor. Must be one of
  54. * the following types:
  55. * float16, float32, uint8, int8, int16, int32, int64, quint8, qint8, qint32
  56. *
  57. *@par Attributes:
  58. * dims: A tensor. Must be one of the following types:"int32"
  59. * 1-D. Represents the shape of the output tensor.
  60. *
  61. *@par Outputs:
  62. * y: A tensor. Has the same type as "value".
  63. */
  64. REG_OP(FillD)
  65. .INPUT(value, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16,
  66. DT_UINT16, DT_UINT8, DT_INT32, DT_INT64,
  67. DT_UINT32, DT_UINT64, DT_BOOL, DT_DOUBLE}))
  68. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, DT_UINT16,
  69. DT_UINT8, DT_INT32, DT_INT64, DT_UINT32,
  70. DT_UINT64, DT_BOOL, DT_DOUBLE}))
  71. .REQUIRED_ATTR(dims, ListInt)
  72. .OP_END_FACTORY_REG(FillD)
  73. /**
  74. *@brief Broadcasts an array for a compatible shape.
  75. * Broadcasting is the process of making arrays to have compatible shapes
  76. * for arithmetic operations. Two shapes are compatible if for each
  77. * dimension pair they are either equal or one of them is one. When trying
  78. * to broadcast a Tensor to a shape, it starts with the trailing dimensions,
  79. * and works its way forward.
  80. *
  81. *@par Inputs:
  82. *@li x: A tensor.
  83. *@li shape: A tensor of type int32.
  84. * A 1D tensor of type int32, for the shape of the desired output.
  85. *
  86. *@par Outputs:
  87. * y: A tensor. Has the same type as "x".
  88. *
  89. *@par Third-party framework compatibility
  90. *Compatible with the TensorFlow operator BroadcastTo.
  91. *
  92. */
  93. REG_OP(BroadcastTo)
  94. .INPUT(x, TensorType::BasicType())
  95. .INPUT(shape, TensorType({DT_INT32}))
  96. .OUTPUT(y, TensorType::BasicType())
  97. .OP_END_FACTORY_REG(BroadcastTo)
  98. /**
  99. *@brief Broadcasts an array for a compatible shape.
  100. * Broadcasting is the process of making arrays to have compatible shapes
  101. * for arithmetic operations. Two shapes are compatible if for each
  102. * dimension pair they are either equal or one of them is one. When trying
  103. * to broadcast a Tensor to a shape, it starts with the trailing dimensions,
  104. * and works its way forward.
  105. *
  106. *@par Inputs:
  107. * x: A tensor. A tensor to broadcast.
  108. *
  109. *@par Attributes:
  110. * shape: A tensor of type int32.
  111. * A 1D tensor of type int32, for the shape of the desired output.
  112. *
  113. *@par Outputs:
  114. * y: A tensor. Has the same type as "x".
  115. *
  116. *@par Third-party framework compatibility
  117. *Compatible with the TensorFlow operator BroadcastTo.
  118. */
  119. REG_OP(BroadcastToD)
  120. .INPUT(x, TensorType::BasicType())
  121. .OUTPUT(y, TensorType::BasicType())
  122. .REQUIRED_ATTR(shape, ListInt)
  123. .OP_END_FACTORY_REG(BroadcastToD)
  124. /**
  125. *@brief Pads a tensor . \n
  126. *@par Inputs:
  127. *Two inputs, including:
  128. * @li x: A Tensor. Must be one of the following types: float16, float32, double, int32,
  129. * uint8, int16, int8, complex64, int64, qint8, quint8, qint32, qint16, quint16, uint16,
  130. * complex128, uint32, uint64.
  131. * @li paddings: A Tensor of type int32 or int64 . \n
  132. *@par Outputs:
  133. *y: A Tensor of the same type as "x" . \n
  134. *@par Third-party framework compatibility:
  135. * Compatible with TensorFlow operator Pad.
  136. */
  137. REG_OP(Pad)
  138. .INPUT(x, TensorType::BasicType())
  139. .INPUT(paddings, TensorType::IndexNumberType())
  140. .OUTPUT(y, TensorType::BasicType())
  141. .OP_END_FACTORY_REG(Pad)
  142. /**
  143. *@brief Pads a tensor . \n
  144. *@par Inputs:
  145. *x: A Tensor. Must be one of the following types: float16, float32, int8, uint8, int32 . \n
  146. *@par Attributes:
  147. *paddings: An optional "vector<vector<int>>". Defaults to "{}".
  148. * For each dimension D of input, paddings[D, 0] indicates how many
  149. * values to add before the contents of tensor in that dimension,
  150. * and paddings[D, 1] indicates how many values to add after the
  151. * contents of tensor in that dimension . \n
  152. *@par Outputs:
  153. *y: A Tensor of the same type as "x" . \n
  154. *@par Third-party framework compatibility:
  155. * Compatible with TensorFlow operator Pad.
  156. */
  157. REG_OP(PadD)
  158. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT8, DT_UINT8, DT_FLOAT}))
  159. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT8, DT_UINT8, DT_FLOAT}))
  160. .REQUIRED_ATTR(paddings, ListListInt)
  161. .OP_END_FACTORY_REG(PadD)
  162. /**
  163. *@brief Pads a tensor.
  164. *@par Inputs:
  165. *Two inputs, including:
  166. * @li x: A Tensor. Must be one of the following types: float16, float32, double, int32,
  167. * uint8, int16, int8, complex64, int64, qint8, quint8, qint32, qint16, quint16, uint16,
  168. * complex128, uint32, uint64.
  169. * @li paddings: A Tensor of type int32 or int64.
  170. * @li constant_values: A optional Tensor of int32 or int64
  171. *@par Attributes:
  172. * @li mode: An optional string, Defaults to "constant", indicates paddings mode,
  173. * support "constant", "reflect", "edge"
  174. * @li paddings_contiguous: An optional bool value, Defaults to true.
  175. * If true, paddings is arranged as [[begin0, end0], [begin1, end1], ...]
  176. * If false, paddings is arranged as [[begin0, begin1], ..., [end0, end1], ...]
  177. *@par Outputs:
  178. *y: A Tensor of the same type as "x".
  179. *@par Third-party framework compatibility:
  180. * Compatible with ONNX operator Pad.
  181. */
  182. REG_OP(PadV3)
  183. .INPUT(x, TensorType::BasicType())
  184. .INPUT(paddings, TensorType::IndexNumberType())
  185. .OPTIONAL_INPUT(constant_values, TensorType::BasicType())
  186. .OUTPUT(y, TensorType::BasicType())
  187. .ATTR(mode, String, "constant")
  188. .ATTR(paddings_contiguous, Bool, true)
  189. .OP_END_FACTORY_REG(PadV3)
  190. /**
  191. *@brief Pads a tensor.
  192. *@par Inputs:
  193. *x: A Tensor. Must be one of the following types: float16, float32, int8, uint8, int32.
  194. *@par Attributes:
  195. * @li paddings: An required "vector<vector<int>>".
  196. * For each dimension D of input, paddings[D, 0] indicates how many
  197. * values to add before the contents of tensor in that dimension,
  198. * and paddings[D, 1] indicates how many values to add after the
  199. * contents of tensor in that dimension.
  200. * @li constant_values: An optional int value for pad.
  201. * @li mode: An optional string, Defaults to "constant", indicates paddings mode,
  202. * support "constant", "reflect", "edge"
  203. * @li paddings_contiguous: An optional bool value, Defaults to true.
  204. * If true, paddings is arranged as [[begin0, end0], [begin1, end1], ...]
  205. * If false, paddings is arranged as [[begin0, begin1], ..., [end0, end1], ...]
  206. *@par Outputs:
  207. *y: A Tensor of the same type as "x".
  208. *@par Third-party framework compatibility:
  209. * Compatible with ONNX operator Pad.
  210. * @par Restrictions:
  211. * Warning: THIS FUNCTION IS DEPRECATED. Please use PadV3 instead.
  212. */
  213. REG_OP(PadV3D)
  214. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT8, DT_UINT8}))
  215. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT8, DT_UINT8}))
  216. .REQUIRED_ATTR(paddings, ListListInt)
  217. .ATTR(constant_values, Int, 0)
  218. .ATTR(mode, String, "constant")
  219. .ATTR(paddings_contiguous, Bool, true)
  220. .OP_END_FACTORY_REG(PadV3D)
  221. /**
  222. *@brief Create a diagonal tensor
  223. *@par Inputs:
  224. *Two inputs, including:
  225. * @li x: A mutable Tensor. Must be one of the following types:
  226. * float16, float32, int32 . \n
  227. * @li assist: A mutable Tensor with rank k is at most 1,
  228. * Has the same type as "x" . \n
  229. *@par Outputs:
  230. *y: A mutable Tensor. Has the same type as "x" . \n
  231. *@see Diag()
  232. *@par Third-party framework compatibility
  233. * Compatible with the TensorFlow operator Diag.
  234. */
  235. REG_OP(DiagD)
  236. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32}))
  237. .INPUT(assist, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32}))
  238. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32}))
  239. .OP_END_FACTORY_REG(DiagD)
  240. /**
  241. *@brief Create a diagonal tensor
  242. *@par Inputs:
  243. *One input, include:
  244. * x: A mutable Tensor with rank k, where k is at most 1. Must be one of the
  245. * following types:
  246. * float16, float32, double, int32, int64, complex64, complex128 . \n
  247. *@par Outputs:
  248. *y: A mutable Tensor. Has the same type as "x" . \n
  249. *@see DiagD()
  250. *@par Third-party framework compatibility
  251. * Compatible with the TensorFlow operator Diag.
  252. */
  253. REG_OP(Diag)
  254. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT32,
  255. DT_INT64, DT_COMPLEX64, DT_COMPLEX128}))
  256. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT32,
  257. DT_INT64, DT_COMPLEX64, DT_COMPLEX128}))
  258. .OP_END_FACTORY_REG(Diag)
  259. /**
  260. *@brief Ascend Padding, pad the last dimension of input
  261. *@par Inputs:
  262. *One input, include:
  263. *x: Tensor which last dimension must be 1. For example: [624000, 1] . \n
  264. *@par Outputs:
  265. *y: Padding the last dimension of x to padDimSize, [624000, padDimSize] . \n
  266. *@par Third-party framework compatibility
  267. * Compatible with the TensorFlow operator Diag.
  268. */
  269. REG_OP(AscendPadding)
  270. .INPUT(x, TensorType::BasicType())
  271. .OUTPUT(y, TensorType::BasicType())
  272. .ATTR(pad_dim_size, Int, 8)
  273. .OP_END_FACTORY_REG(AscendPadding)
  274. /**
  275. *@brief EmbeddingRankId, traverse the index calculation server and its position in the server . \n
  276. *@par Restrictions:
  277. *Warning:THIS FUNCTION IS DEPRECATED. Please do not use. \n
  278. *@par Inputs:
  279. *One input, include:
  280. *addr_table: Tensor which last dimension must be 3. For example: [8, 3].
  281. *index: Tensor For example: [640000].
  282. *@par Outputs:
  283. *rank_id: Tensor the first dimension of index to Size, [size, 3].
  284. Tensor which last dimension must be 3.For example: [640000, 3]
  285. *@par Third-party framework compatibility
  286. * Compatible with the TensorFlow operator Diag.
  287. */
  288. REG_OP(EmbeddingRankId)
  289. .INPUT(addr_table, TensorType({DT_UINT64}))
  290. .INPUT(index, TensorType({DT_UINT32}))
  291. .OUTPUT(rank_id, TensorType({DT_UINT64}))
  292. .ATTR(row_memory, Int, 320)
  293. .ATTR(mode, String, "mod")
  294. .OP_END_FACTORY_REG(EmbeddingRankId)
  295. } // namespace ge
  296. #endif //GE_OP_PAD_OPS_H

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