Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Commit

Permalink
Add early return for empty input to DeviceSegmentedRadixSort.
Browse files Browse the repository at this point in the history
  • Loading branch information
alliepiper committed Nov 19, 2021
1 parent 99c2931 commit 1388078
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions cub/device/dispatch/dispatch_radix_sort.cuh
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/******************************************************************************
* Copyright (c) 2011, Duane Merrill. All rights reserved.
* Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved.
Expand Down Expand Up @@ -1050,10 +1049,6 @@ struct DispatchRadixSort :
break;
}

// Return if empty problem
if (num_items == 0)
break;

// Log single_tile_kernel configuration
if (debug_synchronous)
_CubLog("Invoking single_tile_kernel<<<%d, %d, 0, %lld>>>(), %d items per thread, %d SM occupancy, current bit %d, bit_grain %d\n",
Expand Down Expand Up @@ -1561,6 +1556,17 @@ struct DispatchRadixSort :
typedef typename DispatchRadixSort::MaxPolicy MaxPolicyT;
typedef typename ActivePolicyT::SingleTilePolicy SingleTilePolicyT;

// Return if empty problem
if (num_items == 0)
{
if (d_temp_storage == nullptr)
{
temp_storage_bytes = 1;
}

return cudaSuccess;
}

// Force kernel code-generation in all compiler passes
if (num_items <= (SingleTilePolicyT::BLOCK_THREADS * SingleTilePolicyT::ITEMS_PER_THREAD))
{
Expand Down Expand Up @@ -1904,6 +1910,17 @@ struct DispatchSegmentedRadixSort :
{
typedef typename DispatchSegmentedRadixSort::MaxPolicy MaxPolicyT;

// Return if empty problem
if (num_items == 0)
{
if (d_temp_storage == nullptr)
{
temp_storage_bytes = 1;
}

return cudaSuccess;
}

// Force kernel code-generation in all compiler passes
return InvokePasses<ActivePolicyT>(
DeviceSegmentedRadixSortKernel<MaxPolicyT, false, IS_DESCENDING, KeyT, ValueT, BeginOffsetIteratorT, EndOffsetIteratorT, OffsetT>,
Expand Down

0 comments on commit 1388078

Please sign in to comment.