Skip to content

Commit 6e78aa0

Browse files
committed
Fix kernel error if sparse visual hull field is empty
1 parent 649356b commit 6e78aa0

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/torchhull/_C/src/visual_hull_cuda.cu

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -834,17 +834,20 @@ sparse_visual_hull_field_cuda(const torch::Tensor& masks,
834834
auto sparse_indices_unraveled = torch::empty({ 4, N }, dtype_int64);
835835
auto sparse_indices = sparse_volume.indices();
836836

837-
const int threads_per_block = 128;
838-
dim3 grid_corners;
839-
at::cuda::getApplyGrid(N, grid_corners, masks.device().index(), threads_per_block);
840-
dim3 threads = at::cuda::getApplyBlock(threads_per_block);
841-
842-
extract_sparse_indices<<<grid_corners, threads, 0, stream>>>(
843-
sparse_indices.packed_accessor64<int64_t, 1, torch::RestrictPtrTraits>(),
844-
resolution_cells,
845-
sparse_indices_unraveled.packed_accessor64<int64_t, 2, torch::RestrictPtrTraits>());
846-
AT_CUDA_CHECK(cudaGetLastError());
847-
AT_CUDA_CHECK(cudaStreamSynchronize(stream));
837+
if (N != 0)
838+
{
839+
const int threads_per_block = 128;
840+
dim3 grid_corners;
841+
at::cuda::getApplyGrid(N, grid_corners, masks.device().index(), threads_per_block);
842+
dim3 threads = at::cuda::getApplyBlock(threads_per_block);
843+
844+
extract_sparse_indices<<<grid_corners, threads, 0, stream>>>(
845+
sparse_indices.packed_accessor64<int64_t, 1, torch::RestrictPtrTraits>(),
846+
resolution_cells,
847+
sparse_indices_unraveled.packed_accessor64<int64_t, 2, torch::RestrictPtrTraits>());
848+
AT_CUDA_CHECK(cudaGetLastError());
849+
AT_CUDA_CHECK(cudaStreamSynchronize(stream));
850+
}
848851

849852
auto sparse_field =
850853
torch::sparse_coo_tensor(sparse_indices_unraveled,

0 commit comments

Comments
 (0)