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

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