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

5 years ago
4 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
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. /**
  2. * Copyright 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 OPS_BUILT_IN_OP_PROTO_INC_PAD_OPS_H_
  21. #define OPS_BUILT_IN_OP_PROTO_INC_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. * @par Restrictions:
  65. * Warning: THIS FUNCTION IS DEPRECATED. Please use Fill instead.
  66. */
  67. REG_OP(FillD)
  68. .INPUT(value, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16,
  69. DT_UINT16, DT_UINT8, DT_INT32, DT_INT64,
  70. DT_UINT32, DT_UINT64, DT_BOOL, DT_DOUBLE}))
  71. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, DT_UINT16,
  72. DT_UINT8, DT_INT32, DT_INT64, DT_UINT32,
  73. DT_UINT64, DT_BOOL, DT_DOUBLE}))
  74. .REQUIRED_ATTR(dims, ListInt)
  75. .OP_END_FACTORY_REG(FillD)
  76. /**
  77. *@brief Broadcasts an array for a compatible shape.
  78. * Broadcasting is the process of making arrays to have compatible shapes
  79. * for arithmetic operations. Two shapes are compatible if for each
  80. * dimension pair they are either equal or one of them is one. When trying
  81. * to broadcast a Tensor to a shape, it starts with the trailing dimensions,
  82. * and works its way forward.
  83. *
  84. *@par Inputs:
  85. *@li x: A tensor.
  86. *@li shape: A tensor of type int32.
  87. * A 1D tensor of type int32, for the shape of the desired output.
  88. *
  89. *@par Outputs:
  90. * y: A tensor. Has the same type as "x".
  91. *
  92. *@par Third-party framework compatibility
  93. *Compatible with the TensorFlow operator BroadcastTo.
  94. *
  95. */
  96. REG_OP(BroadcastTo)
  97. .INPUT(x, TensorType::BasicType())
  98. .INPUT(shape, TensorType({DT_INT32,DT_INT64}))
  99. .OUTPUT(y, TensorType::BasicType())
  100. .OP_END_FACTORY_REG(BroadcastTo)
  101. /**
  102. *@brief Broadcasts an array for a compatible shape.
  103. * Broadcasting is the process of making arrays to have compatible shapes
  104. * for arithmetic operations. Two shapes are compatible if for each
  105. * dimension pair they are either equal or one of them is one. When trying
  106. * to broadcast a Tensor to a shape, it starts with the trailing dimensions,
  107. * and works its way forward.
  108. *
  109. *@par Inputs:
  110. * x: A tensor. A tensor to broadcast.
  111. *
  112. *@par Attributes:
  113. * shape: A tensor of type int32.
  114. * A 1D tensor of type int32, for the shape of the desired output.
  115. *
  116. *@par Outputs:
  117. * y: A tensor. Has the same type as "x".
  118. *
  119. *@par Third-party framework compatibility
  120. *Compatible with the TensorFlow operator BroadcastTo.
  121. *
  122. * @par Restrictions:
  123. * Warning: THIS FUNCTION IS DEPRECATED. Please use BroadcastTo instead.
  124. */
  125. REG_OP(BroadcastToD)
  126. .INPUT(x, TensorType::BasicType())
  127. .OUTPUT(y, TensorType::BasicType())
  128. .REQUIRED_ATTR(shape, ListInt)
  129. .OP_END_FACTORY_REG(BroadcastToD)
  130. /**
  131. *@brief Pads a tensor . \n
  132. *@par Inputs:
  133. *Two inputs, including:
  134. * @li x: A Tensor. Must be one of the following types: float16, float32, double, int32,
  135. * uint8, int16, int8, complex64, int64, qint8, quint8, qint32, qint16, quint16, uint16,
  136. * complex128, uint32, uint64.
  137. * @li paddings: A Tensor of type int32 or int64 . \n
  138. *@par Outputs:
  139. *y: A Tensor of the same type as "x" . \n
  140. *@par Third-party framework compatibility:
  141. * Compatible with TensorFlow operator Pad.
  142. */
  143. REG_OP(Pad)
  144. .INPUT(x, TensorType::BasicType())
  145. .INPUT(paddings, TensorType::IndexNumberType())
  146. .OUTPUT(y, TensorType::BasicType())
  147. .OP_END_FACTORY_REG(Pad)
  148. /**
  149. *@brief Pads a tensor . \n
  150. *@par Inputs:
  151. *x: A Tensor. Must be one of the following types: float16, float32, int32 . \n
  152. *@par Attributes:
  153. *paddings: An optional "vector<vector<int>>". Defaults to "{}".
  154. * For each dimension D of input, paddings[D, 0] indicates how many
  155. * values to add before the contents of tensor in that dimension,
  156. * and paddings[D, 1] indicates how many values to add after the
  157. * contents of tensor in that dimension . \n
  158. *@par Outputs:
  159. *y: A Tensor of the same type as "x" . \n
  160. *@par Third-party framework compatibility:
  161. * Compatible with TensorFlow operator Pad.
  162. *
  163. * @par Restrictions:
  164. * Warning: THIS FUNCTION IS DEPRECATED. Please use Pad instead.
  165. */
  166. REG_OP(PadD)
  167. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32}))
  168. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32}))
  169. .REQUIRED_ATTR(paddings, ListListInt)
  170. .OP_END_FACTORY_REG(PadD)
  171. /**
  172. *@brief Pads a tensor . \n
  173. *@par Inputs:
  174. *Three inputs, including:
  175. * @li x: A Tensor. Must be one of the following types: float16, float32, double, int32,
  176. * uint8, int16, int8, complex64, int64, qint8, quint8, qint32, qint16, quint16, uint16,
  177. * complex128, uint32, uint64.
  178. * @li constant_values: A Tensor. Must have the same type as input.
  179. * @li paddings: A Tensor of type int32 or int64 . \n
  180. *@par Outputs:
  181. *y: A Tensor of the same type as "x" . \n
  182. *@par Third-party framework compatibility:
  183. * Compatible with TensorFlow operator Pad.
  184. */
  185. REG_OP(PadV2)
  186. .INPUT(x, TensorType::BasicType())
  187. .INPUT(paddings, TensorType::IndexNumberType())
  188. .INPUT(constant_values, TensorType::BasicType())
  189. .OUTPUT(y, TensorType::BasicType())
  190. .OP_END_FACTORY_REG(PadV2)
  191. /**
  192. *@brief Pads a tensor . \n
  193. *@par Inputs:
  194. *x: A Tensor. Must be one of the following types: float16, float32, int32 . \n
  195. *constant_values: A Tensor. Must have the same type as input.
  196. *@par Attributes:
  197. *paddings: An optional "vector<vector<int>>". Defaults to "{}".
  198. * For each dimension D of input, paddings[D, 0] indicates how many
  199. * values to add before the contents of tensor in that dimension,
  200. * and paddings[D, 1] indicates how many values to add after the
  201. * contents of tensor in that dimension . \n
  202. *@par Outputs:
  203. *y: A Tensor of the same type as "x" . \n
  204. *@par Third-party framework compatibility:
  205. * Compatible with TensorFlow operator PadV2.
  206. */
  207. REG_OP(PadV2D)
  208. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32}))
  209. .INPUT(constant_values, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32}))
  210. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32}))
  211. .REQUIRED_ATTR(paddings, ListListInt)
  212. .OP_END_FACTORY_REG(PadV2D)
  213. /**
  214. *@brief Pads a tensor.
  215. *@par Inputs:
  216. *Two inputs, including:
  217. * @li x: A Tensor. Must be one of the following types: float16, float32, double, int32,
  218. * uint8, int16, int8, complex64, int64, qint8, quint8, qint32, qint16, quint16, uint16,
  219. * complex128, uint32, uint64.
  220. * @li paddings: A Tensor of type int32 or int64.
  221. * @li constant_values: A optional Tensor of int32 or int64
  222. *@par Attributes:
  223. * @li mode: An optional string, Defaults to "constant", indicates paddings mode,
  224. * support "constant", "reflect", "edge"
  225. * @li paddings_contiguous: An optional bool value, Defaults to true.
  226. * If true, paddings is arranged as [[begin0, end0], [begin1, end1], ...]
  227. * If false, paddings is arranged as [[begin0, begin1], ..., [end0, end1], ...]
  228. *@par Outputs:
  229. *y: A Tensor of the same type as "x".
  230. *@par Third-party framework compatibility:
  231. * Compatible with ONNX operator Pad.
  232. */
  233. REG_OP(PadV3)
  234. .INPUT(x, TensorType::BasicType())
  235. .INPUT(paddings, TensorType::IndexNumberType())
  236. .OPTIONAL_INPUT(constant_values, TensorType::BasicType())
  237. .OUTPUT(y, TensorType::BasicType())
  238. .ATTR(mode, String, "constant")
  239. .ATTR(paddings_contiguous, Bool, true)
  240. .OP_END_FACTORY_REG(PadV3)
  241. /**
  242. *@brief Pads a tensor.
  243. *@par Inputs:
  244. *x: A Tensor. Must be one of the following types: float16, float32, int8, uint8, int32.
  245. *@par Attributes:
  246. * @li paddings: An required "vector<vector<int>>".
  247. * For each dimension D of input, paddings[D, 0] indicates how many
  248. * values to add before the contents of tensor in that dimension,
  249. * and paddings[D, 1] indicates how many values to add after the
  250. * contents of tensor in that dimension.
  251. * @li constant_values: An optional int value for pad.
  252. * @li mode: An optional string, Defaults to "constant", indicates paddings mode,
  253. * support "constant", "reflect", "edge"
  254. * @li paddings_contiguous: An optional bool value, Defaults to true.
  255. * If true, paddings is arranged as [[begin0, end0], [begin1, end1], ...]
  256. * If false, paddings is arranged as [[begin0, begin1], ..., [end0, end1], ...]
  257. *@par Outputs:
  258. *y: A Tensor of the same type as "x".
  259. *@par Third-party framework compatibility:
  260. * Compatible with ONNX operator Pad.
  261. * @par Restrictions:
  262. * Warning: THIS FUNCTION IS DEPRECATED. Please use PadV3 instead.
  263. */
  264. REG_OP(PadV3D)
  265. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT8, DT_UINT8}))
  266. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT8, DT_UINT8}))
  267. .REQUIRED_ATTR(paddings, ListListInt)
  268. .ATTR(constant_values, Int, 0)
  269. .ATTR(mode, String, "constant")
  270. .ATTR(paddings_contiguous, Bool, true)
  271. .OP_END_FACTORY_REG(PadV3D)
  272. /**
  273. *@brief Create a diagonal tensor
  274. *@par Inputs:
  275. *Two inputs, including:
  276. * @li x: A mutable Tensor. Must be one of the following types:
  277. * float16, float32, int32 . \n
  278. * @li assist: A mutable Tensor with rank k is at most 1,
  279. * Has the same type as "x" . \n
  280. *@par Outputs:
  281. *y: A mutable Tensor. Has the same type as "x" . \n
  282. *@see Diag()
  283. *@par Third-party framework compatibility
  284. * Compatible with the TensorFlow operator Diag.
  285. *
  286. * @par Restrictions:
  287. * Warning: THIS FUNCTION IS DEPRECATED. Please use Diag instead.
  288. */
  289. REG_OP(DiagD)
  290. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32}))
  291. .INPUT(assist, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32}))
  292. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32}))
  293. .OP_END_FACTORY_REG(DiagD)
  294. /**
  295. *@brief Create a diagonal tensor
  296. *@par Inputs:
  297. *One input, include:
  298. * x: A mutable Tensor with rank k, where k is at most 1. Must be one of the
  299. * following types:
  300. * float16, float32, double, int32, int64, complex64, complex128 . \n
  301. *@par Outputs:
  302. *y: A mutable Tensor. Has the same type as "x" . \n
  303. *@see DiagD()
  304. *@par Third-party framework compatibility
  305. * Compatible with the TensorFlow operator Diag.
  306. */
  307. REG_OP(Diag)
  308. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT32,
  309. DT_INT64, DT_COMPLEX64, DT_COMPLEX128}))
  310. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT32,
  311. DT_INT64, DT_COMPLEX64, DT_COMPLEX128}))
  312. .OP_END_FACTORY_REG(Diag)
  313. /**
  314. *@brief Ascend Padding, pad the last dimension of input
  315. *@par Inputs:
  316. *One input, include:
  317. *x: Tensor which last dimension must be 1. For example: [624000, 1] . \n
  318. *@par Outputs:
  319. *y: Padding the last dimension of x to padDimSize, [624000, padDimSize] . \n
  320. *@par Third-party framework compatibility
  321. * Compatible with the TensorFlow operator Diag.
  322. */
  323. REG_OP(AscendPadding)
  324. .INPUT(x, TensorType::BasicType())
  325. .OUTPUT(y, TensorType::BasicType())
  326. .ATTR(pad_dim_size, Int, 8)
  327. .OP_END_FACTORY_REG(AscendPadding)
  328. /**
  329. *@brief EmbeddingRankId, traverse the index calculation server and its position in the server . \n
  330. *@par Restrictions:
  331. *Warning:THIS FUNCTION IS DEPRECATED. Please do not use. \n
  332. *@par Inputs:
  333. *One input, include:
  334. *addr_table: Tensor which last dimension must be 3. For example: [8, 3].
  335. *index: Tensor For example: [640000].
  336. *@par Outputs:
  337. *rank_id: Tensor the first dimension of index to Size, [size, 3].
  338. Tensor which last dimension must be 3.For example: [640000, 3]
  339. *@par Third-party framework compatibility
  340. * Compatible with the TensorFlow operator Diag.
  341. */
  342. REG_OP(EmbeddingRankId)
  343. .INPUT(addr_table, TensorType({DT_UINT64}))
  344. .INPUT(index, TensorType({DT_INT64,DT_INT32,DT_UINT64}))
  345. .OUTPUT(rank_id, TensorType({DT_UINT64}))
  346. .ATTR(row_memory, Int, 320)
  347. .ATTR(mode, String, "mod")
  348. .OP_END_FACTORY_REG(EmbeddingRankId)
  349. /**
  350. * @brief Fill the value to a tensor has the specified shape.
  351. * @par Inputs:
  352. * One inputs, including:
  353. * @li dims: An Tensor, specify the shape that the value to fill.
  354. * @par Attributes:
  355. * @li value: An optional float value. Defaults to 0.0.
  356. * @par Outputs:
  357. * @li y: A Tensor. Has the shape specify by attr shape, and full of the value specify by attr value.
  358. * @par Third-party framework compatibility
  359. * Compatible with the ONNX operator ConstantOfShape.
  360. */
  361. REG_OP(FillV2)
  362. .INPUT(dims, TensorType({DT_INT16, DT_INT32, DT_INT64}))
  363. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT, DT_DOUBLE, DT_INT8, DT_INT16, DT_INT32, DT_INT64}))
  364. .ATTR(value, Float, 0)
  365. .OP_END_FACTORY_REG(FillV2)
  366. /**
  367. * @brief Fill the value to a tensor has the specified shape.
  368. * @par Attributes:
  369. * @li value: An optional float value. Defaults to 0.0.
  370. * @li dims: An required listInt to specify the shape that the value to fill.
  371. * @par Outputs:
  372. * @li y: A Tensor. Has the shape specify by attr shape, and full of the value specify by attr value.
  373. * @par Third-party framework compatibility
  374. * Compatible with the ONNX operator ConstantOfShape.
  375. */
  376. REG_OP(FillV2D)
  377. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT, DT_DOUBLE, DT_INT8, DT_UINT8, DT_INT16, DT_INT32, DT_INT64}))
  378. .ATTR(value, Float, 0)
  379. .REQUIRED_ATTR(dims, ListInt)
  380. .OP_END_FACTORY_REG(FillV2D)
  381. } // namespace ge
  382. #endif // OPS_BUILT_IN_OP_PROTO_INC_PAD_OPS_H_

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