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.

list_ops.h 7.5 kB

4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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 list_ops.h
  18. * \brief
  19. */
  20. #ifndef OPS_BUILT_IN_OP_PROTO_INC_LIST_OPS_H_
  21. #define OPS_BUILT_IN_OP_PROTO_INC_LIST_OPS_H_
  22. #include <algorithm>
  23. #include "graph/operator_reg.h"
  24. #include "graph/operator.h"
  25. namespace ge {
  26. /**
  27. *@brief Creates and returns an empty tensor list. \n
  28. *@par Inputs:
  29. *@li element_shape: A shape compatible with that of elements in the list.
  30. *@li max_num_elements: The maximum number of elements. \n
  31. *@par Attributes:
  32. *@li element_dtype: The type of elements in the list. \n
  33. *@par Outputs:
  34. *@li handle: An empty tensor list . \n
  35. *@par Third-party framework compatibility.
  36. *Compatible with tensorflow EmptyTensorList operator.
  37. */
  38. REG_OP(EmptyTensorList)
  39. .INPUT(element_shape, TensorType({DT_INT32,DT_INT64}))
  40. .INPUT(max_num_elements, TensorType({DT_INT32}))
  41. .OUTPUT(handle, TensorType({DT_VARIANT}))
  42. .ATTR(element_dtype, Type, DT_INT32)
  43. .OP_END_FACTORY_REG(EmptyTensorList)
  44. /**
  45. *@brief Returns a list which has the passed-in `Tensor` as last element
  46. and the other elements of the given list in `input_handle`. \n
  47. *@par Inputs:
  48. *@li input_handle: The old list.
  49. *@li tensor: The tensor to put on the list. \n
  50. *@par Attributes:
  51. *@li element_dtype: The type of elements in the list. \n
  52. *@par Outputs:
  53. *@li output_handle:A list with the elements of old list followed by tensor. \n
  54. *@par Third-party framework compatibility.
  55. *Compatible with tensorflow TensorListPushBack operator.
  56. */
  57. REG_OP(TensorListPushBack)
  58. .INPUT(input_handle, TensorType({DT_VARIANT}))
  59. .INPUT(tensor, TensorType({DT_FLOAT16,DT_FLOAT,DT_DOUBLE,DT_INT8,
  60. DT_INT16,DT_INT32,DT_INT64,DT_UINT8,DT_UINT16,DT_QINT8,DT_QUINT8,
  61. DT_QINT16,DT_QUINT16,DT_QINT32,DT_BOOL,DT_RESOURCE,
  62. DT_STRING,DT_COMPLEX64,DT_COMPLEX128}))
  63. .OUTPUT(output_handle, TensorType({DT_VARIANT}))
  64. .ATTR(element_dtype, Type, DT_INT32)
  65. .OP_END_FACTORY_REG(TensorListPushBack)
  66. /**
  67. *@brief The last element of the input list as well as a
  68. list with all but that element. \n
  69. *@par Inputs:
  70. *@li input_handle: The input list.
  71. *@li element_shape: A shape compatible with that of elements in the list. \n
  72. *@par Attributes:
  73. *@li element_dtype: The type of elements in the list. \n
  74. *@par Outputs:
  75. *@li output_handle:A list with the elements of the old list followed by tensor.
  76. *@li tensor:The withdrawn last element of the list. \n
  77. *@par Third-party framework compatibility.
  78. *Compatible with tensorflow TensorListPopBack operator.
  79. */
  80. REG_OP(TensorListPopBack)
  81. .INPUT(input_handle, TensorType({DT_VARIANT}))
  82. .INPUT(element_shape, TensorType({DT_INT32}))
  83. .OUTPUT(output_handle, TensorType({DT_VARIANT}))
  84. .OUTPUT(tensor, TensorType({DT_FLOAT16,DT_FLOAT,DT_DOUBLE,DT_INT8,
  85. DT_INT16,DT_INT32,DT_INT64,DT_UINT8,DT_UINT16,DT_QINT8,DT_QUINT8,
  86. DT_QINT16,DT_QUINT16,DT_QINT32,DT_BOOL,DT_RESOURCE,
  87. DT_STRING,DT_COMPLEX64,DT_COMPLEX128}))
  88. .ATTR(element_dtype, Type, DT_INT32)
  89. .OP_END_FACTORY_REG(TensorListPopBack)
  90. /**
  91. *@brief The number of tensors in the input tensor list. \n
  92. *@par Inputs:
  93. *@li input_handle: The input list. \n
  94. *@par Outputs:
  95. *@li length:The number of tensors in the list. \n
  96. *@par Third-party framework compatibility.
  97. *Compatible with tensorflow TensorListLength operator.
  98. */
  99. REG_OP(TensorListLength)
  100. .INPUT(input_handle, TensorType({DT_VARIANT}))
  101. .OUTPUT(length, TensorType({DT_INT32}))
  102. .OP_END_FACTORY_REG(TensorListLength)
  103. /**
  104. *@brief The shape of elements in the input tensor list. \n
  105. *@par Inputs:
  106. *@li input_handle: The input list. \n
  107. *@par Attributes:
  108. *@li shape_type: The type of shape in the list. \n
  109. *@par Outputs:
  110. *@li element_shape:A shape compatible with that of elements in the list. \n
  111. *@par Third-party framework compatibility.
  112. *Compatible with tensorflow TensorListElementShape operator.
  113. */
  114. REG_OP(TensorListElementShape)
  115. .INPUT(input_handle, TensorType({DT_VARIANT}))
  116. .OUTPUT(element_shape, TensorType({DT_INT32,DT_INT64}))
  117. .ATTR(shape_type, Type, DT_INT32)
  118. .OP_END_FACTORY_REG(TensorListElementShape)
  119. /**
  120. *@brief List of the given size with empty elements. \n
  121. *@par Inputs:
  122. *@li element_shape: A shape compatible with that of elements in the list.
  123. *@li num_elements: The number of elements to reserve. \n
  124. *@par Attributes:
  125. *@li element_dtype: The type of elements in the list.
  126. *@li shape_type: The type of shape in the list. \n
  127. *@par Outputs:
  128. *@li handle: An output tensor list . \n
  129. *@par Third-party framework compatibility.
  130. *Compatible with tensorflow TensorListReserve operator.
  131. */
  132. REG_OP(TensorListReserve)
  133. .INPUT(element_shape, TensorType({DT_INT32,DT_INT64}))
  134. .INPUT(num_elements, TensorType({DT_INT32}))
  135. .OUTPUT(handle, TensorType({DT_VARIANT}))
  136. .ATTR(element_dtype, Type, DT_INT32)
  137. .ATTR(shape_type, Type, DT_INT32)
  138. .OP_END_FACTORY_REG(TensorListReserve)
  139. /**
  140. *@brief Get input tensor list elements of index position. \n
  141. *@par Inputs:
  142. *@li input_handle: The input list.
  143. *@li index: A tensor of position.
  144. *@li element_shape: A shape compatible with that of elements in the list. \n
  145. *@par Attributes:
  146. *@li element_dtype: The type of elements in the list. \n
  147. *@par Outputs:
  148. *@li item: An output tensor value of index position . \n
  149. *@par Third-party framework compatibility.
  150. *Compatible with tensorflow TensorListGetItem operator.
  151. */
  152. REG_OP(TensorListGetItem)
  153. .INPUT(input_handle, TensorType({DT_VARIANT}))
  154. .INPUT(index, TensorType({DT_INT32}))
  155. .INPUT(element_shape, TensorType({DT_INT32}))
  156. .OUTPUT(item, TensorType({DT_FLOAT16,DT_FLOAT,DT_DOUBLE,DT_INT8,
  157. DT_INT16,DT_INT32,DT_INT64,DT_UINT8,DT_UINT16,DT_QINT8,DT_QUINT8,
  158. DT_QINT16,DT_QUINT16,DT_QINT32,DT_BOOL,
  159. DT_STRING,DT_COMPLEX64,DT_COMPLEX128}))
  160. .ATTR(element_dtype, Type, DT_INT32)
  161. .OP_END_FACTORY_REG(TensorListGetItem)
  162. /**
  163. *@brief Sets the index-th position of the list to contain the given tensor. \n
  164. *@par Inputs:
  165. *@li input_handle: The input list.
  166. *@li index: The position in the list to which the tensor will be assigned.
  167. *@li item: The element to be assigned to that position. \n
  168. *@par Attributes:
  169. *@li element_dtype: The type of elements in the list. \n
  170. *@par Outputs:
  171. *@li output_handle: An output tensor list . \n
  172. *@par Third-party framework compatibility.
  173. *Compatible with tensorflow TensorListSetItem operator.
  174. */
  175. REG_OP(TensorListSetItem)
  176. .INPUT(input_handle, TensorType({DT_VARIANT}))
  177. .INPUT(index, TensorType({DT_INT32}))
  178. .INPUT(item, TensorType({DT_FLOAT16,DT_FLOAT,DT_DOUBLE,DT_INT8,
  179. DT_INT16,DT_INT32,DT_INT64,DT_UINT8,DT_UINT16,DT_QINT8,DT_QUINT8,
  180. DT_QINT16,DT_QUINT16,DT_QINT32,DT_BOOL,DT_RESOURCE,
  181. DT_STRING,DT_COMPLEX64,DT_COMPLEX128}))
  182. .OUTPUT(output_handle, TensorType({DT_VARIANT}))
  183. .ATTR(element_dtype, Type, DT_INT32)
  184. .OP_END_FACTORY_REG(TensorListSetItem)
  185. } // namespace ge
  186. #endif // OPS_BUILT_IN_OP_PROTO_INC_LIST_OPS_H_

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