Skip to content

Commit

Permalink
Add early exit in sparse_async_cumsum ops (#2202)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #2202

This diff adds an early exit in sparse_async_cumsum ops. When the size(s) of input tensor are zeor(s) ops return zero tensor.

Reviewed By: jspark1105, sryap, jasonjk-park

Differential Revision: D51999938

fbshipit-source-id: 5c2151a01f547666a1e1742f334953c01dbf6630
  • Loading branch information
Mark Eremeev authored and facebook-github-bot committed Dec 12, 2023
1 parent 9747336 commit a029c50
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
9 changes: 9 additions & 0 deletions fbgemm_gpu/src/sparse_ops/sparse_async_cumsum.cu
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ using Tensor = at::Tensor;
namespace fbgemm_gpu {

DLL_PUBLIC Tensor asynchronous_inclusive_cumsum_gpu(const Tensor& t_in) {
if (t_in.numel() == 0) {
return at::zeros_like(t_in);
}
TENSOR_ON_CUDA_GPU(t_in);

at::cuda::OptionalCUDAGuard device_guard;
Expand Down Expand Up @@ -54,6 +57,9 @@ DLL_PUBLIC Tensor asynchronous_inclusive_cumsum_gpu(const Tensor& t_in) {
}

DLL_PUBLIC Tensor asynchronous_exclusive_cumsum_gpu(const Tensor& t_in) {
if (t_in.numel() == 0) {
return at::zeros_like(t_in);
}
TENSOR_ON_CUDA_GPU(t_in);

at::cuda::OptionalCUDAGuard device_guard;
Expand Down Expand Up @@ -95,6 +101,9 @@ DLL_PUBLIC Tensor asynchronous_exclusive_cumsum_gpu(const Tensor& t_in) {
}

DLL_PUBLIC Tensor asynchronous_complete_cumsum_gpu(const Tensor& t_in) {
if (t_in.numel() == 0) {
return at::zeros({t_in.numel() + 1}, t_in.options());
}
TENSOR_ON_CUDA_GPU(t_in);

at::cuda::OptionalCUDAGuard device_guard;
Expand Down
6 changes: 3 additions & 3 deletions fbgemm_gpu/test/sparse_ops_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ def test_block_bucketize_sparse_features_long_indices(
torch.testing.assert_close(new_indices_gpu.cpu(), new_indices_cpu)

@given(
n=st.integers(min_value=1, max_value=100),
n=st.integers(min_value=0, max_value=100),
long_index=st.booleans(),
)
@settings(verbosity=Verbosity.verbose, max_examples=20, deadline=None)
Expand Down Expand Up @@ -655,8 +655,8 @@ def test_cumsum(self, n: int, long_index: bool) -> None:
)

@given(
n=st.integers(min_value=1, max_value=600),
b=st.integers(min_value=1, max_value=10),
n=st.integers(min_value=0, max_value=600),
b=st.integers(min_value=0, max_value=10),
long_index=st.booleans(),
)
@settings(verbosity=Verbosity.verbose, max_examples=20, deadline=None)
Expand Down

0 comments on commit a029c50

Please sign in to comment.