cub icon indicating copy to clipboard operation
cub copied to clipboard

Device-scope segmented reduce temp storage allocation issue

Open gevtushenko opened this issue 3 years ago • 0 comments

Device-scope segmented reduce contains the following short-circuit:

if (num_segments <= 0)
{
  return cudaSuccess;
}

which happens before temp_storage_bytes is initialized. The issue might take place:

size_t temp_storage_bytes; // <- uninitialized
cub::DeviceSegmentedReduce::Reduce(nullptr, temp_storage_bytes);
thrust::device_vector<char> temp_storage(temp_storage_bytes); // <- allocate random amount of memory

We guarantee to overwrite temp_storage_bytes in the docs. Therefore, we should fix this.

gevtushenko avatar Jul 19 '22 13:07 gevtushenko