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.

functional_ops.h 16 kB

5 years ago
5 years ago
5 years ago
3 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. /**
  2. * Copyright 2019 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 functional_ops.h
  18. * \brief
  19. */
  20. #ifndef OPS_BUILT_IN_OP_PROTO_INC_FUNCTIONAL_OPS_H_
  21. #define OPS_BUILT_IN_OP_PROTO_INC_FUNCTIONAL_OPS_H_
  22. #include "graph/operator_reg.h"
  23. #include "graph/operator.h"
  24. namespace ge {
  25. /**
  26. *@brief Select one of the subgraphs to pass the input tensors and return the output tensors.
  27. * If "cond" means True, the selected subgraph is "then_branch".
  28. * Otherwise, the selected subgraph is "else_branch" . \n
  29. *@par Inputs:
  30. *@li cond: A Tensor. If "cond" is not a scalar of boolean type,
  31. * it will be converted to a boolean according to the following rule:
  32. * if "cond" is a numerical scalar, non-zero means True and zero means False;
  33. * if "cond" is a string scalar, non-empty means True and empty means False;
  34. * if "cond" is not a scalar, non-empty means True and empty means False.
  35. *@li input: The input tensors . It's a dynamic input. \n
  36. *@par Graphs:
  37. *@li then_branch: A subgraph takes 'input' and returns a list of tensors,
  38. * whose types are the same as what else_branch returns.
  39. *@li else_branch: A subgraph takes 'input' and returns a list of tensors,
  40. * whose types are the same as what then_branch returns . \n
  41. *@par Outputs:
  42. *output: The output tensors returned by either then_branch(input) or else_branch(input) . \n
  43. *@par Third-party framework compatibility
  44. *@Compatible with the TensorFlow operator _If.
  45. */
  46. REG_OP(_If)
  47. .INPUT(cond, TensorType::ALL())
  48. .DYNAMIC_INPUT(input, TensorType::ALL())
  49. .DYNAMIC_OUTPUT(output, TensorType::ALL())
  50. .GRAPH(then_branch)
  51. .GRAPH(else_branch)
  52. .OP_END_FACTORY_REG(_If)
  53. /**
  54. *@brief Select one of the subgraphs to pass the input tensors and return the output tensors.
  55. * If "cond" means True, the selected subgraph is "then_branch".
  56. * Otherwise, the selected subgraph is "else_branch" . \n
  57. *@par Inputs:
  58. *@li cond: A Tensor. If "cond" is not a scalar of boolean type,
  59. * it will be converted to a boolean according to the following rule:
  60. * if "cond" is a numerical scalar, non-zero means True and zero means False;
  61. * if "cond" is a string scalar, non-empty means True and empty means False;
  62. * if "cond" is not a scalar, non-empty means True and empty means False.
  63. *@li input: The input tensors . It's a dynamic input. \n
  64. *@par Graphs:
  65. *@li then_branch: A subgraph takes 'input' and returns a list of tensors,
  66. * whose types are the same as what else_branch returns.
  67. *@li else_branch: A subgraph takes 'input' and returns a list of tensors,
  68. * whose types are the same as what then_branch returns . \n
  69. *@par Outputs:
  70. *output: The output tensors returned by either then_branch(input) or else_branch(input) . \n
  71. *@par Third-party framework compatibility
  72. *@Compatible with the TensorFlow operator StatelessIf.
  73. */
  74. REG_OP(StatelessIf)
  75. .INPUT(cond, TensorType::ALL())
  76. .DYNAMIC_INPUT(input, TensorType::ALL())
  77. .DYNAMIC_OUTPUT(output, TensorType::ALL())
  78. .GRAPH(then_branch)
  79. .GRAPH(else_branch)
  80. .OP_END_FACTORY_REG(StatelessIf)
  81. /**
  82. *@brief Select one of the subgraphs to pass the input tensors and return the output tensors.
  83. * If "cond" means True, the selected subgraph is "then_branch".
  84. * Otherwise, the selected subgraph is "else_branch" . \n
  85. *@par Inputs:
  86. *@li cond: A Tensor. If "cond" is not a scalar of boolean type,
  87. * it will be converted to a boolean according to the following rule:
  88. * if "cond" is a numerical scalar, non-zero means True and zero means False;
  89. * if "cond" is a string scalar, non-empty means True and empty means False;
  90. * if "cond" is not a scalar, non-empty means True and empty means False.
  91. *@li input: The input tensors . It's a dynamic input. \n
  92. *@par Graphs:
  93. *@li then_branch: A subgraph takes 'input' and returns a list of tensors,
  94. * whose types are the same as what else_branch returns.
  95. *@li else_branch: A subgraph takes 'input' and returns a list of tensors,
  96. * whose types are the same as what then_branch returns . \n
  97. *@par Outputs:
  98. *output: The output tensors returned by either then_branch(input) or else_branch(input) . \n
  99. *@par Third-party framework compatibility
  100. *@Compatible with the TensorFlow operator If.
  101. */
  102. REG_OP(If)
  103. .INPUT(cond, TensorType::ALL())
  104. .DYNAMIC_INPUT(input, TensorType::ALL())
  105. .DYNAMIC_OUTPUT(output, TensorType::ALL())
  106. .GRAPH(then_branch)
  107. .GRAPH(else_branch)
  108. .OP_END_FACTORY_REG(If)
  109. /**
  110. *@brief Select one of the subgraphs to pass the input tensors and return the output tensors . \n
  111. *@par Inputs:
  112. *@li branch_index: A int32 scalar which determines the selected subgraph.
  113. *@li input: The input tensors, which will be passed to the subgraph . It's a dynamic input. \n
  114. *@par Graphs:
  115. *branches: A list of subgraphs, each of which takes 'input' and returns a list of tensors,
  116. * whose types are the same as what every other subgraph returns . \n
  117. *@par Outputs:
  118. *output: The output tensors returned by one of branches . It's a dynamic output. \n
  119. *@par Third-party framework compatibility
  120. *@Compatible with the TensorFlow operator Case.
  121. */
  122. REG_OP(StatelessCase)
  123. .INPUT(branch_index, DT_INT32)
  124. .DYNAMIC_INPUT(input, TensorType::ALL())
  125. .DYNAMIC_OUTPUT(output, TensorType::ALL())
  126. .DYNAMIC_GRAPH(branches)
  127. .OP_END_FACTORY_REG(StatelessCase)
  128. /**
  129. *@brief Select one of the subgraphs to pass the input tensors and return the output tensors . \n
  130. *@par Inputs:
  131. *@li branch_index: A int32 scalar which determines the selected subgraph.
  132. *@li input: The input tensors, which will be passed to the subgraph . It's a dynamic input. \n
  133. *@par Graphs:
  134. *branches: A list of subgraphs, each of which takes 'input' and returns a list of tensors,
  135. * whose types are the same as what every other subgraph returns . \n
  136. *@par Outputs:
  137. *output: The output tensors returned by one of branches . It's a dynamic output. \n
  138. *@par Third-party framework compatibility
  139. *@Compatible with the TensorFlow operator Case.
  140. */
  141. REG_OP(Case)
  142. .INPUT(branch_index, DT_INT32)
  143. .DYNAMIC_INPUT(input, TensorType::ALL())
  144. .DYNAMIC_OUTPUT(output, TensorType::ALL())
  145. .DYNAMIC_GRAPH(branches)
  146. .OP_END_FACTORY_REG(Case)
  147. /**
  148. *@brief Cyclic execute the "body" subgraph until the return tensor of "cond" subgraph means False . \n
  149. *@par Inputs:
  150. *input: The input tensors . It's a dynamic input. \n
  151. *@par Graphs:
  152. *@li cond: A subgraph takes 'input' and returns a tensor.
  153. * If the tensor is not a scalar of boolean type,
  154. * it will be converted to a boolean according to the following rule:
  155. * if it is a numerical scalar, non-zero means True and zero means False;
  156. * if it is a string scalar, non-empty means True and empty means False;
  157. * if it is not a scalar, non-empty means True and empty means False.
  158. *@li body: A subgraph takes 'input' and returns a another list of tensors . \n
  159. *@par Outputs:
  160. *output: The output tensors returned by "body". Has the same type as "input" . \n
  161. *@par Third-party framework compatibility
  162. *@Compatible with the TensorFlow operator _While.
  163. */
  164. REG_OP(_While)
  165. .DYNAMIC_INPUT(input, TensorType::ALL())
  166. .DYNAMIC_OUTPUT(output, TensorType::ALL())
  167. .GRAPH(cond)
  168. .GRAPH(body)
  169. .OP_END_FACTORY_REG(_While)
  170. /**
  171. *@brief Cyclic execute the "body" subgraph until the return tensor of "cond" subgraph means False . \n
  172. *@par Inputs:
  173. *input: The input tensors . It's a dynamic input. \n
  174. *@par Graphs:
  175. *@li cond: A subgraph takes 'input' and returns a tensor.
  176. * If the tensor is not a scalar of boolean type,
  177. * it will be converted to a boolean according to the following rule:
  178. * if it is a numerical scalar, non-zero means True and zero means False;
  179. * if it is a string scalar, non-empty means True and empty means False;
  180. * if it is not a scalar, non-empty means True and empty means False.
  181. *@li body: A subgraph takes 'input' and returns a another list of tensors . \n
  182. *@par Attributes:
  183. *parallel_iterations: An optional int, default as 10 . \n
  184. *@par Outputs:
  185. *output: The output tensors returned by "body". Has the same type as "input" . It's a dynamic output. \n
  186. *@par Third-party framework compatibility
  187. *@Compatible with the TensorFlow operator While.
  188. */
  189. REG_OP(While)
  190. .DYNAMIC_INPUT(input, TensorType::ALL())
  191. .DYNAMIC_OUTPUT(output, TensorType::ALL())
  192. .GRAPH(cond)
  193. .GRAPH(body)
  194. .ATTR(parallel_iterations, Int, 10)
  195. .OP_END_FACTORY_REG(While)
  196. /**
  197. *@brief Cyclic execute the "body" subgraph until the return tensor of "cond" subgraph means False . \n
  198. *@par Inputs:
  199. *input: The input tensors . It's a dynamic input. \n
  200. *@par Graphs:
  201. *@li cond: A subgraph takes 'input' and returns a tensor.
  202. * If the tensor is not a scalar of boolean type,
  203. * it will be converted to a boolean according to the following rule:
  204. * if it is a numerical scalar, non-zero means True and zero means False;
  205. * if it is a string scalar, non-empty means True and empty means False;
  206. * if it is not a scalar, non-empty means True and empty means False.
  207. *@li body: A subgraph takes 'input' and returns a another list of tensors . \n
  208. *@par Attributes:
  209. *parallel_iterations: An optional int, default as 10 . \n
  210. *@par Outputs:
  211. *output: The output tensors returned by "body". Has the same type as "input" . It's a dynamic output. \n
  212. *@par Third-party framework compatibility
  213. *@Compatible with the TensorFlow operator StatelessWhile.
  214. */
  215. REG_OP(StatelessWhile)
  216. .DYNAMIC_INPUT(input, TensorType::ALL())
  217. .DYNAMIC_OUTPUT(output, TensorType::ALL())
  218. .GRAPH(cond)
  219. .GRAPH(body)
  220. .ATTR(parallel_iterations, Int, 10)
  221. .OP_END_FACTORY_REG(StatelessWhile)
  222. /**
  223. *@brief Cyclic execute the "body" subgraph until the first input of For op exceed upper bound . \n
  224. *@par Inputs:
  225. *@li start: A int32 scalar. The lower bound.
  226. *@li limit: A int32 scalar. The upper bound.
  227. *@li delta: A int32 scalar. The step size.
  228. *@li input: The input tensors, which will be passed to "body" . It's a dynamic input. \n
  229. *@par Graphs:
  230. *body: A subgraph takes 'input' and returns a another list of tensors . \n
  231. *@par Outputs:
  232. *output: The output tensors returned by "body". Has the same type as "input" . It's a dynamic output. \n
  233. *@par Third-party framework compatibility
  234. *@Compatible with the TensorFlow operator For.
  235. */
  236. REG_OP(For)
  237. .INPUT(start, DT_INT32)
  238. .INPUT(limit, DT_INT32)
  239. .INPUT(delta, DT_INT32)
  240. .DYNAMIC_INPUT(input, TensorType::ALL())
  241. .DYNAMIC_OUTPUT(output, TensorType::ALL())
  242. .GRAPH(body)
  243. .OP_END_FACTORY_REG(For)
  244. /**
  245. *@brief Pass the input tensors to the subgraph "f" and return the output tensors . \n
  246. *@par Inputs:
  247. *args: The input tensors, which will be passed to "f" . It's a dynamic input. \n
  248. *@par Graphs:
  249. *f: A subgraph takes 'args' and returns a another list of tensors . \n
  250. *@par Attributes:
  251. *@li config: An optional string, default as "".
  252. *@li config_proto: An optional int, default as "".
  253. *@li executor_type: An optional int, default as "" . \n
  254. *@par Outputs:
  255. *output: The output tensors returned by "f" . It's a dynamic output. \n
  256. *@par Third-party framework compatibility
  257. *@Compatible with the TensorFlow operator PartitionedCall.
  258. */
  259. REG_OP(PartitionedCall)
  260. .DYNAMIC_INPUT(args, TensorType::ALL())
  261. .DYNAMIC_OUTPUT(output, TensorType::ALL())
  262. .GRAPH(f)
  263. .ATTR(config, String, "")
  264. .ATTR(config_proto, String, "")
  265. .ATTR(executor_type, String, "")
  266. .OP_END_FACTORY_REG(PartitionedCall)
  267. /**
  268. *@brief Pass the input tensors to the subgraph "f" and return the output tensors . \n
  269. *@par Inputs:
  270. *args: The input tensors, which will be passed to "f" . It's a dynamic input. \n
  271. *@par Graphs:
  272. *f: A subgraph takes 'args' and returns a another list of tensors . \n
  273. *@par Attributes:
  274. *@li config: An optional string, default as "".
  275. *@li config_proto: An optional int, default as "".
  276. *@li executor_type: An optional int, default as "" . \n
  277. *@par Outputs:
  278. *output: The output tensors returned by "f" . It's a dynamic output. \n
  279. *@par Third-party framework compatibility
  280. *@Compatible with the TensorFlow operator StatefulPartitionedCall.
  281. */
  282. REG_OP(StatefulPartitionedCall)
  283. .DYNAMIC_INPUT(args, TensorType::ALL())
  284. .DYNAMIC_OUTPUT(output, TensorType::ALL())
  285. .GRAPH(f)
  286. .ATTR(config, String, "")
  287. .ATTR(config_proto, String, "")
  288. .ATTR(executor_type, String, "")
  289. .OP_END_FACTORY_REG(StatefulPartitionedCall)
  290. /**
  291. * @par Inputs:
  292. * @li input: The input tensors \n
  293. *
  294. * @par Outputs:
  295. * @li output: The output tensors. \n
  296. */
  297. REG_OP(ToBool)
  298. .INPUT(input, TensorType({DT_INT64, DT_INT32, DT_INT16, DT_INT8, \
  299. DT_UINT8, DT_FLOAT, DT_DOUBLE, DT_STRING, DT_BOOL}))
  300. .OUTPUT(output, DT_BOOL)
  301. .OP_END_FACTORY_REG(ToBool)
  302. /**
  303. * @brief Abstract tiling function to an op definition
  304. * The input will be data or shape \n
  305. * @par Inputs:
  306. * @li x: the data of input. all types are available,
  307. * @li outputshape: the shape of previous op output shape . all types are available. \n
  308. * @par Outputs:
  309. * @li tiling_data: tiling data of tiling function. It should be a buffer
  310. * @li tiling_key: tiling key of tiling function.
  311. * @li block_dim: block dim of tiling function.
  312. * @li tiling_cond: tiling condition of tiling function which will be used to determined real execute kernel. \n
  313. * @par Attributes:
  314. * @li tiling_node: A string. real tiling node such as matmul.
  315. * @li op_type: A string. Op type of the original node. \n
  316. * @par Third-party framework compatibility
  317. */
  318. REG_OP(OpTiling)
  319. .DYNAMIC_INPUT(x, TensorType::ALL())
  320. .DYNAMIC_INPUT(output_shape, TensorType::ALL())
  321. .OUTPUT(tiling_data, TensorType({DT_UINT8}))
  322. .OUTPUT(tiling_key, TensorType({DT_UINT64}))
  323. .OUTPUT(block_dim, TensorType({DT_INT32}))
  324. .OUTPUT(tiling_cond, TensorType({DT_INT32}))
  325. .REQUIRED_ATTR(tiling_node, String)
  326. .REQUIRED_ATTR(op_type, String)
  327. .OP_END_FACTORY_REG(OpTiling)
  328. /**
  329. * @brief Calculate condition value by input tensor which will be used for if input or case input. \n
  330. * @par Inputs:
  331. * @li x: the data or shape of input. all types are available,
  332. * @par Outputs:
  333. * @li cond: condition value calculated by cond fuction.
  334. It will be cond input of if or branch_index input of case. \n
  335. * @par Attributes:
  336. * @li cond_func: A string. real condition function registered to calculate condition value.
  337. * @li x_dependency: List of int. It should be the same number of inputs: 0(shape) 1(data). \n
  338. * @par Third-party framework compatibility
  339. */
  340. REG_OP(ConditionCalc)
  341. .DYNAMIC_INPUT(x, TensorType::ALL())
  342. .OUTPUT(cond, TensorType({DT_INT32}))
  343. .REQUIRED_ATTR(cond_func, String)
  344. .REQUIRED_ATTR(x_dependency, ListInt)
  345. .OP_END_FACTORY_REG(ConditionCalc)
  346. } // namespace ge
  347. #endif // OPS_BUILT_IN_OP_PROTO_INC_FUNCTIONAL_OPS_H_

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