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.

lookup_ops.h 11 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
3 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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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 lookup_ops.h
  18. * \brief
  19. */
  20. #ifndef OPS_BUILT_IN_OP_PROTO_INC_LOOKUP_OPS_H_
  21. #define OPS_BUILT_IN_OP_PROTO_INC_LOOKUP_OPS_H_
  22. #include "graph/operator_reg.h"
  23. namespace ge {
  24. /**
  25. *@brief Replaces the contents of the table with the specified keys and values . \n
  26. *@par Inputs:
  27. *The dtype of input handle must be resource. Inputs include:
  28. *@li handle: A Tensor of type resource. Handle to the table.
  29. *@li keys: A Tensor. Any shape. Keys to look up.
  30. *@li values: A Tensor. Values to associate with keys . \n
  31. *@par Third-party framework compatibility.
  32. *Compatible with tensorflow LookupTableImport operator.
  33. */
  34. REG_OP(LookupTableImport)
  35. .INPUT(handle, TensorType({DT_RESOURCE}))
  36. .INPUT(keys, TensorType({DT_STRING, DT_INT32, DT_INT64}))
  37. .INPUT(values, TensorType({DT_BOOL, DT_DOUBLE, \
  38. DT_FLOAT, DT_INT32, DT_INT64, DT_STRING}))
  39. .OP_END_FACTORY_REG(LookupTableImport)
  40. /**
  41. *@brief Updates the table to associates keys with values . \n
  42. *@par Inputs:
  43. *The dtype of input handle must be resource. Inputs include:
  44. *@li handle: A Tensor of type resource. Handle to the table.
  45. *@li keys: A Tensor. Any shape. Keys to look up.
  46. *@li values: A Tensor. Values to associate with keys . \n
  47. *@attention Constraints:
  48. *@li The tensor keys must be of the same type as the keys of the table.
  49. *@li The tensor values must be of the type of the table values.
  50. *@par Third-party framework compatibility.
  51. *Compatible with tensorflow LookupTableInsert operator.
  52. */
  53. REG_OP(LookupTableInsert)
  54. .INPUT(handle, TensorType({DT_RESOURCE}))
  55. .INPUT(keys, TensorType({DT_STRING, DT_INT32, DT_INT64}))
  56. .INPUT(values, TensorType({DT_BOOL, DT_DOUBLE, DT_FLOAT, \
  57. DT_INT32, DT_INT64, DT_STRING}))
  58. .OP_END_FACTORY_REG(LookupTableInsert)
  59. /**
  60. *@brief Outputs all keys and values in the table . \n
  61. *@par Inputs:
  62. *The dtype of input handle must be resource. Inputs include:
  63. *handle: A Tensor of type resource. Handle to the table . \n
  64. *@par Attributes:
  65. *@li Tkeys: A DType of keys.
  66. *@li Tvalues: A DType of values.
  67. *@par Outputs:
  68. *@li keys: A Tensor of type Tkeys.
  69. *@li values: A Tensor of type Tvalues . \n
  70. *@par Third-party framework compatibility.
  71. *Compatible with tensorflow LookupTableExport operator.
  72. */
  73. REG_OP(LookupTableExport)
  74. .INPUT(handle, TensorType({DT_RESOURCE}))
  75. .OUTPUT(keys, TensorType({DT_INT32, DT_INT64, DT_STRING}))
  76. .OUTPUT(values, TensorType({DT_BOOL, DT_DOUBLE, DT_FLOAT, \
  77. DT_INT32, DT_INT64, DT_STRING}))
  78. .REQUIRED_ATTR(Tkeys, Type)
  79. .REQUIRED_ATTR(Tvalues, Type)
  80. .OP_END_FACTORY_REG(LookupTableExport)
  81. /**
  82. *@brief Computes the number of elements in the given table . \n
  83. *@par Inputs:
  84. *The dtype of input handle must be resource. Inputs include:
  85. *handle: A Tensor of type resource. Handle to the table . \n
  86. *@par Outputs:
  87. *size: A Tensor of type int64 . \n
  88. *@par Third-party framework compatibility.
  89. *Compatible with tensorflow LookupTableSize operator.
  90. */
  91. REG_OP(LookupTableSize)
  92. .INPUT(handle, TensorType({DT_RESOURCE}))
  93. .OUTPUT(size, TensorType({DT_INT64}))
  94. .OP_END_FACTORY_REG(LookupTableSize)
  95. /**
  96. *@brief Looks up keys in a table, outputs the corresponding values . \n
  97. *@par Inputs:
  98. *The dtype of input handle must be resource. Inputs include:
  99. *@li handle: A Tensor of type resource. Handle to the table.
  100. *@li keys: A Tensor. Any shape. Keys to look up.
  101. *@li default_value: A Tensor . \n
  102. *@par Attributes:
  103. *Tout: Specified type of ouput values . \n
  104. *@par Outputs:
  105. *values: A Tensor. Has the same type as default_value . \n
  106. *@par Third-party framework compatibility.
  107. *Compatible with tensorflow LookupTableFind operator.
  108. */
  109. REG_OP(LookupTableFind)
  110. .INPUT(handle, TensorType({DT_RESOURCE}))
  111. .INPUT(keys, TensorType({DT_INT32, DT_INT64, DT_STRING}))
  112. .INPUT(default_value, TensorType({DT_DOUBLE, DT_FLOAT, \
  113. DT_INT32, DT_INT64, DT_STRING, DT_BOOL}))
  114. .OUTPUT(values, TensorType({DT_DOUBLE, DT_FLOAT, DT_INT32, \
  115. DT_INT64, DT_STRING, DT_BOOL}))
  116. .REQUIRED_ATTR(Tout, Type)
  117. .OP_END_FACTORY_REG(LookupTableFind)
  118. /**
  119. *@brief Creates a non-initialized hash table . \n
  120. *@par Attributes:
  121. *@li container: An optional string. Defaults to "". If non-empty, this table
  122. is placed in the given container. Otherwise, a default container is used.
  123. *@li shared_name: An optional string. Defaults to "". If non-empty, this
  124. table is shared under the given name across multiple sessions.
  125. *@li use_node_name_sharing: An optional bool. Defaults to False. If true and
  126. shared_name is empty, the table is shared using the node name.
  127. *@li key_dtype: A DType. Type of the table keys.
  128. *@li value_dtype: A DType. Type of the table values . \n
  129. *@par Outputs:
  130. *handle: A Tensor of type resource. Handle to the table . \n
  131. *@attention Constraints:
  132. *The implementation for HashTable on Ascend uses ai cpu, with bad performance.
  133. *@par Third-party framework compatibility.
  134. *Compatible with tensorflow HashTable operator.
  135. */
  136. REG_OP(HashTable)
  137. .OUTPUT(handle, TensorType({DT_RESOURCE}))
  138. .ATTR(container, String, "")
  139. .ATTR(shared_name, String, "")
  140. .ATTR(use_node_name_sharing, Bool, false)
  141. .REQUIRED_ATTR(key_dtype, Type)
  142. .REQUIRED_ATTR(value_dtype, Type)
  143. .OP_END_FACTORY_REG(HashTable)
  144. /**
  145. *@brief Table initializer that takes two tensors for keys and values
  146. respectively . \n
  147. *@par Inputs:
  148. *The dtype of input handle must be resource. Inputs include:
  149. *@li handle: A Tensor of type resource. Handle to a table which will be
  150. initialized.
  151. *@li keys: A Tensor. Keys of type Tkey.
  152. *@li values: A Tensor. Values of type Tval . \n
  153. *@par Third-party framework compatibility.
  154. *Compatible with tensorflow InitializeTable operator.
  155. */
  156. REG_OP(InitializeTable)
  157. .INPUT(handle, TensorType({DT_RESOURCE}))
  158. .INPUT(keys, TensorType({DT_INT32, DT_INT64, DT_STRING}))
  159. .INPUT(values, TensorType({DT_INT32, DT_INT64, DT_FLOAT, \
  160. DT_DOUBLE, DT_BOOL, DT_STRING}))
  161. .OP_END_FACTORY_REG(InitializeTable)
  162. /**
  163. *@brief Creates an empty hash table that uses tensors as the backing store . \n
  164. *@par Inputs:
  165. *The input deleted_key must have the same type as empty_key. Inputs include:
  166. *@li empty_key: A Tensor. The key used to represent empty key buckets
  167. internally. Must not be used in insert or lookup operations.
  168. *@li deleted_key: A Tensor. Must have the same type as empty_key . \n
  169. *@par Attributes:
  170. *@li container: An optional string. Defaults to "". If non-empty, this table
  171. is placed in the given container. Otherwise, a default container is used.
  172. *@li shared_name: An optional string. Defaults to "". If non-empty, this
  173. table is shared under the given name across multiple sessions.
  174. *@li use_node_name_sharing: An optional bool. Defaults to False. If true and
  175. shared_name is empty, the table is shared using the node name.
  176. *@li value_dtype: A DType. Type of the table values.
  177. *@li value_shape: An optional TensorShape or list of ints. Defaults to [].
  178. The shape of each value.
  179. *@li initial_num_buckets: An optional int. Defaults to 131072. The initial
  180. number of hash table buckets. Must be a power to 2.
  181. *@li max_load_factor: An optional float. Defaults to 0.8. The maximum ratio
  182. between number of entries and number of buckets before growing the table.
  183. Must be between 0 and 1 . \n
  184. *@par Outputs:
  185. *handle: A Tensor of type resource. Handle to the table . \n
  186. *@par Third-party framework compatibility.
  187. *Compatible with tensorflow MutableDenseHashTable operator.
  188. */
  189. REG_OP(MutableDenseHashTable)
  190. .INPUT(empty_key, TensorType({DT_INT32, DT_INT64, DT_STRING}))
  191. .INPUT(deleted_key, TensorType({DT_INT32, DT_INT64, DT_STRING}))
  192. .OUTPUT(handle, TensorType({DT_RESOURCE}))
  193. .ATTR(container, String, "")
  194. .ATTR(shared_name, String, "")
  195. .ATTR(use_node_name_sharing, Bool, false)
  196. .REQUIRED_ATTR(value_dtype, Type)
  197. .ATTR(value_shape, ListInt, {})
  198. .ATTR(initial_num_buckets, Int, 131072)
  199. .ATTR(max_load_factor, Float, 0.8)
  200. .OP_END_FACTORY_REG(MutableDenseHashTable)
  201. /**
  202. *@brief Creates an empty hash table . \n
  203. *@par Attributes:
  204. *@li container: An optional string. Defaults to "". If non-empty, this table
  205. is placed in the given container. Otherwise, a default container is used.
  206. *@li shared_name: An optional string. Defaults to "". If non-empty, this
  207. table is shared under the given name across multiple sessions.
  208. *@li use_node_name_sharing: An optional bool. Defaults to False. If true and
  209. shared_name is empty, the table is shared using the node name.
  210. *@li key_dtype: A DType. Type of the table keys.
  211. *@li value_dtype: A DType. Type of the table values.
  212. *@li value_shape: An optional TensorShape or list of ints. Defaults to [] . \n
  213. *@par Outputs:
  214. *handle: A Tensor of type resource. Handle to the table . \n
  215. *@par Third-party framework compatibility.
  216. *Compatible with tensorflow MutableHashTableOfTensors operator.
  217. */
  218. REG_OP(MutableHashTableOfTensors)
  219. .OUTPUT(handle, TensorType({DT_RESOURCE}))
  220. .ATTR(container, String, "")
  221. .ATTR(shared_name, String, "")
  222. .ATTR(use_node_name_sharing, Bool, false)
  223. .REQUIRED_ATTR(key_dtype, Type)
  224. .REQUIRED_ATTR(value_dtype, Type)
  225. .ATTR(value_shape, ListInt, {})
  226. .OP_END_FACTORY_REG(MutableHashTableOfTensors)
  227. /**
  228. *@brief Creates an empty hash table . \n
  229. *@par Attributes:
  230. *@li container: An optional string. Defaults to "". If non-empty, this table
  231. is placed in the given container. Otherwise, a default container is used.
  232. *@li shared_name: An optional string. Defaults to "". If non-empty, this
  233. table is shared under the given name across multiple sessions.
  234. *@li use_node_name_sharing: An optional bool. Defaults to False. If true and
  235. shared_name is empty, the table is shared using the node name.
  236. *@li key_dtype: A DType. Type of the table keys.
  237. *@li value_dtype: A DType. Type of the table values . \n
  238. *@par Outputs:
  239. *handle: A Tensor of type resource. Handle to the table . \n
  240. *@par Third-party framework compatibility.
  241. *Compatible with tensorflow MutableHashTable operator.
  242. */
  243. REG_OP(MutableHashTable)
  244. .OUTPUT(handle, TensorType({DT_RESOURCE}))
  245. .ATTR(container, String, "")
  246. .ATTR(shared_name, String, "")
  247. .ATTR(use_node_name_sharing, Bool, false)
  248. .REQUIRED_ATTR(key_dtype, Type)
  249. .REQUIRED_ATTR(value_dtype, Type)
  250. .OP_END_FACTORY_REG(MutableHashTable)
  251. } // namespace ge
  252. #endif // OPS_BUILT_IN_OP_PROTO_INC_LOOKUP_OPS_H_

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