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

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