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.

parsing_ops.h 12 kB

5 years ago
5 years ago
5 years ago
5 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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 parsing_ops.h
  18. * \brief
  19. */
  20. #ifndef OPS_BUILT_IN_OP_PROTO_INC_PARSING_OPS_H_
  21. #define OPS_BUILT_IN_OP_PROTO_INC_PARSING_OPS_H_
  22. #include "graph/operator_reg.h"
  23. #include "graph/operator.h"
  24. namespace ge {
  25. /**
  26. *@brief Converts each string in the input Tensor to the specified numeric type . \n
  27. *@par Inputs:
  28. *Inputs include:
  29. *x: A Tensor. Must be one of the following types: string . \n
  30. *@par Attributes:
  31. *out_type: The numeric type to interpret each string in string_tensor as . \n
  32. *@par Outputs:
  33. *y: A Tensor. Has the same type as x . \n
  34. *@attention Constraints:
  35. *The implementation for StringToNumber on Ascend uses AICPU, with bad performance. \n
  36. *@par Third-party framework compatibility
  37. *@li compatible with tensorflow StringToNumber operator.
  38. */
  39. REG_OP(StringToNumber)
  40. .INPUT(x, TensorType({DT_STRING}))
  41. .OUTPUT(y, TensorType({DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64}))
  42. .ATTR(out_type, Type, DT_FLOAT)
  43. .OP_END_FACTORY_REG(StringToNumber)
  44. /**
  45. *@brief Convert serialized tensorflow.TensorProto prototype to Tensor.
  46. *@brief Parse an Example prototype.
  47. *@par Inputs:
  48. *@li serialized: A Tensor of type string.
  49. *@li dense_defaults: DYNAMIC INPUT Tensor type as string, float, int64. \n
  50. *@par Attributes:
  51. *@li num_sparse: type int num of inputs sparse_indices , sparse_values, sparse_shapes
  52. *@li sparse_keys: ListString
  53. *@li sparse_types: types of sparse_values
  54. *@li dense_keys: ListString
  55. *@li Tdense: output of dense_defaults type
  56. *@li dense_shapes: output of dense_defaults shape \n
  57. *@par Outputs:
  58. *@li sparse_indices: A Tensor of type string.
  59. *@li sparse_values: Has the same type as sparse_types.
  60. *@li sparse_shapes: A Tensor of type int64
  61. *@li dense_values: Has the same type as dense_defaults.
  62. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  63. */
  64. REG_OP(ParseSingleExample)
  65. .INPUT(serialized, TensorType({DT_STRING}))
  66. .DYNAMIC_INPUT(dense_defaults, TensorType({DT_STRING,DT_FLOAT,DT_INT64}))
  67. .DYNAMIC_OUTPUT(sparse_indices, TensorType({DT_INT64}))
  68. .DYNAMIC_OUTPUT(sparse_values, TensorType({DT_STRING,DT_FLOAT,DT_INT64}))
  69. .DYNAMIC_OUTPUT(sparse_shapes, TensorType({DT_INT64}))
  70. .DYNAMIC_OUTPUT(dense_values, TensorType({DT_STRING,DT_FLOAT,DT_INT64}))
  71. .ATTR(num_sparse, Int, 0)
  72. .ATTR(sparse_keys, ListString, {})
  73. .ATTR(dense_keys, ListString, {})
  74. .ATTR(sparse_types, ListType, {})
  75. .ATTR(Tdense, ListType, {})
  76. .ATTR(dense_shapes, ListListInt, {})
  77. .OP_END_FACTORY_REG(ParseSingleExample)
  78. /**
  79. *@brief Decodes raw file into tensor . \n
  80. *@par Inputs:
  81. *bytes: A Tensor of type string.
  82. *@par Attributes:
  83. *@li little_endian: bool ture
  84. *@li out_type: output type
  85. *@par Outputs:
  86. *Output: A Tensor
  87. */
  88. REG_OP(DecodeRaw)
  89. .INPUT(bytes, TensorType({DT_STRING}))
  90. .OUTPUT(output, TensorType({DT_BOOL,DT_FLOAT16,DT_DOUBLE,DT_FLOAT,
  91. DT_INT64,DT_INT32,DT_INT8,DT_UINT8,DT_INT16,
  92. DT_UINT16,DT_COMPLEX64,DT_COMPLEX128}))
  93. .ATTR(out_type, Type, DT_FLOAT)
  94. .ATTR(little_endian, Bool, true)
  95. .OP_END_FACTORY_REG(DecodeRaw)
  96. /**
  97. *@brief Convert serialized tensorflow.TensorProto prototype to Tensor. \n
  98. *@par Inputs:
  99. *serialized: A Tensor of string type. Scalar string containing serialized
  100. *TensorProto prototype. \n
  101. *@par Attributes:
  102. *out_type: The type of the serialized tensor. The provided type must match the
  103. *type of the serialized tensor and no implicit conversion will take place. \n
  104. *@par Outputs:
  105. *output: A Tensor of type out_type. \n
  106. *@attention Constraints:
  107. *The implementation for StringToNumber on Ascend uses AICPU,
  108. *with badperformance. \n
  109. *@par Third-party framework compatibility
  110. *@li compatible with tensorflow ParseTensor operator.
  111. */
  112. REG_OP(ParseTensor)
  113. .INPUT(serialized, TensorType({DT_STRING}))
  114. .OUTPUT(output, TensorType(DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16,
  115. DT_UINT16, DT_UINT8, DT_INT32, DT_INT64, DT_UINT32,
  116. DT_UINT64, DT_BOOL, DT_DOUBLE, DT_STRING,
  117. DT_COMPLEX64, DT_COMPLEX128}))
  118. .ATTR(out_type, Type, DT_FLOAT)
  119. .OP_END_FACTORY_REG(ParseTensor)
  120. /**
  121. *@brief Converts each string in the input Tensor to the specified numeric
  122. *type . \n
  123. *@par Inputs:
  124. *Inputs include:
  125. *@li records: Each string is a record/row in the csv and all records should have the
  126. *same format. \n
  127. *@li record_defaults: One tensor per column of the input record, with either a
  128. *scalar default value for that column or an empty vector if the column is
  129. *required. \n
  130. *@par Attributes:
  131. *@li OUT_TYPE: The numeric type to interpret each string in string_tensor as . \n
  132. *@li field_delim: char delimiter to separate fields in a record. \n
  133. *@li use_quote_delim: If false, treats double quotation marks as regular characters
  134. *inside of the string fields (ignoring RFC 4180, Section 2, Bullet 5). \n
  135. *@li na_value: Additional string to recognize as NA/NaN. \n
  136. *@li select_cols: Optional sorted list of column indices to select. If specified,
  137. only this subset of columns will be parsed and returned.
  138. *@par Outputs:
  139. *output: A Tensor. Has the same type as x . \n
  140. *@attention Constraints:
  141. *The implementation for StringToNumber on Ascend uses AICPU, with bad
  142. *performance. \n
  143. *@par Third-party framework compatibility
  144. *@li compatible with tensorflow StringToNumber operator.
  145. */
  146. REG_OP(DecodeCSV)
  147. .INPUT(records, TensorType({DT_STRING}))
  148. .DYNAMIC_INPUT(record_defaults, TensorType({DT_FLOAT, DT_DOUBLE, DT_INT32,
  149. DT_INT64, DT_STRING}))
  150. .DYNAMIC_OUTPUT(output, TensorType({DT_FLOAT, DT_DOUBLE, DT_INT32,
  151. DT_INT64, DT_STRING}))
  152. .ATTR(OUT_TYPE, ListType, {})
  153. .ATTR(field_delim, String, ",")
  154. .ATTR(use_quote_delim, Bool, true)
  155. .ATTR(na_value, String, ",")
  156. .ATTR(select_cols, ListInt, {})
  157. .OP_END_FACTORY_REG(DecodeCSV)
  158. /**
  159. *@brief Convert serialized tensorflow.TensorProto prototype to Tensor.
  160. *@brief Parse an Example prototype.
  161. *@par Inputs:
  162. *@li serialized: A Tensor of type string. \n
  163. *@li name:A Tensor of type string. \n
  164. *@li sparse_keys: Dynamic input tensor of string. \n
  165. *@li dense_keys: Dynamic input tensor of string \n
  166. *@li dense_defaults: Dynamic input tensor type as string, float, int64. \n
  167. *@par Attributes:
  168. *@li Nsparse: Number of sparse_keys, sparse_indices and sparse_shapes \n
  169. *@li Ndense: Number of dense_keys \n
  170. *@li sparse_types: types of sparse_values \n
  171. *@li Tdense: Type of dense_defaults dense_defaults and dense_values \n
  172. *@li dense_shapes: output of dense_defaults shape \n
  173. *@par Outputs:
  174. *@li sparse_indices: A Tensor of type string. \n
  175. *@li sparse_values: Has the same type as sparse_types. \n
  176. *@li sparse_shapes: A Tensor of type int64 \n
  177. *@li dense_values: Has the same type as dense_defaults. \n
  178. *@par Third-party framework compatibility \n
  179. *@li compatible with tensorflow StringToNumber operator. \n
  180. */
  181. REG_OP(ParseExample)
  182. .INPUT(serialized, TensorType({DT_STRING}))
  183. .INPUT(name, TensorType({DT_STRING}))
  184. .DYNAMIC_INPUT(sparse_keys, TensorType({DT_STRING}))
  185. .DYNAMIC_INPUT(dense_keys, TensorType({DT_STRING}))
  186. .DYNAMIC_INPUT(dense_defaults, TensorType({DT_FLOAT, DT_INT64, DT_STRING}))
  187. .DYNAMIC_OUTPUT(sparse_indices, TensorType({DT_INT64}))
  188. .DYNAMIC_OUTPUT(sparse_values, TensorType({DT_FLOAT, DT_INT64, DT_STRING}))
  189. .DYNAMIC_OUTPUT(sparse_shapes, TensorType({DT_INT64}))
  190. .DYNAMIC_OUTPUT(dense_values, TensorType({DT_FLOAT, DT_INT64, DT_STRING}))
  191. .ATTR(Nsparse, Int, 0)
  192. .ATTR(Ndense, Int, 0)
  193. .ATTR(sparse_types, ListType, {})
  194. .ATTR(Tdense, ListType, {})
  195. .ATTR(dense_shapes, ListListInt, {})
  196. .OP_END_FACTORY_REG(ParseExample)
  197. /**
  198. *@brief Transforms a scalar brain.SequenceExample proto (as strings) into typed
  199. *tensors.
  200. *@par Inputs:
  201. *@li serialized: A Tensor of type string. \n
  202. *@li feature_list_dense_missing_assumed_empty:A Tensor of type string. \n
  203. *@li context_sparse_keys: Dynamic input tensor of string. \n
  204. *@li context_dense_keys: Dynamic input tensor of string \n
  205. *@li feature_list_sparse_keys: Dynamic input tensor of string \n
  206. *@li feature_list_dense_keys: Dynamic input tensor of string \n
  207. *@li context_dense_defaults: Dynamic input tensor of string, float, int64 \n
  208. *@li debug_name: A Tensor of type string. \n
  209. *@par Attributes:
  210. *@li Ncontext_sparse: Number of context_sparse_keys, context_sparse_indices and context_sparse_shapes \n
  211. *@li Ncontext_dense: Number of context_dense_keys \n
  212. *@li Nfeature_list_sparse: Number of feature_list_sparse_keys \n
  213. *@li Nfeature_list_dense: Number of feature_list_dense_keys \n
  214. *@li context_sparse_types: Types of context_sparse_values \n
  215. *@li Tcontext_dense: Number of dense_keys \n
  216. *@li feature_list_dense_types: Types of feature_list_dense_values \n
  217. *@li context_dense_shapes: Shape of context_dense \n
  218. *@li feature_list_sparse_types: Type of feature_list_sparse_values \n
  219. *@li feature_list_dense_shapes: Shape of feature_list_dense \n
  220. *@par Outputs:
  221. *@li context_sparse_indices: Dynamic output tensor of type int64. \n
  222. *@li context_sparse_values: Dynamic output tensor of type string, float, int64. \n
  223. *@li context_sparse_shapes: Dynamic output tensor of type int64 \n
  224. *@li context_dense_values: Dynamic output tensor of type string, float, int64. \n
  225. *@li feature_list_sparse_indices: Dynamic output tensor of type int64. \n
  226. *@li feature_list_sparse_values: Dynamic output tensor of type string, float, int64. \n
  227. *@li feature_list_sparse_shapes: Dynamic output tensor of type int64 \n
  228. *@li feature_list_dense_values: Dynamic output tensor of type string, float, int64. \n
  229. *@par Third-party framework compatibility \n
  230. *@li compatible with tensorflow StringToNumber operator. \n
  231. */
  232. REG_OP(ParseSingleSequenceExample)
  233. .INPUT(serialized, TensorType({DT_STRING}))
  234. .INPUT(feature_list_dense_missing_assumed_empty, TensorType({DT_STRING}))
  235. .DYNAMIC_INPUT(context_sparse_keys, TensorType({DT_STRING}))
  236. .DYNAMIC_INPUT(context_dense_keys, TensorType({DT_STRING}))
  237. .DYNAMIC_INPUT(feature_list_sparse_keys, TensorType({DT_STRING}))
  238. .DYNAMIC_INPUT(feature_list_dense_keys, TensorType({DT_STRING}))
  239. .DYNAMIC_INPUT(context_dense_defaults, TensorType({DT_FLOAT, DT_INT64, DT_STRING}))
  240. .INPUT(debug_name, TensorType({DT_STRING}))
  241. .DYNAMIC_OUTPUT(context_sparse_indices, TensorType({DT_INT64}))
  242. .DYNAMIC_OUTPUT(context_sparse_values, TensorType({DT_FLOAT, DT_INT64, DT_STRING}))
  243. .DYNAMIC_OUTPUT(context_sparse_shapes, TensorType({DT_INT64}))
  244. .DYNAMIC_OUTPUT(context_dense_values, TensorType({DT_FLOAT, DT_INT64, DT_STRING}))
  245. .DYNAMIC_OUTPUT(feature_list_sparse_indices, TensorType({DT_INT64}))
  246. .DYNAMIC_OUTPUT(feature_list_sparse_values, TensorType({DT_FLOAT, DT_INT64, DT_STRING}))
  247. .DYNAMIC_OUTPUT(feature_list_sparse_shapes, TensorType({DT_INT64}))
  248. .DYNAMIC_OUTPUT(feature_list_dense_values, TensorType({DT_FLOAT, DT_INT64, DT_STRING}))
  249. .ATTR(Ncontext_sparse, Int, 0)
  250. .ATTR(Ncontext_dense, Int, 0)
  251. .ATTR(Nfeature_list_sparse, Int, 0)
  252. .ATTR(Nfeature_list_dense, Int, 0)
  253. .ATTR(context_sparse_types, ListType, {})
  254. .ATTR(Tcontext_dense, ListType, {})
  255. .ATTR(feature_list_dense_types, ListType, {})
  256. .ATTR(context_dense_shapes, ListListInt, {})
  257. .ATTR(feature_list_sparse_types, ListType, {})
  258. .ATTR(feature_list_dense_shapes, ListListInt, {})
  259. .OP_END_FACTORY_REG(ParseSingleSequenceExample)
  260. } // namespace ge
  261. #endif // OPS_BUILT_IN_OP_PROTO_INC_PARSING_OPS_H_

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