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.

split_combination_ops.h 15 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
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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  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 split_combination_ops.h
  18. * \brief
  19. */
  20. #ifndef GE_OP_SPLIT_COMBINATION_OPS_H
  21. #define GE_OP_SPLIT_COMBINATION_OPS_H
  22. #include "graph/operator_reg.h"
  23. namespace ge {
  24. /**
  25. *@brief Splits a tensor along dimension "split_dim" into "num_split" smaller tensors.
  26. *@par Inputs:
  27. * Two inputs, including:
  28. *@li x: An ND Tensor.
  29. *Must be one of the types:float16, float32, double, int64, int32, uint8, uint16, uint32, uint64, int8, int16, complex64, complex128, qint8, quint8, qint16, quint16, qint32.
  30. *@li split_dim: Must be the following type:int32. Specifies the dimension along which to split.
  31. *@par Attributes:
  32. *num_split: A required int32. Specifies the number of output tensors. No default value.
  33. *@par Outputs:
  34. *y: Dynamic output.A list of output tensors. Has the same type and format as "x".
  35. *@attention Constraints:
  36. *@li "num_split" is greater than or equals to 1.
  37. *@li "num_split" is divisible by the size of dimension "split_dim".
  38. *@li "split_dim" is in the range [-len(x.shape), (x.shape)-1].
  39. *@par Third-party framework compatibility
  40. * Compatible with the TensorFlow operator Split.
  41. */
  42. REG_OP(Split)
  43. .INPUT(split_dim, TensorType({DT_INT32}))
  44. .INPUT(x, TensorType::BasicType())
  45. .DYNAMIC_OUTPUT(y, TensorType::BasicType())
  46. .REQUIRED_ATTR(num_split, Int)
  47. .OP_END_FACTORY_REG(Split)
  48. /**
  49. *@brief Splits a tensor along dimension "split_dim" into "num_split" smaller tensors.
  50. *@par Inputs:
  51. * One input:
  52. *: An ND Tensor. \n
  53. *Must be one of the following types: float16, float32, int32, int8, int16, int64, uint8, uint16, uint32, uint64
  54. *@par Attributes:
  55. *@li split_dim: A required int8, int16, int32, or int64. Specifies the dimension along which to split. No default value.
  56. *@li num_split: A required int8, int16, int32, or int64. Specifies the number of output tensors. No default value.
  57. *@par Outputs:
  58. *y:Dynamic output. A list of output tensors. Has the same type and format as "x".
  59. *@attention Constraints:
  60. *@li "num_split" is greater than or equals to 1.
  61. *@li "num_split" is divisible by the size of dimension "split_dim".
  62. *@li "split_dim" is in the range [-len(x.shape), (x.shape)-1].
  63. *@par Third-party framework compatibility
  64. * Compatible with the TensorFlow operator Split.
  65. */
  66. REG_OP(SplitD)
  67. .INPUT(x, TensorType({DT_INT8, DT_INT16, DT_INT32, DT_INT64, DT_UINT8,
  68. DT_UINT16, DT_UINT32, DT_UINT64, DT_FLOAT, DT_FLOAT16}))
  69. .DYNAMIC_OUTPUT(y, TensorType({DT_INT8, DT_INT16, DT_INT32, DT_INT64, DT_UINT8,
  70. DT_UINT16, DT_UINT32, DT_UINT64, DT_FLOAT, DT_FLOAT16}))
  71. .REQUIRED_ATTR(split_dim, Int)
  72. .REQUIRED_ATTR(num_split, Int)
  73. .OP_END_FACTORY_REG(SplitD)
  74. /**
  75. *@brief Splits a tensor along dimension "split_dim" into "num_split" smaller tensors according to "size_splits".
  76. *@par Inputs:
  77. * Three inputs, including:
  78. *@li x: An ND Tensor. \n
  79. *Must be one of the following types:
  80. *@li size_splits: A list of int8, int16, int32, or int64. Specifies a list containing the sizes of each output tensor along the split dimension.
  81. *@li split_dim: An int8, int16, int32, or int64. Specifies the dimension along which to split.
  82. *@par Attributes:
  83. *num_split: A required int8, int16, int32, or int64. Specifies the number of output tensors. No default value.
  84. *@par Outputs:
  85. *y: Dynamic output.A list of output tensors. Has the same type and format as "x".
  86. *@attention Constraints:
  87. *@li Each element in "size_splits" is greater than or equal to 1.
  88. *@li "size_splits" and "num_split" have the same length.
  89. *@li The elements in "size_splits" sum to the size of dimension "split_dim".
  90. *@par Third-party framework compatibility
  91. * Compatible with the TensorFlow operator SplitV.
  92. */
  93. REG_OP(SplitV)
  94. .INPUT(x, TensorType::BasicType())
  95. .INPUT(size_splits, TensorType::IndexNumberType())
  96. .INPUT(split_dim, TensorType({DT_INT32}))
  97. .DYNAMIC_OUTPUT(y, TensorType::BasicType())
  98. .REQUIRED_ATTR(num_split, Int)
  99. .OP_END_FACTORY_REG(SplitV)
  100. /**
  101. *@brief Splits a tensor along dimension "split_dim" into "num_split" smaller tensors according to "size_splits".
  102. *@par Inputs:
  103. * One input:
  104. * x: An ND Tensor. \n
  105. *Must be one of the following types: float16, float32, int32, int8, int16, int64, uint8, uint16, uint32, uint64
  106. *@par Attributes:
  107. *@li size_splits: A required list of int8, int16, int32, or int64. Specifies a list containing the sizes of each output tensor along the split dimension.
  108. *@li split_dim: A required int8, int16, int32, or int64. Specifies the dimension along which to split. No default value.
  109. *@li num_split: A required int8, int16, int32, or int64. Specifies the number of output tensors. No default value.
  110. *@par Outputs:
  111. *y: Dynamic output.A list of output tensors. Has the same type and format as "x".
  112. *@attention Constraints:
  113. *@li Each element in "size_splits" is greater than or equal to 1.
  114. *@li "size_splits" and "num_split" have the same length.
  115. Under the caffe framework, the conversion of slice_point through the cut point to cut segment is mapped to size_splits.
  116. *@li The elements in "size_splits" sum to the size of dimension "split_dim".
  117. Under the caffe framework,size_splits or axis transformat to split_dim.Only one can effect.
  118. *@par Third-party framework compatibility
  119. * Compatible with the TensorFlow operator SplitV.
  120. */
  121. REG_OP(SplitVD)
  122. .INPUT(x, TensorType({DT_INT8, DT_INT16, DT_INT32, DT_INT64, DT_UINT8,
  123. DT_UINT16, DT_UINT32, DT_UINT64, DT_FLOAT, DT_FLOAT16}))
  124. .DYNAMIC_OUTPUT(y, TensorType({DT_INT8, DT_INT16, DT_INT32, DT_INT64, DT_UINT8,
  125. DT_UINT16, DT_UINT32, DT_UINT64, DT_FLOAT, DT_FLOAT16}))
  126. .REQUIRED_ATTR(size_splits, ListInt)
  127. .REQUIRED_ATTR(split_dim, Int)
  128. .REQUIRED_ATTR(num_split, Int)
  129. .OP_END_FACTORY_REG(SplitVD)
  130. /**
  131. *@brief Concatenates a list of N tensors along the first dimension.
  132. *@par Inputs:
  133. * Two inputs, including:
  134. * @li values: A list of Tensors. Must be one of the following types: int8, int16, int32, \n
  135. * int64, uint8, uint16, uint32, uint64, float16, float32. \n
  136. * Tensors to be concatenated. \n
  137. * All must have size 1 in the first dimension and same shape.
  138. * @li shape: A Tensor of the same type as "x". \n
  139. * The final shape of the result. Should be equal to the shapes of any input
  140. * but with the number of input values in the first dimension.
  141. *@par Attributes:
  142. * @li shape: A required list of ints.
  143. * @li N: The numble of dynamic_input "values".
  144. *@par Outputs:
  145. *output_data: The concatenated tensor with same type as "values".
  146. *@par Third-party framework compatibility
  147. *Compatible with the TensorFlow operator ParallelConcat.
  148. */
  149. REG_OP(ParallelConcat)
  150. .DYNAMIC_INPUT(values, TensorType({DT_FLOAT,DT_FLOAT16,DT_INT8,DT_INT16,DT_INT32,DT_INT64,DT_UINT8,DT_UINT16,DT_UINT32,DT_UINT64}))
  151. .OUTPUT(output_data, TensorType({DT_FLOAT,DT_FLOAT16,DT_INT8,DT_INT16,DT_INT32,DT_INT64,DT_UINT8,DT_UINT16,DT_UINT32,DT_UINT64}))
  152. .REQUIRED_ATTR(shape, ListInt)
  153. .REQUIRED_ATTR(N, Int)
  154. .OP_END_FACTORY_REG(ParallelConcat)
  155. /**
  156. *@brief Concatenates tensors along one dimension.
  157. *@par Inputs:
  158. * One input:
  159. *x: Dynamic input.An NC1HWC0 or ND Tensor.
  160. *Must be one of the following types: float16, float32, int32, int8, int16, int64, uint8, uint16, uint32, uint64
  161. *@par Attributes:
  162. *concat_dim: A required int8, int16, int32, or int64. Specifies the dimension along which to concatenate. No default value.
  163. *N: An attribute int8, int16, int32, or int64. Specifies the number of elements in "x". Defaults to "1".
  164. *@par Outputs:
  165. *y: A Tensor. Has the same type and format as "x".
  166. *@attention Constraints:
  167. *@li "x" is a list of at least 2 "tensor" objects of the same type.
  168. *@li "concat_dim" is in the range [-len(x.shape), len(x.shape)].
  169. *@par Third-party framework compatibility
  170. * Compatible with the TensorFlow operator ConcatV2.
  171. *@par Restrictions:
  172. *Warning: THIS FUNCTION IS DEPRECATED. Please use ConcatV2 instead.
  173. */
  174. REG_OP(ConcatV2D)
  175. .DYNAMIC_INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32, DT_INT8, DT_INT64, DT_UINT64, DT_UINT32, DT_INT16, DT_UINT16, DT_UINT8}))
  176. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32, DT_INT8, DT_INT64, DT_UINT64, DT_UINT32, DT_INT16, DT_UINT16, DT_UINT8}))
  177. .REQUIRED_ATTR(concat_dim, Int)
  178. .ATTR(N, Int, 1)
  179. .OP_END_FACTORY_REG(ConcatV2D)
  180. /**
  181. *@brief Concatenates tensors along one dimension.
  182. *@par Inputs:
  183. * Two inputs, including:
  184. *@li Dynamic input "x" is An NC1HWC0 or ND Tensor.
  185. *Must be one of the following types: float16, float32, int32, int8, int16, int64, uint8, uint16, uint32, uint64
  186. *@li concat_dim: An int32, or int64. Specifies the dimension along which to concatenate.
  187. *@par Attributes:
  188. *N: An optional int8, int16, int32, or int64. Specifies the number of elements in "x". No default value.
  189. *@par Outputs:
  190. *y: A Tensor. Has the same type and format as "x".
  191. *@attention Constraints:
  192. * "x" is a list of at least 2 "tensor" objects of the same type.
  193. *@par Third-party framework compatibility
  194. * Compatible with the TensorFlow operator ConcatV2.
  195. */
  196. REG_OP(ConcatV2)
  197. .DYNAMIC_INPUT(x, TensorType::BasicType())
  198. .INPUT(concat_dim, TensorType::IndexNumberType())
  199. .OUTPUT(y, TensorType::BasicType())
  200. .ATTR(N, Int, 1)
  201. .OP_END_FACTORY_REG(ConcatV2)
  202. /**
  203. *@brief Concatenates tensors along one dimension.
  204. *@par Inputs:
  205. * One input:
  206. *x:Dynamic input. An NC1HWC0 or ND Tensor.
  207. *Must be one of the following types: float16, float32, int32, int8, int16, int64, uint8, uint16, uint32, uint64
  208. *@par Attributes:
  209. *@li concat_dim: A required int8, int16, int32, or int64. Specifies the dimension along which to concatenate. No default value.
  210. *@li N: An optional int8, int16, int32, or int64. Specifies the number of elements in "x". No default value.
  211. *@par Outputs:
  212. *y: A Tensor. Has the same type and format as "x".
  213. *@attention Constraints:
  214. *@li "x" is a list of at least 2 "tensor" objects of the same type.
  215. *@li "concat_dim" is in the range [-len(x.shape), len(x.shape)].
  216. *@par Third-party framework compatibility
  217. * Compatible with the TensorFlow operator Concat.
  218. *@par Restrictions:
  219. *Warning: THIS FUNCTION IS DEPRECATED. Please use Concat instead.
  220. */
  221. REG_OP(ConcatD)
  222. .DYNAMIC_INPUT(x, TensorType({DT_FLOAT,DT_FLOAT16,DT_INT8,DT_INT16,DT_INT32,DT_INT64,DT_UINT8,DT_UINT16,DT_UINT32,DT_UINT64}))
  223. .OUTPUT(y, TensorType({DT_FLOAT,DT_FLOAT16,DT_INT8,DT_INT16,DT_INT32,DT_INT64,DT_UINT8,DT_UINT16,DT_UINT32,DT_UINT64}))
  224. .REQUIRED_ATTR(concat_dim, Int)
  225. .ATTR(N, Int, 1)
  226. .OP_END_FACTORY_REG(ConcatD)
  227. /**
  228. *@brief Concatenates tensors along one dimension.
  229. *@par Inputs:
  230. * Two inputs, including:
  231. *@li x: Dynamic input.An NC1HWC0 or ND Tensor.
  232. *Must be one of the following types: float16, float32, double, int32,
  233. * uint8, int16, int8, complex64, int64, qint8, quint8, qint32, uint16,
  234. * complex128, uint32, uint64, qint16, quint16.
  235. *@li concat_dim: An int32, or int64. Specifies the dimension along which to concatenate.
  236. *@par Attributes:
  237. *N: An optional int8, int16, int32, or int64. Specifies the number of elements in "x".
  238. *@par Outputs:
  239. *y: A Tensor. Has the same type and format as "x".
  240. *@attention Constraints:
  241. *@li "x" is a list of at least 2 "tensor" objects of the same type.
  242. *@li "concat_dim" is in the range [-len(x.shape), len(x.shape)].
  243. *@par Third-party framework compatibility
  244. * Compatible with the TensorFlow operator Concat.
  245. */
  246. REG_OP(Concat)
  247. .DYNAMIC_INPUT(x, TensorType::BasicType())
  248. .INPUT(concat_dim, TensorType::IndexNumberType())
  249. .OUTPUT(y, TensorType::BasicType())
  250. .ATTR(N, Int, 1)
  251. .OP_END_FACTORY_REG(Concat)
  252. /**
  253. *@brief Packs the list of tensors in values into a tensor with rank one higher than each tensor in
  254. * values, by packing them along the axis dimension. Given a list of length N of tensors of
  255. * shape (A, B, C); if axis == 0 then the output tensor will have the shape (N, A, B, C).
  256. *@par Inputs:
  257. * x: A list of N Tensors. Must be one of the following types: int8, int16, int32,
  258. * int64, uint8, uint16, uint32, uint64, float16, float32, bool.
  259. *@par Attributes:
  260. *@li axis: A optional int, defaultvalue is 0.
  261. * Dimension along which to pack. The range is [-(R+1), R+1).
  262. *@li N: A required int. Number of tensors.
  263. *@par Outputs:
  264. *y: A Tensor. Has the same type as "x".
  265. *@par Third-party framework compatibility
  266. *Compatible with the TensorFlow operator Pack.
  267. */
  268. REG_OP(Pack)
  269. .DYNAMIC_INPUT(x, TensorType::BasicType())
  270. .OUTPUT(y, TensorType::BasicType())
  271. .ATTR(axis, Int, 0)
  272. .REQUIRED_ATTR(N, Int)
  273. .OP_END_FACTORY_REG(Pack)
  274. /**
  275. *@brief Computes offsets of concat inputs within its output.
  276. *@par Inputs:
  277. *Two inputs, including:
  278. * @li concat_dim: A Tensor of type int32.
  279. * @li x: A list of 1D Tensor objects of type int32.
  280. *@par Attributes:
  281. *N: A required int.
  282. *@par Outputs:
  283. *y: A Tensor list with same type as "x".
  284. *@par Third-party framework compatibility
  285. *@ Compatible with the TensorFlow operator ConcatOffset.
  286. */
  287. REG_OP(ConcatOffset)
  288. .INPUT(concat_dim, TensorType({DT_INT32}))
  289. .DYNAMIC_INPUT(x, TensorType({DT_INT32}))
  290. .DYNAMIC_OUTPUT(y, TensorType({DT_INT32}))
  291. .REQUIRED_ATTR(N, Int)
  292. .OP_END_FACTORY_REG(ConcatOffset)
  293. /**
  294. *@brief Computes offsets of concat inputs within its output.
  295. *@par Inputs:
  296. *Two inputs, including:
  297. * @li concat_dim: A Tensor of type int32.
  298. * @li x: A list of 1D Tensor objects of type int32.
  299. *@par Attributes:
  300. *@li Concat_dim: A required int. Must be within the rank of input "x".
  301. *@li N: A required int.
  302. *@par Outputs:
  303. *y: A Tensor list with same type as "x".
  304. *@par Third-party framework compatibility
  305. *@ Compatible with the TensorFlow operator ConcatOffset.
  306. *@par Restrictions:
  307. *Warning: THIS FUNCTION IS DEPRECATED. Please use ConcatOffset instead.
  308. */
  309. REG_OP(ConcatOffsetD)
  310. .DYNAMIC_INPUT(x, TensorType({DT_INT32}))
  311. .DYNAMIC_OUTPUT(y, TensorType({DT_INT32}))
  312. .REQUIRED_ATTR(concat_dim, Int)
  313. .REQUIRED_ATTR(N, Int)
  314. .OP_END_FACTORY_REG(ConcatOffsetD)
  315. } // namespace ge
  316. #endif // GE_OP_SPLIT_COMBINATION_OPS_H

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