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

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