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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  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 types:float16, float32, double, int64, int32, uint8, uint16, uint32, uint64, int8, int16, complex64, complex128, qint8, quint8, qint16, quint16, qint32.
  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 int32. 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. *N: An attribute int8, int16, int32, or int64. Specifies the number of elements in "x". Defaults to "1".
  160. *@par Outputs:
  161. *y: A Tensor. Has the same type and format as "x".
  162. *@attention Constraints:
  163. *@li "x" is a list of at least 2 "tensor" objects of the same type.
  164. *@li "concat_dim" is in the range [-len(x.shape), len(x.shape)].
  165. *@par Third-party framework compatibility
  166. * Compatible with the TensorFlow operator ConcatV2.
  167. */
  168. REG_OP(ConcatV2D)
  169. .DYNAMIC_INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32, DT_INT8, DT_INT64, DT_UINT64, DT_UINT32, DT_INT16, DT_UINT16, DT_UINT8}))
  170. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32, DT_INT8, DT_INT64, DT_UINT64, DT_UINT32, DT_INT16, DT_UINT16, DT_UINT8}))
  171. .REQUIRED_ATTR(concat_dim, Int)
  172. .ATTR(N, Int, 1)
  173. .OP_END_FACTORY_REG(ConcatV2D)
  174. /**
  175. *@brief Concatenates tensors along one dimension.
  176. *@par Inputs:
  177. * Two inputs, including:
  178. *@li Dynamic input "x" is An NC1HWC0 or ND Tensor.
  179. *Must be one of the following types: float16, float32, int32, int8, int16, int64, uint8, uint16, uint32, uint64
  180. *@li concat_dim: An int32, or int64. Specifies the dimension along which to concatenate.
  181. *@par Attributes:
  182. *N: An optional int8, int16, int32, or int64. Specifies the number of elements in "x". No default value.
  183. *@par Outputs:
  184. *y: A Tensor. Has the same type and format as "x".
  185. *@attention Constraints:
  186. * "x" is a list of at least 2 "tensor" objects of the same type.
  187. *@par Third-party framework compatibility
  188. * Compatible with the TensorFlow operator ConcatV2.
  189. */
  190. REG_OP(ConcatV2)
  191. .DYNAMIC_INPUT(x, TensorType::BasicType())
  192. .INPUT(concat_dim, TensorType::IndexNumberType())
  193. .OUTPUT(y, TensorType::BasicType())
  194. .ATTR(N, Int, 1)
  195. .OP_END_FACTORY_REG(ConcatV2)
  196. /**
  197. *@brief Concatenates tensors along one dimension.
  198. *@par Inputs:
  199. * One input:
  200. *x:Dynamic input. An NC1HWC0 or ND Tensor.
  201. *Must be one of the following types: float16, float32, int32, int8, int16, int64, uint8, uint16, uint32, uint64
  202. *@par Attributes:
  203. *@li concat_dim: A required int8, int16, int32, or int64. Specifies the dimension along which to concatenate. No default value.
  204. *@li N: An optional int8, int16, int32, or int64. Specifies the number of elements in "x". No default value.
  205. *@par Outputs:
  206. *y: A Tensor. Has the same type and format as "x".
  207. *@attention Constraints:
  208. *@li "x" is a list of at least 2 "tensor" objects of the same type.
  209. *@li "concat_dim" is in the range [-len(x.shape), len(x.shape)].
  210. *@par Third-party framework compatibility
  211. * Compatible with the TensorFlow operator Concat.
  212. */
  213. REG_OP(ConcatD)
  214. .DYNAMIC_INPUT(x, TensorType({DT_FLOAT,DT_FLOAT16,DT_INT8,DT_INT16,DT_INT32,DT_INT64,DT_UINT8,DT_UINT16,DT_UINT32,DT_UINT64}))
  215. .OUTPUT(y, TensorType({DT_FLOAT,DT_FLOAT16,DT_INT8,DT_INT16,DT_INT32,DT_INT64,DT_UINT8,DT_UINT16,DT_UINT32,DT_UINT64}))
  216. .REQUIRED_ATTR(concat_dim, Int)
  217. .ATTR(N, Int, 1)
  218. .OP_END_FACTORY_REG(ConcatD)
  219. /**
  220. *@brief Concatenates tensors along one dimension.
  221. *@par Inputs:
  222. * Two inputs, including:
  223. *@li x: Dynamic input.An NC1HWC0 or ND Tensor.
  224. *Must be one of the following types: float16, float32, double, int32,
  225. * uint8, int16, int8, complex64, int64, qint8, quint8, qint32, uint16,
  226. * complex128, uint32, uint64, qint16, quint16.
  227. *@li concat_dim: An int32, or int64. Specifies the dimension along which to concatenate.
  228. *@par Attributes:
  229. *N: An optional int8, int16, int32, or int64. Specifies the number of elements in "x".
  230. *@par Outputs:
  231. *y: A Tensor. Has the same type and format as "x".
  232. *@attention Constraints:
  233. *@li "x" is a list of at least 2 "tensor" objects of the same type.
  234. *@li "concat_dim" is in the range [-len(x.shape), len(x.shape)].
  235. *@par Third-party framework compatibility
  236. * Compatible with the TensorFlow operator Concat.
  237. */
  238. REG_OP(Concat)
  239. .DYNAMIC_INPUT(x, TensorType::BasicType())
  240. .INPUT(concat_dim, TensorType::IndexNumberType())
  241. .OUTPUT(y, TensorType::BasicType())
  242. .ATTR(N, Int, 1)
  243. .OP_END_FACTORY_REG(Concat)
  244. /**
  245. *@brief Packs the list of tensors in values into a tensor with rank one higher than each tensor in
  246. * values, by packing them along the axis dimension. Given a list of length N of tensors of
  247. * shape (A, B, C); if axis == 0 then the output tensor will have the shape (N, A, B, C).
  248. *@par Inputs:
  249. * x: A list of N Tensors. Must be one of the following types: int8, int16, int32,
  250. * int64, uint8, uint16, uint32, uint64, float16, float32, bool.
  251. *@par Attributes:
  252. *@li axis: A optional int, defaultvalue is 0.
  253. * Dimension along which to pack. The range is [-(R+1), R+1).
  254. *@li N: A required int. Number of tensors.
  255. *@par Outputs:
  256. *y: A Tensor. Has the same type as "x".
  257. *@par Third-party framework compatibility
  258. *Compatible with the TensorFlow operator Pack.
  259. */
  260. REG_OP(Pack)
  261. .DYNAMIC_INPUT(x, TensorType::BasicType())
  262. .OUTPUT(y, TensorType::BasicType())
  263. .ATTR(axis, Int, 0)
  264. .REQUIRED_ATTR(N, Int)
  265. .OP_END_FACTORY_REG(Pack)
  266. /**
  267. *@brief Computes offsets of concat inputs within its output.
  268. *@par Inputs:
  269. *Two inputs, including:
  270. * @li concat_dim: A Tensor of type int32.
  271. * @li x: A list of 1D Tensor objects of type int32.
  272. *@par Attributes:
  273. *N: A required int.
  274. *@par Outputs:
  275. *y: A Tensor list with same type as "x".
  276. *@par Third-party framework compatibility
  277. *@ Compatible with the TensorFlow operator ConcatOffset.
  278. */
  279. REG_OP(ConcatOffset)
  280. .INPUT(concat_dim, TensorType({DT_INT32}))
  281. .DYNAMIC_INPUT(x, TensorType({DT_INT32}))
  282. .DYNAMIC_OUTPUT(y, TensorType({DT_INT32}))
  283. .REQUIRED_ATTR(N, Int)
  284. .OP_END_FACTORY_REG(ConcatOffset)
  285. /**
  286. *@brief Computes offsets of concat inputs within its output.
  287. *@par Inputs:
  288. *Two inputs, including:
  289. * @li concat_dim: A Tensor of type int32.
  290. * @li x: A list of 1D Tensor objects of type int32.
  291. *@par Attributes:
  292. *@li Concat_dim: A required int. Must be within the rank of input "x".
  293. *@li N: A required int.
  294. *@par Outputs:
  295. *y: A Tensor list with same type as "x".
  296. *@par Third-party framework compatibility
  297. *@ Compatible with the TensorFlow operator ConcatOffset.
  298. */
  299. REG_OP(ConcatOffsetD)
  300. .DYNAMIC_INPUT(x, TensorType({DT_INT32}))
  301. .DYNAMIC_OUTPUT(y, TensorType({DT_INT32}))
  302. .REQUIRED_ATTR(concat_dim, Int)
  303. .REQUIRED_ATTR(N, Int)
  304. .OP_END_FACTORY_REG(ConcatOffsetD)
  305. } // namespace ge
  306. #endif // GE_OP_SPLIT_COMBINATION_OPS_H

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