Skip to content

Commit c79fb30

Browse files
author
Aapo Kyrola
committed
[sparse] use _sparse_coo_tensor_unsafe in coalesce for speedup
1 parent a6bb154 commit c79fb30

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

aten/src/ATen/native/sparse/cuda/SparseCUDATensor.cu

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,10 @@ SparseTensor coalesce_sparse_cuda(const SparseTensor& self) {
143143
}
144144
}
145145
////////////////////////////////////////////////////////////
146-
147-
SparseTensor dst = ::at::native::sparse_coo_tensor(newIndices, newValues, self.sizes())._coalesced_(true);
146+
// We can use unsafe sparse tensor constructor because the indices do not
147+
// need to be revalidated as we do not add or change indices, just remove
148+
// duplicates.
149+
SparseTensor dst = ::at::native::_sparse_coo_tensor_unsafe(newIndices, newValues, self.sizes())._coalesced_(true);
148150

149151
THCudaCheck(cudaGetLastError());
150152
return dst;

0 commit comments

Comments
 (0)