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.

sparse_ops.h 41 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
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
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
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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979
  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_SPARSE_OPS_H_
  17. #define GE_OP_SPARSE_OPS_H_
  18. #include "graph/operator_reg.h"
  19. namespace ge {
  20. /**
  21. *@brief Applies softmax to a batched ND SparseTensor.
  22. *@par Inputs:
  23. *The input must be a batched ND SparseTensor.
  24. * @li indices: A matrix Tensor of type int64. 2D. The indices of the SparseTensor.
  25. * @li values: A vector Tensor of type float or double. 1D. The values of the SparseTensor.
  26. * @li shape: A vector Tensor of type int64. 1D. The shape of the SparseTensor.
  27. *@par Outputs:
  28. *y: A vector Tensor. 1D. Has the same type as "values".
  29. */
  30. REG_OP(SparseSoftmax)
  31. .INPUT(indices, TensorType({DT_INT64}))
  32. .INPUT(values, TensorType({DT_FLOAT, DT_DOUBLE}))
  33. .INPUT(shape, TensorType({DT_INT64}))
  34. .OUTPUT(y, TensorType({DT_FLOAT, DT_DOUBLE}))
  35. .OP_END_FACTORY_REG(SparseSoftmax)
  36. /**
  37. *@brief Adds up a SparseTensor and a dense Tensor, producing a dense Tensor.
  38. *@par Inputs:
  39. *Inputs "x1_*" must be SparseTensors and "x2" must be a dense Tensor.
  40. * @li x1_indices: A matrix Tensor of type int32 or int64. 2D. The indices of the SparseTensor.
  41. * @li x1_values: The values of the SparseTensor. A vector Tensor. 1D.
  42. * @li x1_shape: A vector Tensor of type int32 or int64. 1D. The shape of the SparseTensor.
  43. * @li x2: A matrix Tensor. Has the same type and same shape as the SparseTensors.
  44. *@par Outputs:
  45. *y: A matrix Tensor. Has the same type and same shape as "x2".
  46. */
  47. REG_OP(SparseTensorDenseAdd)
  48. .INPUT(x1_indices, TensorType({DT_INT32, DT_INT64}))
  49. .INPUT(x1_values, TensorType({DT_INT64, DT_INT32, DT_UINT16, DT_INT16, DT_UINT8, DT_INT8, \
  50. DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_COMPLEX64, DT_COMPLEX128}))
  51. .INPUT(x1_shape, TensorType({DT_INT32, DT_INT64}))
  52. .INPUT(x2, TensorType({DT_INT64, DT_INT32, DT_UINT16, DT_INT16, DT_UINT8, DT_INT8, \
  53. DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_COMPLEX64, DT_COMPLEX128}))
  54. .OUTPUT(y, TensorType({DT_INT64, DT_INT32, DT_UINT16, DT_INT16, DT_UINT8, DT_INT8, \
  55. DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_COMPLEX64, DT_COMPLEX128}))
  56. .OP_END_FACTORY_REG(SparseTensorDenseAdd)
  57. /**
  58. *@brief Reorders a SparseTensor into the canonical, row-major ordering.
  59. *@par Inputs:
  60. * @li indices: A matrix Tensor of type int32 or int64. 2D. The indices of the SparseTensor.
  61. * @li values: Values of the SparseTensor. A vector Tensor. 1D.
  62. * @li shape: A vector Tensor of type int32 or int64. 1D. The shape of the SparseTensor.
  63. *@par Outputs:
  64. *@li y_indices: The indices of the SparseTensor. Has the same type as "indices".
  65. *@li y_values: The values of the SparseTensorr. Has the same type as "values".
  66. */
  67. REG_OP(SparseReorder)
  68. .INPUT(indices, TensorType({DT_INT64}))
  69. .INPUT(values, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, \
  70. DT_UINT16, DT_UINT8, DT_INT32, DT_INT64, DT_BOOL, DT_DOUBLE, \
  71. DT_COMPLEX64, DT_COMPLEX128, DT_RESOURCE, DT_STRING}))
  72. .INPUT(shape, TensorType({DT_INT64}))
  73. .OUTPUT(y_indices, TensorType({DT_INT64}))
  74. .OUTPUT(y_values, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, \
  75. DT_UINT16, DT_UINT8, DT_INT32, DT_INT64, DT_BOOL, DT_DOUBLE, \
  76. DT_COMPLEX64, DT_COMPLEX128, DT_RESOURCE, DT_STRING}))
  77. .OP_END_FACTORY_REG(SparseReorder)
  78. /**
  79. *@brief Reshapes a SparseTensor to represent values in a new dense shape.
  80. *@par Inputs:
  81. * @li indices: A matrix Tensor of type int64. 2D. The indices of the SparseTensor.
  82. * @li shape: A vector Tensor of type int64. 1D. The shape of the SparseTensor.
  83. * @li new_shape: A 1D Tensor of type int64. The requested new dense shape.
  84. *@par Outputs:
  85. *@li y_indices: A Tensor of type int64. The indices of the new dense shape.
  86. *@li y_shape: A Tensor of type int64. The shape of the new dense shape.
  87. */
  88. REG_OP(SparseReshape)
  89. .INPUT(indices, TensorType({DT_INT64}))
  90. .INPUT(shape, TensorType({DT_INT64}))
  91. .INPUT(new_shape, TensorType({DT_INT64}))
  92. .OUTPUT(y_indices, TensorType({DT_INT64}))
  93. .OUTPUT(y_shape, TensorType({DT_INT64}))
  94. .OP_END_FACTORY_REG(SparseReshape)
  95. /**
  96. *@brief Adds up a SparseTensor and a dense Tensor.
  97. *@par Inputs:
  98. *(1) Broadcasts the dense side to have the same shape as the sparse side, if eligible;\n
  99. *(2) Then, only the dense values pointed to by the indices of the SparseTensor participate in the cwise addition.
  100. * @li x1_indices: A matrix Tensor of type int64. 2D. The indices of the SparseTensor.
  101. * @li x1_values: The values of the SparseTensor. A vector Tensor. 1D.
  102. * @li x1_shape: A 1D Tensor of type int64. The requested new dense shape.
  103. * @li x2: A dense Tensor of the same type as "x1_values".
  104. *@par Outputs:
  105. *y: A Tensor. Has the same type as "x1_values".
  106. */
  107. REG_OP(SparseDenseCwiseAdd)
  108. .INPUT(x1_indices, TensorType({DT_INT64}))
  109. .INPUT(x1_values, TensorType({DT_INT8, DT_UINT8, DT_INT16, DT_UINT16, \
  110. DT_INT32, DT_INT64, DT_FLOAT16, DT_FLOAT, \
  111. DT_DOUBLE, DT_COMPLEX64, DT_COMPLEX128}))
  112. .INPUT(x1_shape, TensorType({DT_INT64}))
  113. .INPUT(x2, TensorType({DT_INT8, DT_UINT8, DT_INT16, DT_UINT16, DT_INT32, \
  114. DT_INT64, DT_FLOAT16, DT_FLOAT, DT_DOUBLE, \
  115. DT_COMPLEX64, DT_COMPLEX128}))
  116. .OUTPUT(y, TensorType({DT_INT8, DT_UINT8, DT_INT16, DT_UINT16, DT_INT32, \
  117. DT_INT64, DT_FLOAT16, DT_FLOAT, DT_DOUBLE, \
  118. DT_COMPLEX64, DT_COMPLEX128}))
  119. .OP_END_FACTORY_REG(SparseDenseCwiseAdd)
  120. /**
  121. *@brief Divides a SparseTensor by a dense Tensor.
  122. *@par Inputs:
  123. * @li x1_indices: A matrix Tensor of type int64. 2D. The indices of the SparseTensor.
  124. * @li x1_values: The values of the SparseTensor. A vector Tensor. 1D.
  125. * @li x1_shape: A 1D Tensor of type int64. The requested new dense shape.
  126. * @li x2: A dense Tensor of the same type as "x1_values".
  127. *@par Outputs:
  128. *y: A Tensor. Has the same type as "x1_values".
  129. */
  130. REG_OP(SparseDenseCwiseDiv)
  131. .INPUT(x1_indices, TensorType({DT_INT64}))
  132. .INPUT(x1_values, TensorType({DT_INT8, DT_UINT8, DT_INT16, DT_UINT16, \
  133. DT_INT32, DT_INT64, DT_FLOAT16, DT_FLOAT, \
  134. DT_DOUBLE, DT_COMPLEX64, DT_COMPLEX128}))
  135. .INPUT(x1_shape, TensorType({DT_INT64}))
  136. .INPUT(x2, TensorType({DT_INT8, DT_UINT8, DT_INT16, DT_UINT16, DT_INT32, \
  137. DT_INT64, DT_FLOAT16, DT_FLOAT, DT_DOUBLE, \
  138. DT_COMPLEX64, DT_COMPLEX128}))
  139. .OUTPUT(y, TensorType({DT_INT8, DT_UINT8, DT_INT16, DT_UINT16, DT_INT32, \
  140. DT_INT64, DT_FLOAT16, DT_FLOAT, DT_DOUBLE, \
  141. DT_COMPLEX64, DT_COMPLEX128}))
  142. .OP_END_FACTORY_REG(SparseDenseCwiseDiv)
  143. /**
  144. *@brief Multiplies a SparseTensor by a dense Tensor.
  145. *@par Inputs:
  146. * @li x1_indices: A matrix Tensor of type int64. 2D. The indices of the SparseTensor.
  147. * @li x1_values: The values of the SparseTensor. A vector Tensor. 1D.
  148. * @li x1_shape: A 1D Tensor of type int64. The requested new dense shape.
  149. * @li x2: A dense Tensor of the same type as "x1_values".
  150. *@par Outputs:
  151. *y: A Tensor. Has the same type as "x1_values".
  152. */
  153. REG_OP(SparseDenseCwiseMul)
  154. .INPUT(x1_indices, TensorType({DT_INT64}))
  155. .INPUT(x1_values, TensorType({DT_INT8, DT_UINT8, DT_INT16, DT_UINT16, \
  156. DT_INT32, DT_INT64, DT_FLOAT16, DT_FLOAT, \
  157. DT_DOUBLE, DT_COMPLEX64, DT_COMPLEX128}))
  158. .INPUT(x1_shape, TensorType({DT_INT64}))
  159. .INPUT(x2, TensorType({DT_INT8, DT_UINT8, DT_INT16, DT_UINT16, DT_INT32, \
  160. DT_INT64, DT_FLOAT16, DT_FLOAT, DT_DOUBLE, \
  161. DT_COMPLEX64, DT_COMPLEX128}))
  162. .OUTPUT(y, TensorType({DT_INT8, DT_UINT8, DT_INT16, DT_UINT16, DT_INT32, \
  163. DT_INT64, DT_FLOAT16, DT_FLOAT, DT_DOUBLE, \
  164. DT_COMPLEX64, DT_COMPLEX128}))
  165. .OP_END_FACTORY_REG(SparseDenseCwiseMul)
  166. /**
  167. *@brief Adds a SparseTensor to a SparseTensorsMap.
  168. *@par Inputs:
  169. * The input tensor must be a SparseTensor.
  170. * @li x1_indices: A matrix Tensor of type int64. 2D. The indices of the SparseTensor.
  171. * @li x1_values: The values of the SparseTensor. A vector Tensor. 1D.
  172. * @li x1_shape: A 1D Tensor of type int64. The requested new dense shape.
  173. *@par Attributes:
  174. *@li container: An optional string. Defaults to " ".
  175. *@li shared_name: An optional string. Defaults to " ".
  176. *@par Outputs:
  177. *handle: A Tensor of type int64.
  178. */
  179. REG_OP(AddSparseToTensorsMap)
  180. .INPUT(indices, TensorType({DT_INT64}))
  181. .INPUT(values, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, \
  182. DT_UINT16, DT_UINT8, DT_INT32, DT_INT64, DT_BOOL, DT_DOUBLE \
  183. DT_COMPLEX64, DT_COMPLEX128, DT_RESOURCE, DT_STRING}))
  184. .INPUT(shape, TensorType({DT_INT64}))
  185. .OUTPUT(handle, TensorType({DT_INT64}))
  186. .ATTR(container, String, "")
  187. .ATTR(shared_name, String, "")
  188. .OP_END_FACTORY_REG(AddSparseToTensorsMap)
  189. /**
  190. *@brief The gradient operator for the SparseSlice op.
  191. *@par Inputs:
  192. * @li backprop_val_grad: A Tensor.
  193. * @li indices: A matrix Tensor of type int64. 2D. The indices of the SparseTensor.
  194. * @li start: A 1D Tensor of type int64. The start of the slice.
  195. * @li new_indices: A matrix Tensor of type int64. 2D. The indices of the sliced SparseTensor.
  196. *@par Outputs:
  197. *y_grad: A Tensor of type int64.
  198. */
  199. REG_OP(SparseSliceGrad)
  200. .INPUT(backprop_val_grad, TensorType({ DT_INT8, DT_UINT8, DT_INT16,
  201. DT_UINT16, DT_INT32, DT_INT64, DT_FLOAT, DT_FLOAT16, DT_DOUBLE,
  202. DT_COMPLEX64, DT_COMPLEX128}))
  203. .INPUT(indices, TensorType({DT_INT64}))
  204. .INPUT(start, TensorType({DT_INT64}))
  205. .INPUT(new_indices, TensorType({DT_INT64}))
  206. .OUTPUT(y_grad, TensorType({ DT_INT8, DT_UINT8, DT_INT16,
  207. DT_UINT16, DT_INT32, DT_INT64, DT_FLOAT, DT_FLOAT16, DT_DOUBLE,
  208. DT_COMPLEX64, DT_COMPLEX128 }))
  209. .OP_END_FACTORY_REG(SparseSliceGrad)
  210. /**
  211. *@brief Slices a SparseTensor based on the "start" and "size".
  212. *@par Inputs:
  213. * @li indices: A 2D Tensor of type int64. The indices of the SparseTensor.
  214. * @li values: A 1D Tensor. The values of the SparseTensor.
  215. * @li shape: A 2D Tensor of type int64. The shape of the SparseTensor.
  216. * @li start: A 1D Tensor of type int64. The start of the slice.
  217. * @li size: A 1D Tensor of type int64. The size of the slice.
  218. *@par Outputs:
  219. *y_indices: A Tensor of type int64.
  220. *y_values: A Tensor. Has the same type as "values".
  221. *y_values: A Tensor of type int64.
  222. */
  223. REG_OP(SparseSlice)
  224. .INPUT(indices, TensorType({DT_INT64}))
  225. .INPUT(values, TensorType({DT_INT64, DT_INT32, DT_UINT16, DT_INT16, \
  226. DT_UINT8, DT_INT8, DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_COMPLEX64, \
  227. DT_COMPLEX128, DT_BOOL, DT_STRING, DT_RESOURCE}))
  228. .INPUT(shape, TensorType({DT_INT64}))
  229. .INPUT(start, TensorType({DT_INT64}))
  230. .INPUT(size, TensorType({DT_INT64}))
  231. .OUTPUT(y_indices, TensorType({DT_INT64}))
  232. .OUTPUT(y_values, TensorType({DT_INT64, DT_INT32, DT_UINT16, DT_INT16, \
  233. DT_UINT8, DT_INT8, DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_COMPLEX64, \
  234. DT_COMPLEX128, DT_BOOL, DT_STRING, DT_RESOURCE}))
  235. .OUTPUT(y_shape, TensorType({DT_INT64}))
  236. .OP_END_FACTORY_REG(SparseSlice)
  237. /**
  238. *@brief The gradient operator for the SparseAdd op.
  239. *@par Inputs:
  240. * @li backprop_val_grad: A 1D Tensor with shape [nnz(sum)]. The gradient with respect to the non-empty values of the sum.
  241. * @li x1_indices: A 2D Tensor of type int64. The indices of the SparseTensor A, with size [nnz(A), ndims].
  242. * @li x2_indices: A 2D Tensor of type int64. The indices of the SparseTensor B, with size [nnz(B), ndims].
  243. * @li sum_indices: A 2D Tensor of type int64. The indices of the sum SparseTensor, with size [nnz(sum), ndims].
  244. *@par Outputs:
  245. *x1_val_grad: A Tensor. Has the same type as "backprop_val_grad".
  246. *x2_val_grad: A Tensor. Has the same type as "backprop_val_grad".
  247. */
  248. REG_OP(SparseAddGrad)
  249. .INPUT(backprop_val_grad, TensorType({DT_INT8, DT_INT16, DT_INT32,
  250. DT_INT64, DT_FLOAT, DT_DOUBLE, DT_COMPLEX64, DT_COMPLEX128}))
  251. .INPUT(x1_indices, TensorType({DT_INT64}))
  252. .INPUT(x2_indices, TensorType({DT_INT64}))
  253. .INPUT(sum_indices, TensorType({DT_INT64}))
  254. .OUTPUT(x1_val_grad, TensorType({DT_INT8, DT_INT16, DT_INT32,
  255. DT_INT64, DT_FLOAT, DT_DOUBLE, DT_COMPLEX64, DT_COMPLEX128}))
  256. .OUTPUT(x2_val_grad, TensorType({DT_INT8, DT_INT16, DT_INT32,
  257. DT_INT64, DT_FLOAT, DT_DOUBLE, DT_COMPLEX64, DT_COMPLEX128}))
  258. .OP_END_FACTORY_REG(SparseAddGrad)
  259. /**
  260. *@brief The gradient of SparseFillEmptyRows.
  261. *@par Inputs:
  262. * @li reverse_index_map: A 1D Tensor of type int64. The reverse index map from SparseFillEmptyRows.
  263. * @li grad_values: A 1D Tensor. The gradients from backprop.
  264. *@par Outputs:
  265. *@li y_value: A Tensor. Has the same type as "grad_values".
  266. *@li y_default_value: A Tensor. Has the same type as "grad_values".
  267. */
  268. REG_OP(SparseFillEmptyRowsGrad)
  269. .INPUT(reverse_index_map, TensorType({DT_INT64}))
  270. .INPUT(grad_values, TensorType({DT_INT8, DT_UINT8, DT_INT16, DT_UINT16, \
  271. DT_INT32, DT_INT64, DT_FLOAT16, DT_FLOAT, DT_DOUBLE, \
  272. DT_COMPLEX64, DT_COMPLEX128, DT_RESOURCE, DT_STRING}))
  273. .OUTPUT(y_value, TensorType({DT_INT8, DT_UINT8, DT_INT16, DT_UINT16, \
  274. DT_INT32, DT_INT64, DT_FLOAT16, DT_FLOAT, DT_DOUBLE, \
  275. DT_COMPLEX64, DT_COMPLEX128, DT_RESOURCE, DT_STRING}))
  276. .OUTPUT(y_default_value, TensorType({DT_INT8, DT_UINT8, DT_INT16, \
  277. DT_UINT16, DT_INT32, DT_INT64, DT_FLOAT16, DT_FLOAT, DT_DOUBLE, \
  278. DT_COMPLEX64, DT_COMPLEX128, DT_RESOURCE, DT_STRING}))
  279. .OP_END_FACTORY_REG(SparseFillEmptyRowsGrad)
  280. /**
  281. *@brief Multiplies SparseTensor A (of rank 2) by dense matrix B.
  282. *@par Inputs:
  283. * @li x1_indices: A 2D Tensor of type int32 or int64.
  284. * @li The indices of the matrix "SparseTensor", with size [nnz, 2].
  285. * @li x1_values: A 1D Tensor. The values of the SparseTensor, with size [nnz].
  286. * @li x1_shape: A 1D Tensor of type int64. The shape of the SparseTensor, with size [2].
  287. * @li x2: A dense matrix Tensor of the same type as "x1_values". 2D.
  288. *@par Outputs:
  289. *y: A "Tensor". Has the same type as "x1_values".
  290. *@par Attributes:
  291. *@li adjoint_a: An optional bool. Defaults to "False".Use the adjoint of A in the matrix multiply.
  292. *@li If A is complex, this is transpose(conj(A)). Otherwise it is transpose(A).
  293. *@li adjoint_b: An optional bool. Defaults to "False".Use the adjoint of B in the matrix multiply.
  294. *@li If B is complex, this is transpose(conj(B)). Otherwise it is transpose(B).
  295. */
  296. REG_OP(SparseTensorDenseMatMul)
  297. .INPUT(x1_indices, TensorType({DT_INT32, DT_INT64}))
  298. .INPUT(x1_values, TensorType({DT_FLOAT, DT_DOUBLE, DT_INT32, \
  299. DT_COMPLEXT64, DT_COMPLEX128, DT_FLOAT16}))
  300. .INPUT(x1_shape, TensorType({DT_INT64}))
  301. .INPUT(x2, TensorType({DT_FLOAT, DT_DOUBLE, DT_INT32, DT_COMPLEXT64, \
  302. DT_COMPLEX128, DT_FLOAT16}))
  303. .OUTPUT(y, TensorType({DT_FLOAT, DT_DOUBLE, DT_INT32, DT_COMPLEXT64, \
  304. DT_COMPLEX128, DT_FLOAT16}))
  305. .ATTR(adjoint_a, Bool, false)
  306. .ATTR(adjoint_b, Bool, false)
  307. .OP_END_FACTORY_REG(SparseTensorDenseMatMul)
  308. /**
  309. *@brief Converts a sparse representation into a dense tensor.
  310. *@par Inputs:
  311. * @li indices: A 0D, 1D, or 2D Tensor of type int32 or int64.
  312. * @li output_shape: A 1D Tensor of the same type as "sparse_indices". The shape of the dense output tensor.
  313. * @li values: A 1D Tensor. Values corresponding to each row of "sparse_indices",
  314. * @li or a scalar value to be used for all sparse indices.
  315. * @li default_value: A Tensor of the same type as "sparse_values".
  316. *@par Outputs:
  317. *y: A Tensor. Has the same type as "values".
  318. */
  319. REG_OP(SparseToDense)
  320. .INPUT(indices, TensorType({DT_INT32, DT_INT64}))
  321. .INPUT(output_shape, TensorType({DT_INT32, DT_INT64}))
  322. .INPUT(values, TensorType({DT_INT8, DT_UINT8, DT_INT16, DT_UINT16, \
  323. DT_INT32, DT_INT64, DT_FLOAT16, DT_FLOAT, DT_BOOL, DT_DOUBLE}))
  324. .INPUT(default_value, TensorType({DT_INT8, DT_UINT8, DT_INT16, \
  325. DT_UINT16, DT_INT32, DT_INT64, DT_FLOAT16, DT_FLOAT, DT_BOOL, \
  326. DT_DOUBLE}))
  327. .OUTPUT(y, TensorType({DT_INT8, DT_UINT8, DT_INT16, DT_UINT16, \
  328. DT_INT32, DT_INT64, DT_FLOAT16, DT_FLOAT, DT_BOOL, DT_DOUBLE}))
  329. .ATTR(validate_indices, Bool, true)
  330. .OP_END_FACTORY_REG(SparseToDense)
  331. /**
  332. *@brief Concatenates a list of `SparseTensor` along the specified dimension.\n
  333. *Concatenation is with respect to the dense versions of these sparse tensors.
  334. *@par Inputs:
  335. *3 or 5 inputs,contains:
  336. * @li indices:A list of at least 2 `Tensor` objects with type `int64`.2-D. \n
  337. *Indices of each input `SparseTensor`.
  338. * @li values:A list with the same length as `indices` of `Tensor` objects with the same type.
  339. * @li shapes:A list with the same length as `indices` of `Tensor` objects with type `int64`.1-D. \n
  340. * Shapes of each `SparseTensor`.
  341. *@par Attributes:
  342. *@li concat_dim: An `int` Dimension to concatenate along
  343. *@li N:Number of sparse
  344. *@par Outputs:
  345. * @li y_indices:A `Tensor` of type `int64`.
  346. * @li y_values:A `Tensor`. Has the same type as `values`.
  347. * @li y_shape:A `Tensor` of type `int64`.
  348. */
  349. REG_OP(SparseConcat)
  350. .DYNAMIC_INPUT(indices, TensorType({DT_INT64}))
  351. .DYNAMIC_INPUT(values,
  352. TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, DT_UINT16, \
  353. DT_UINT8, DT_INT32, DT_INT64, DT_BOOL, DT_DOUBLE, \
  354. DT_COMPLEX64, DT_COMPLEX128, DT_RESOURCE, DT_STRING}))
  355. .DYNAMIC_INPUT(shapes, TensorType({DT_INT64}))
  356. .OUTPUT(y_indices, TensorType({DT_INT64}))
  357. .OUTPUT(y_values,
  358. TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, DT_UINT16, \
  359. DT_UINT8, DT_INT32, DT_INT64, DT_BOOL, DT_DOUBLE, \
  360. DT_COMPLEX64, DT_COMPLEX128, DT_RESOURCE, DT_STRING}))
  361. .OUTPUT(y_shape, TensorType({DT_INT64}))
  362. .ATTR(concat_dim, Int, 0)
  363. .ATTR(N, Int, 1)
  364. .OP_END_FACTORY_REG(SparseConcat)
  365. /**
  366. *@brief Adds two `SparseTensor` objects to produce another `SparseTensor`.
  367. *@par Inputs:
  368. *7 inputs, contains:
  369. * @li x1_indices:A `Tensor` of type `int64`.2-D. \n
  370. * The `indices` of the first `SparseTensor`, size `[nnz, ndims]` Matrix.
  371. * @li x1_values:A `Tensor`. Must be one of the following types:float,int8,int16,int32,int64, float64.
  372. * @li x1_shape:A `Tensor` of type `int64`.1-D. The `shape` of the first `SparseTensor`, \n
  373. * size `[ndims]` Vector.
  374. * @li x2_indices:A `Tensor` of type `int64`.2-D.The `indices` of the second `SparseTensor`, \n
  375. * size `[nnz, ndims]` Matrix.
  376. * @li x2_values:A `Tensor`. Must have the same type as `a_values`.1-D. \n
  377. * The `values` of the second `SparseTensor`, size `[nnz]` Vector.
  378. * @li x2_shape:A `Tensor` of type `int64`.1-D. \n
  379. * The `shape` of the second `SparseTensor`, size `[ndims]` Vector.
  380. * @li thresh:A `Tensor` 0-D.The magnitude threshold that determines if an output value/index pair takes space.
  381. *@par Outputs:
  382. * @li sum_indices:A `Tensor` of type `int64`.
  383. * @li sum_values:A `Tensor`. Has the same type as `x1_values`.
  384. * @li sum_shape:A `Tensor` of type `int64`.
  385. */
  386. REG_OP(SparseAdd)
  387. .INPUT(x1_indices, TensorType({DT_INT64}))
  388. .INPUT(x1_values, TensorType({DT_FLOAT, DT_INT8, DT_INT16, \
  389. DT_INT32, DT_INT64, DT_DOUBLE, DT_COMPLEX64, DT_COMPLEX128}))
  390. .INPUT(x1_shape, TensorType({DT_INT64}))
  391. .INPUT(x2_indices, TensorType({DT_INT64}))
  392. .INPUT(x2_values, TensorType({DT_FLOAT, DT_INT8, DT_INT16, DT_INT32, \
  393. DT_INT64, DT_DOUBLE, DT_COMPLEX64, DT_COMPLEX128}))
  394. .INPUT(x2_shape, TensorType({DT_INT64}))
  395. .INPUT(thresh, TensorType({DT_FLOAT, DT_INT8, DT_INT16, DT_INT32, \
  396. DT_INT64, DT_DOUBLE}))
  397. .OUTPUT(sum_indices, TensorType({DT_INT64}))
  398. .OUTPUT(sum_values, TensorType({DT_FLOAT, DT_INT8, DT_INT16, \
  399. DT_INT32, DT_INT64, DT_DOUBLE, DT_COMPLEX64, DT_COMPLEX128}))
  400. .OUTPUT(sum_shape, TensorType({DT_INT64}))
  401. .OP_END_FACTORY_REG(SparseAdd)
  402. /**
  403. *@brief Fills empty rows in the input 2-D `SparseTensor` with a default value.
  404. *@par Inputs:
  405. *4 inputs,contains:
  406. * @li indices: A `Tensor` of type `int64`.2-D. the indices of the sparse tensor.
  407. * @li values: A `Tensor`. 1-D. the values of the sparse tensor.
  408. * @li dense_shape: A `Tensor` of type `int64`.1-D. the shape of the sparse tensor.
  409. * @li default_value: `Tensor`. Must have the same type as `values`.\n
  410. *0-D. default value to insert into location `[row, 0, ..., 0]` \n
  411. *for rows missing from the input sparse tensor.
  412. *@par Outputs:
  413. * @li y_indices:A `Tensor` of type `int64`.
  414. * @li y_values:A `Tensor`. Has the same type as `values`.
  415. * @li empty_row_indicator:A `Tensor` of type `bool`.
  416. * @li reverse_index_map:A `Tensor` of type `int64`.
  417. */
  418. REG_OP(SparseFillEmptyRows)
  419. .INPUT(indices, TensorType({DT_INT64}))
  420. .INPUT(values, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, \
  421. DT_UINT16, DT_UINT8, DT_INT32, DT_INT64, DT_BOOL, DT_DOUBLE, \
  422. DT_COMPLEX64, DT_COMPLEX128, DT_RESOURCE, DT_STRING}))
  423. .INPUT(dense_shape, TensorType({DT_INT64}))
  424. .INPUT(default_value, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, \
  425. DT_INT16, DT_UINT16, DT_UINT8, \
  426. DT_INT32, DT_INT64, DT_BOOL, DT_DOUBLE, \
  427. DT_COMPLEX64, DT_COMPLEX128, DT_RESOURCE, DT_STRING}))
  428. .OUTPUT(y_indices, TensorType({DT_INT64}))
  429. .OUTPUT(y_values, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, \
  430. DT_INT16, DT_UINT16, DT_UINT8, \
  431. DT_INT32, DT_INT64, DT_BOOL, DT_DOUBLE, \
  432. DT_COMPLEX64, DT_COMPLEX128, DT_RESOURCE, DT_STRING}))
  433. .OUTPUT(empty_row_indicator, TensorType({DT_BOOL}))
  434. .OUTPUT(reverse_index_map, TensorType({DT_INT64}))
  435. .OP_END_FACTORY_REG(SparseFillEmptyRows)
  436. /**
  437. *@brief Returns the element-wise max of two SparseTensors.
  438. *@par Inputs:
  439. *6 inputs,contains:
  440. * @li x1_indices:A `Tensor` of type `int64`.2-D. \n
  441. *`N x R` matrix with the indices of non-empty values in a SparseTensor, \n
  442. * in the canonical lexicographic ordering.
  443. * @li x1_values:A `Tensor`. 1-D. the values of the sparse tensor.
  444. * @li x1_shape:A `Tensor` of type `int64`.1-D. the shape of the sparse tensor.
  445. * @li x2_indices:A `Tensor` of type `int64`.2-D. the indices of the sparse tensor.
  446. * @li x2_values:A `Tensor`. 1-D. Must have the same type as `x1_values`.
  447. * @li x2_shape:A `Tensor` of type `int64`.1-D. \n
  448. *counterpart to `a_shape` for the other operand; the two shapes must be equal.
  449. *@par Outputs:
  450. * @li y_indices:A `Tensor` of type `int64`.
  451. * @li y_values:A `Tensor`. Has the same type as `x1_values`.
  452. */
  453. REG_OP(SparseSparseMaximum)
  454. .INPUT(x1_indices, TensorType({DT_INT64}))
  455. .INPUT(x1_values, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, \
  456. DT_UINT16, DT_UINT8, DT_INT32, DT_INT64, DT_DOUBLE}))
  457. .INPUT(x1_shape, TensorType({DT_INT64}))
  458. .INPUT(x2_indices, TensorType({DT_INT64}))
  459. .INPUT(x2_values, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, \
  460. DT_UINT16, DT_UINT8, DT_INT32, DT_INT64, DT_DOUBLE}))
  461. .INPUT(x2_shape, TensorType({DT_INT64}))
  462. .OUTPUT(y_indices, TensorType({DT_INT64}))
  463. .OUTPUT(y_values, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, \
  464. DT_UINT16, DT_UINT8, DT_INT32, DT_INT64, DT_DOUBLE}))
  465. .OP_END_FACTORY_REG(SparseSparseMaximum)
  466. /**
  467. *@brief Returns the element-wise min of two SparseTensors.
  468. *@par Inputs:
  469. *6 inputs,contains:
  470. * @li x1_indices:A `Tensor` of type `int64`.2-D. \n
  471. *`N x R` matrix with the indices of non-empty values in a SparseTensor, \n
  472. * in the canonical lexicographic ordering.
  473. * @li x1_values:A `Tensor`. 1-D. the values of the sparse tensor.
  474. * @li x1_shape:A `Tensor` of type `int64`.1-D. the shape of the sparse tensor.
  475. * @li x2_indices:A `Tensor` of type `int64`.2-D. the indices of the sparse tensor.
  476. * @li x2_values:A `Tensor`. 1-D. Must have the same type as `x1_values`.
  477. * @li x2_shape:A `Tensor` of type `int64`.1-D. \n
  478. *counterpart to `a_shape` for the other operand; the two shapes must be equal.
  479. *@par Outputs:
  480. * @li y_indices:A `Tensor` of type `int64`.
  481. * @li y_values:A `Tensor`. Has the same type as `x1_values`.
  482. */
  483. REG_OP(SparseSparseMinimum)
  484. .INPUT(x1_indices, TensorType({DT_INT64}))
  485. .INPUT(x1_values, TensorType({DT_INT64, DT_INT32, \
  486. DT_UINT16, DT_INT16, DT_UINT8, DT_INT8, DT_FLOAT16, \
  487. DT_FLOAT, DT_DOUBLE, DT_COMPLEX64, DT_COMPLEX128}))
  488. .INPUT(x1_shape, TensorType({DT_INT64}))
  489. .INPUT(x2_indices, TensorType({DT_INT64}))
  490. .INPUT(x2_values, TensorType({DT_INT64, DT_INT32, \
  491. DT_UINT16, DT_INT16, DT_UINT8, DT_INT8, DT_FLOAT16, \
  492. DT_FLOAT, DT_DOUBLE, DT_COMPLEX64, DT_COMPLEX128}))
  493. .INPUT(x2_shape, TensorType({DT_INT64}))
  494. .OUTPUT(y_indices, TensorType({DT_INT64}))
  495. .OUTPUT(y_values, TensorType({DT_INT64, DT_INT32, \
  496. DT_UINT16, DT_INT16, DT_UINT8, DT_INT8, DT_FLOAT16, \
  497. DT_FLOAT, DT_DOUBLE, DT_COMPLEX64, DT_COMPLEX128}))
  498. .OP_END_FACTORY_REG(SparseSparseMinimum)
  499. /**
  500. *@brief Computes the max of elements across dimensions of a SparseTensor.
  501. *@par Inputs:
  502. *4 or 5 inputs,contains:
  503. * @li x_indices:A `Tensor` of type `int64`.2-D. \n
  504. *`N x R` matrix with the indices of non-empty values in a \n
  505. *SparseTensor, possibly not in canonical ordering.
  506. * @li x_values:A `Tensor`. 1-D. the values of the sparse tensor. \n
  507. *`N` non-empty values corresponding to `input_indices`.
  508. * @li x_shape:A `Tensor` of type `int64`.1-D. Shape of the input SparseTensor.
  509. * @li reduction_axes:A `Tensor` of type `int32`.1-D.\n
  510. *Length-`K` vector containing the reduction axes.
  511. *@par Attributes:
  512. * keep_dims:An optional `bool`. Defaults to `False`.\n
  513. *If true, retain reduced dimensions with length 1.
  514. *@par Outputs:
  515. * y:A `Tensor`. Has the same type as `input_values`.
  516. */
  517. REG_OP(SparseReduceMax)
  518. .INPUT(x_indices, TensorType({DT_INT64}))
  519. .INPUT(x_values, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, \
  520. DT_UINT16, DT_UINT8, DT_INT32, DT_INT64, DT_DOUBLE}))
  521. .INPUT(x_shape, TensorType({DT_INT64}))
  522. .INPUT(reduction_axes, TensorType({DT_INT32}))
  523. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16,
  524. DT_UINT16, DT_UINT8, DT_INT32, DT_INT64, DT_DOUBLE}))
  525. .ATTR(keep_dims, Bool, false)
  526. .OP_END_FACTORY_REG(SparseReduceMax)
  527. /**
  528. *@brief Computes the max of elements across dimensions of a SparseTensor.
  529. *@par Inputs:
  530. *4 or 5 inputs,contains:
  531. * @li x_indices:A `Tensor` of type `int64`.2-D. \n
  532. *`N x R` matrix with the indices of non-empty values in a \n
  533. *SparseTensor, possibly not in canonical ordering.
  534. * @li x_values:A `Tensor`. 1-D. the values of the sparse tensor. \n
  535. *`N` non-empty values corresponding to `input_indices`.
  536. * @li x_shape:A `Tensor` of type `int64`.1-D. Shape of the input SparseTensor.
  537. * @li reduction_axes:A `Tensor` of type `int32`.1-D.\n
  538. *Length-`K` vector containing the reduction axes.
  539. *@par Attributes:
  540. * keep_dims:An optional `bool`. Defaults to `False`.\n
  541. *If true, retain reduced dimensions with length 1.
  542. *@par Outputs:
  543. * @li y_indices:A `Tensor` of type `int64`.
  544. * @li y_values:A `Tensor`. Has the same type as `input_values`.
  545. * @li y_shape:A `Tensor` of type `int64`.
  546. */
  547. REG_OP(SparseReduceMaxSparse)
  548. .INPUT(x_indices, TensorType({DT_INT64}))
  549. .INPUT(x_values, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, \
  550. DT_UINT16, DT_UINT8, DT_INT32, DT_INT64, DT_DOUBLE}))
  551. .INPUT(x_shape, TensorType({DT_INT64}))
  552. .INPUT(reduction_axes, TensorType({DT_INT32}))
  553. .OUTPUT(y_indices, TensorType({DT_INT64}))
  554. .OUTPUT(y_values, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, \
  555. DT_UINT16, DT_UINT8, DT_INT32, DT_INT64, DT_DOUBLE}))
  556. .OUTPUT(y_shape, TensorType({DT_INT64}))
  557. .ATTR(keep_dims, Bool, false)
  558. .OP_END_FACTORY_REG(SparseReduceMaxSparse)
  559. /**
  560. *@brief Computes the sum of elements across dimensions of a SparseTensor.
  561. *@par Inputs:
  562. *4 or 5 inputs, including:
  563. * @li x_indices: A 2D Tensor of type int64.
  564. *"N x R" matrix with the indices of non-empty values in a \n
  565. *SparseTensor, possibly not in canonical ordering.
  566. * @li x_values: A 1D Tensor. The values of the SparseTensor.
  567. *"N" non-empty values corresponding to "input_indices".
  568. * @li x_shape: A 1D Tensor of type int64. Shape of the input SparseTensor.
  569. * @li reduction_axes: A 1D Tensor of type int32. \n
  570. *A length-"K" vector containing the reduction axes.
  571. *@par Attributes:
  572. * keep_dims: An optional bool. Defaults to "False". \n
  573. *If true, retains reduced dimensions with length 1.
  574. *@par Outputs:
  575. * @li y_indices: A Tensor of type int64.
  576. * @li y_values: A Tensor. Has the same type as "input_values".
  577. * @li y_shape: A Tensor of type int64.
  578. */
  579. REG_OP(SparseReduceSum)
  580. .INPUT(x_indices, TensorType({DT_INT64}))
  581. .INPUT(x_values, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, \
  582. DT_UINT16, DT_UINT8, DT_INT32, DT_INT64, DT_DOUBLE, \
  583. DT_COMPLEX64, DT_COMPLEX128}))
  584. .INPUT(x_shape, TensorType({DT_INT64}))
  585. .INPUT(reduction_axes, TensorType({DT_INT32}))
  586. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16,
  587. DT_UINT16, DT_UINT8, DT_INT32, DT_INT64, DT_DOUBLE, \
  588. DT_COMPLEX64, DT_COMPLEX128}))
  589. .ATTR(keep_dims, Bool, false)
  590. .OP_END_FACTORY_REG(SparseReduceSum)
  591. /**
  592. *@brief Computes the sum of elements across dimensions of a SparseTensor.
  593. *@par Inputs:
  594. *4 or 5 inputs, including:
  595. * @li x_indices: A 2D Tensor of type int64.
  596. *"N x R" matrix with the indices of non-empty values in a \n
  597. *SparseTensor, possibly not in canonical ordering.
  598. * @li x_values: A 1D Tensor. The values of the SparseTensor.
  599. *"N" non-empty values corresponding to "input_indices".
  600. * @li x_shape: A 1D Tensor of type int64. Shape of the input SparseTensor.
  601. * @li reduction_axes: A 1D Tensor of type int32. \n
  602. * A length-"K" vector containing the reduction axes.
  603. *@par Attributes:
  604. * keep_dims: An optional bool. Defaults to "False".\n
  605. *If true, retains reduced dimensions with length 1.
  606. *@par Outputs:
  607. * @li y_indices: A Tensor of type int64.
  608. * @li y_values: A Tensor. Has the same type as "input_values".
  609. * @li y_shape: A Tensor of type int64.
  610. */
  611. REG_OP(SparseReduceSumSparse)
  612. .INPUT(x_indices, TensorType({DT_INT64}))
  613. .INPUT(x_values, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, \
  614. DT_UINT16, DT_UINT8, DT_INT32, DT_INT64, DT_DOUBLE, \
  615. DT_COMPLEX64, DT_COMPLEX128}))
  616. .INPUT(x_shape, TensorType({DT_INT64}))
  617. .INPUT(reduction_axes, TensorType({DT_INT32}))
  618. .OUTPUT(y_indices, TensorType({DT_INT64}))
  619. .OUTPUT(y_values, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, \
  620. DT_UINT16, DT_UINT8, DT_INT32, DT_INT64, DT_DOUBLE, \
  621. DT_COMPLEX64, DT_COMPLEX128}))
  622. .OUTPUT(y_shape, TensorType({DT_INT64}))
  623. .ATTR(keep_dims, Bool, false)
  624. .OP_END_FACTORY_REG(SparseReduceSumSparse)
  625. /**
  626. *@brief Splits a SparseTensor into "num_split" tensors along one dimension.
  627. *@par Inputs:
  628. *4 or 5 inputs, including:
  629. * @li split_dim: A 0D Tensor of type int64.\n
  630. *The dimension along which to split. Must be in the range "[0, rank(shape))".
  631. * @li indices: A 2D Tensor of type int64.\n
  632. * The indices of the SparseTensor.
  633. * @li values: A 1D Tensor. The values of the SparseTensor.
  634. * @li shape: A 1D Tensor of type int64. Shape of the SparseTensor.
  635. *@par Attributes:
  636. * num_split: An int that is >= 1. The number of ways to split.
  637. *@par Outputs:
  638. * @li y_indices: A list of "num_split" Tensor objects of type int64.
  639. * @li y_values: A list of "num_split" Tensor objects with the same type as "values".
  640. * @li y_shape: A list of "num_split" Tensor objects of type int64.
  641. */
  642. REG_OP(SparseSplit)
  643. .INPUT(split_dim, TensorType({DT_INT64}))
  644. .INPUT(indices, TensorType({DT_INT64}))
  645. .INPUT(values, TensorType({DT_INT64, DT_INT32, DT_UINT16, DT_INT16, \
  646. DT_UINT8, DT_INT8, DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_COMPLEX64, \
  647. DT_COMPLEX128, DT_BOOL, DT_STRING, DT_RESOURCE}))
  648. .INPUT(shape, TensorType({DT_INT64}))
  649. .DYNAMIC_OUTPUT(y_indices, TensorType({DT_INT64}))
  650. .DYNAMIC_OUTPUT(y_values, TensorType({DT_INT64, DT_INT32, DT_UINT16, \
  651. DT_INT16, DT_UINT8, DT_INT8, DT_FLOAT16, DT_FLOAT, DT_DOUBLE, \
  652. DT_COMPLEX64, DT_COMPLEX128, DT_BOOL, DT_STRING, DT_RESOURCE}))
  653. .DYNAMIC_OUTPUT(y_shape, TensorType({DT_INT64}))
  654. .ATTR(num_split, Int, 1)
  655. .OP_END_FACTORY_REG(SparseSplit)
  656. /**
  657. *@brief Generates sparse cross from a list of sparse and dense tensors.
  658. *@par Inputs:
  659. *8 or 10 inputs, including:
  660. * @li indices: A list of 2D Tensor objects of type int64.
  661. * Indices of each input SparseTensor.
  662. * @li values: A list of 1D Tensor objects of type int64 or string.
  663. * Values of each SparseTensor.
  664. * @li shapes: A list with the same length as "indices" of 1D Tensor objects of type int64.
  665. * Shapes of each SparseTensor.
  666. * @li dense_inputs: A list of 2D Tensor objects of type int64 or string.
  667. * Columns represented by dense Tensor.
  668. *@par Attributes:
  669. * @li N: number of sparse.
  670. * @li hashed_output: A bool. If true, returns the hash of the cross instead of the string.
  671. * @li num_buckets: An int that is >= 0. It is used if "hashed_output" is true. \n
  672. *output = hashed_value%num_buckets if num_buckets > 0 else "hashed_value".
  673. * @li hash_key: An int. Specify the hash_key that will be used by the "FingerprintCat64"\n
  674. *function to combine the crosses fingerprints.
  675. * @li out_type: An int64 or string.
  676. * @li internal_type: An int64 or string.
  677. *@par Outputs:
  678. * @li output_indices: A Tensor of type int64.
  679. * @li output_values: A Tensor of type "out_type".
  680. * @li output_shape: A Tensor of type int64.
  681. */
  682. REG_OP(SparseCross)
  683. .DYNAMIC_INPUT(indices, TensorType({DT_INT64}))
  684. .DYNAMIC_INPUT(values, TensorType({DT_INT64, DT_STRING}))
  685. .DYNAMIC_INPUT(shapes, TensorType({DT_INT64}))
  686. .DYNAMIC_INPUT(dense_inputs, TensorType({DT_INT64, DT_STRING}))
  687. .OUTPUT(output_indices, TensorType({DT_INT64}))
  688. .OUTPUT(output_values, TensorType({DT_INT64, DT_STRING}))
  689. .OUTPUT(output_shape, TensorType({DT_INT64}))
  690. .ATTR(N, Int, 0)
  691. .REQUIRED_ATTR(hashed_output, Bool)
  692. .ATTR(num_buckets, Int, 0)
  693. .REQUIRED_ATTR(hash_key, Int)
  694. .REQUIRED_ATTR(out_type, Type)
  695. .REQUIRED_ATTR(internal_type, Type)
  696. .OP_END_FACTORY_REG(SparseCross)
  697. /**
  698. *@brief Generates sparse cross from a list of sparse and dense tensors.
  699. *@par Inputs:
  700. *3 or 5 inputs, including:
  701. * @li indices: A 2D Tensor of type int64. \n
  702. * The "indices" of the minibatch SparseTensor.
  703. * @li values: A 1D Tensor. The "values" of the minibatch SparseTensor.
  704. * @li shape: A 1D Tensor of type int64. The "shape" of the minibatch SparseTensor.
  705. *@par Attributes:
  706. * @li container: An optional string. Defaults to "". \n
  707. *The container name for the "SparseTensorsMap" created by this op.
  708. * @li shared_name: An optional string. Defaults to "". \n
  709. *The shared name for the "SparseTensorsMap" created by this op.
  710. *@par Outputs:
  711. * handles: A Tensor of type int64.
  712. */
  713. REG_OP(AddManySparseToTensorsMap)
  714. .INPUT(indices, TensorType({DT_INT64}))
  715. .INPUT(values, TensorType({DT_INT8, DT_UINT8, DT_INT16, DT_UINT16, \
  716. DT_INT32, DT_INT64, DT_BOOL, DT_FLOAT16, DT_FLOAT, DT_DOUBLE, \
  717. DT_COMPLEX64, DT_COMPLEX128, DT_RESOURCE, DT_STRING}))
  718. .INPUT(shape, TensorType({DT_INT64}))
  719. .OUTPUT(handles, TensorType({DT_INT64}))
  720. .ATTR(container, String, "")
  721. .ATTR(shared_name, String, "")
  722. .OP_END_FACTORY_REG(AddManySparseToTensorsMap)
  723. /**
  724. *@brief Reads SparseTensors from a "SparseTensorsMap" and concatenate them.
  725. *@par Inputs:
  726. *2 or 4 inputs, including:
  727. * handles: A 1D Tensor of type int64. \n
  728. * The "N" serialized SparseTensor objects.
  729. *@par Attributes:
  730. * @li container: An optional string. Defaults to "". \n
  731. *The container name for the "SparseTensorsMap" read by this op.
  732. * @li shared_name: An optional string. Defaults to "". \n
  733. *The shared name for the "SparseTensorsMap" read by this op.
  734. *@par Outputs:
  735. * @li indices: A Tensor of type int64.
  736. * @li values: A Tensor of type "dtype".
  737. * @li shape: A Tensor of type int64.
  738. */
  739. REG_OP(TakeManySparseFromTensorsMap)
  740. .INPUT(handles, TensorType({DT_INT64}))
  741. .OUTPUT(indices, TensorType({DT_INT64}))
  742. .OUTPUT(values, TensorType({DT_BOOL, DT_INT8, DT_UINT8, DT_INT16, \
  743. DT_UINT16, DT_INT32, DT_INT64, DT_DOUBLE, DT_FLOAT, DT_FLOAT16}))
  744. .OUTPUT(shape, TensorType({DT_INT64}))
  745. .REQUIRED_ATTR(dtype, Type)
  746. .ATTR(container, String, "")
  747. .ATTR(shared_name, String, "")
  748. .OP_END_FACTORY_REG(TakeManySparseFromTensorsMap)
  749. /**
  750. *@brief Serializes a SparseTensor into a [3] Tensor object.
  751. *@par Inputs:
  752. *3 or 4 inputs, including:
  753. * @li indices: A 2D Tensor of type int64. The indices of the SparseTensor.
  754. * @li values: A 1D Tensor. The values of the SparseTensor.
  755. * @li shape: A 1D Tensor of type int64. The shape of the SparseTensor.
  756. *@par Attributes:
  757. * out_type: An optional type. Defaults to "string".
  758. *@par Outputs:
  759. * serialized_sparse: A Tensor of type "out_type".
  760. */
  761. REG_OP(SerializeSparse)
  762. .INPUT(indices, TensorType({DT_INT64}))
  763. .INPUT(values, TensorType({DT_BOOL, DT_INT8, DT_UINT8, DT_INT16, \
  764. DT_UINT16, DT_INT32, DT_INT64, DT_DOUBLE, DT_FLOAT, DT_FLOAT16, \
  765. DT_COMPLEX64, DT_COMPLEX128, DT_RESOURCE, DT_STRING}))
  766. .INPUT(shape, TensorType({DT_INT64}))
  767. .OUTPUT(serialized_sparse, TensorType({DT_STRING}))
  768. .ATTR(out_type, Type, DT_STRING)
  769. .OP_END_FACTORY_REG(SerializeSparse)
  770. /**
  771. *@brief Serializes an "N"-minibatch SparseTensor into an [N, 3] Tensor object.
  772. *@par Inputs:
  773. *3 or 4 inputs, including:
  774. * @li indices: A 2D Tensor of type int64. The "indices" of the minibatch SparseTensor.
  775. * @li values: A 1D Tensor. The "values" of the minibatch SparseTensor.
  776. * @li shape: A 1D Tensor of type int64. The "shape" of the minibatch SparseTensor.
  777. *@par Attributes:
  778. * out_type: An optional type. Defaults to "string".
  779. *@par Outputs:
  780. * serialized_sparse: A Tensor of type "out_type".
  781. */
  782. REG_OP(SerializeManySparse)
  783. .INPUT(indices, TensorType({DT_INT64}))
  784. .INPUT(values, TensorType({DT_BOOL, DT_INT8, DT_UINT8, DT_INT16, \
  785. DT_UINT16, DT_INT32, DT_INT64, DT_DOUBLE, DT_FLOAT, DT_FLOAT16, \
  786. DT_COMPLEX64, DT_COMPLEX128, DT_RESOURCE, DT_STRING}))
  787. .INPUT(shape, TensorType({DT_INT64}))
  788. .OUTPUT(serialized_sparse, TensorType({DT_STRING}))
  789. .ATTR(out_type, Type, DT_STRING)
  790. .OP_END_FACTORY_REG(SerializeManySparse)
  791. /**
  792. *@brief Deserializes SparseTensor objects.
  793. *@par Inputs:
  794. *Two inputs, including:
  795. * serialized_sparse: A Tensor. The serialized SparseTensor objects. \n
  796. *The last dimension must have 3 columns.
  797. *@par Attributes:
  798. * dtype: An optional type. The type of the serialized SparseTensor objects.
  799. *@par Outputs:
  800. * @li indices: A Tensor of type int64.
  801. * @li values: A Tensor of type "dtype".
  802. * @li shape: A Tensor of type int64.
  803. */
  804. REG_OP(DeserializeSparse)
  805. .INPUT(serialized_sparse, TensorType({DT_STRING}))
  806. .OUTPUT(indices, TensorType({DT_INT64}))
  807. .OUTPUT(values, TensorType({DT_BOOL, DT_INT8, DT_UINT8, DT_INT16, \
  808. DT_UINT16, DT_INT32, DT_INT64, DT_DOUBLE, DT_FLOAT, DT_FLOAT16, \
  809. DT_COMPLEX64, DT_COMPLEX128, DT_RESOURCE, DT_STRING}))
  810. .OUTPUT(shape, TensorType({DT_INT64}))
  811. .REQUIRED_ATTR(dtype, Type)
  812. .OP_END_FACTORY_REG(DeserializeSparse)
  813. /**
  814. *@brief Deserializes and concatenates SparseTensors from a serialized minibatch.
  815. *@par Inputs:
  816. *Two inputs, including:
  817. * serialized_sparse: A 2D Tensor of type string. \n
  818. *The "N" serialized SparseTensor objects. Must have 3 columns.
  819. *@par Attributes:
  820. * dtype: An optional type. The type of the serialized SparseTensor objects.
  821. *@par Outputs:
  822. * @li indices: A Tensor of type int64.
  823. * @li values: A Tensor of type "dtype".
  824. * @li shape: A Tensor of type int64.
  825. */
  826. REG_OP(DeserializeManySparse)
  827. .INPUT(serialized_sparse, TensorType({DT_STRING}))
  828. .OUTPUT(indices, TensorType({DT_INT64}))
  829. .OUTPUT(values, TensorType({DT_BOOL, DT_INT8, DT_UINT8, DT_INT16, \
  830. DT_UINT16, DT_INT32, DT_INT64, DT_DOUBLE, DT_FLOAT, DT_FLOAT16, \
  831. DT_COMPLEX64, DT_COMPLEX128, DT_RESOURCE, DT_STRING}))
  832. .OUTPUT(shape, TensorType({DT_INT64}))
  833. .REQUIRED_ATTR(dtype, Type)
  834. .OP_END_FACTORY_REG(DeserializeManySparse)
  835. } // namespace ge
  836. #endif // GE_OP_SPARSE_OPS_H_

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