Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guard against an overflow in sort tests #1980

Merged
merged 1 commit into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion cub/test/catch2_test_device_merge_sort.cu
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ struct index_to_key_value_op
static_cast<std::size_t>(::cuda::std::numeric_limits<UnsignedIntegralKeyT>::max());
static constexpr std::size_t lowest_key_value =
static_cast<std::size_t>(::cuda::std::numeric_limits<UnsignedIntegralKeyT>::lowest());
static_assert(sizeof(UnsignedIntegralKeyT) < sizeof(std::size_t),
"Calculation of num_distinct_key_values would overflow");
static constexpr std::size_t num_distinct_key_values = (max_key_value - lowest_key_value + std::size_t{1ULL});

__device__ __host__ UnsignedIntegralKeyT operator()(std::size_t index)
Expand All @@ -166,6 +168,8 @@ private:
static_cast<std::size_t>(::cuda::std::numeric_limits<UnsignedIntegralKeyT>::max());
static constexpr std::size_t lowest_key_value =
static_cast<std::size_t>(::cuda::std::numeric_limits<UnsignedIntegralKeyT>::lowest());
static_assert(sizeof(UnsignedIntegralKeyT) < sizeof(std::size_t),
"Calculation of num_distinct_key_values would overflow");
static constexpr std::size_t num_distinct_key_values = (max_key_value - lowest_key_value + std::size_t{1ULL});

// item_count / num_distinct_key_values
Expand Down Expand Up @@ -406,7 +410,7 @@ CUB_TEST("DeviceMergeSort::StableSortPairs works for large inputs", "[merge][sor
{
using testing_types_tuple = c2h::get<0, TestType>;
using key_t = typename testing_types_tuple::key_t;
using offset_t = typename c2h::get<0, TestType>::offset_t;
using offset_t = typename testing_types_tuple::offset_t;

// Clamp 64-bit offset type problem sizes to just slightly larger than 2^32 items
auto num_items_ull =
Expand Down
4 changes: 4 additions & 0 deletions thrust/testing/cuda/sort.cu
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ struct index_to_key_value_op
static_cast<std::size_t>(::cuda::std::numeric_limits<UnsignedIntegralKeyT>::max());
static constexpr std::size_t lowest_key_value =
static_cast<std::size_t>(::cuda::std::numeric_limits<UnsignedIntegralKeyT>::lowest());
static_assert(sizeof(UnsignedIntegralKeyT) < sizeof(std::size_t),
"Calculation of num_distinct_key_values would overflow");
static constexpr std::size_t num_distinct_key_values = (max_key_value - lowest_key_value + std::size_t{1ULL});

__device__ __host__ UnsignedIntegralKeyT operator()(std::size_t index)
Expand All @@ -197,6 +199,8 @@ private:
static_cast<std::size_t>(::cuda::std::numeric_limits<UnsignedIntegralKeyT>::max());
static constexpr std::size_t lowest_key_value =
static_cast<std::size_t>(::cuda::std::numeric_limits<UnsignedIntegralKeyT>::lowest());
static_assert(sizeof(UnsignedIntegralKeyT) < sizeof(std::size_t),
"Calculation of num_distinct_key_values would overflow");
static constexpr std::size_t num_distinct_key_values = (max_key_value - lowest_key_value + std::size_t{1ULL});

// item_count / num_distinct_key_values
Expand Down
Loading