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

Commit

Permalink
Merge pull request #393 from allisonvacanti/enable_min_max_tests
Browse files Browse the repository at this point in the history
Fix some min/max macro collisions with windows.h
  • Loading branch information
alliepiper authored Feb 8, 2022
2 parents 93f26ab + 69079eb commit 6261346
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
12 changes: 7 additions & 5 deletions cmake/header_test.in
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,19 @@

// Hacky way to build a string, but it works on all tested platforms.
#define CUB_MACRO_CHECK(MACRO, HEADER) \
CUB_MACRO_CHECK_IMPL(Identifier MACRO should not be used from Thrust \
headers due to conflicts with HEADER.)
CUB_MACRO_CHECK_IMPL(Identifier MACRO should not be used from CUB \
headers due to conflicts with HEADER macros.)

// complex.h conflicts
#define I CUB_MACRO_CHECK('I', complex.h)

// windows.h conflicts
// Disabling for now; we use min/max in many places, but since most
// projects build with NOMINMAX this doesn't seem to be high priority to fix.
#define small CUB_MACRO_CHECK('small', windows.h)
// We can't enable these checks without breaking some builds -- some standard
// library implementations unconditionally `#undef` these macros, which then
// causes random failures later.
// Leaving these commented out as a warning: Here be dragons.
//#define min(...) CUB_MACRO_CHECK('min', windows.h)
//#define max(...) CUB_MACRO_CHECK('max', windows.h)
#define small CUB_MACRO_CHECK('small', windows.h)

#include <cub/${header}>
2 changes: 1 addition & 1 deletion test/bfloat16.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ struct bfloat16_t

/// numeric_traits<bfloat16_t>::max
__host__ __device__ __forceinline__
static bfloat16_t max() {
static bfloat16_t (max)() {
uint16_t max_word = 0x7F7F;
return reinterpret_cast<bfloat16_t&>(max_word);
}
Expand Down
4 changes: 2 additions & 2 deletions test/half.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ struct half_t

/// numeric_traits<half_t>::max
__host__ __device__ __forceinline__
static half_t max() {
static half_t (max)() {
uint16_t max_word = 0x7BFF;
return reinterpret_cast<half_t&>(max_word);
}
Expand Down Expand Up @@ -315,7 +315,7 @@ std::ostream& operator<<(std::ostream &out, const __half &x)
template <>
struct CUB_NS_QUALIFIER::FpLimits<half_t>
{
static __host__ __device__ __forceinline__ half_t Max() { return half_t::max(); }
static __host__ __device__ __forceinline__ half_t Max() { return (half_t::max)(); }

static __host__ __device__ __forceinline__ half_t Lowest() { return half_t::lowest(); }
};
Expand Down
14 changes: 7 additions & 7 deletions test/test_device_segmented_sort.cu
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ public:
InputDescription& add(const SizeGroupDescription &group)
{
if (static_cast<std::size_t>(group.segment_size) <
static_cast<std::size_t>(std::numeric_limits<KeyT>::max()))
static_cast<std::size_t>((std::numeric_limits<KeyT>::max)()))
{
for (int i = 0; i < group.segments; i++)
{
Expand Down Expand Up @@ -1244,8 +1244,8 @@ void RandomizeInput(thrust::host_vector<KeyT> &h_keys,
{
for (std::size_t i = 0; i < h_keys.size(); i++)
{
h_keys[i] = RandomValue(std::numeric_limits<KeyT>::max());
h_values[i] = RandomValue(std::numeric_limits<ValueT>::max());
h_keys[i] = RandomValue((std::numeric_limits<KeyT>::max)());
h_values[i] = RandomValue((std::numeric_limits<ValueT>::max)());
}
}

Expand All @@ -1255,8 +1255,8 @@ void RandomizeInput(thrust::host_vector<half_t> &h_keys,
{
for (std::size_t i = 0; i < h_keys.size(); i++)
{
h_keys[i] = RandomValue(std::numeric_limits<int>::max());
h_values[i] = RandomValue(std::numeric_limits<std::uint32_t>::max());
h_keys[i] = RandomValue((std::numeric_limits<int>::max)());
h_values[i] = RandomValue((std::numeric_limits<std::uint32_t>::max)());
}
}
#endif
Expand All @@ -1267,8 +1267,8 @@ void RandomizeInput(thrust::host_vector<bfloat16_t> &h_keys,
{
for (std::size_t i = 0; i < h_keys.size(); i++)
{
h_keys[i] = RandomValue(std::numeric_limits<int>::max());
h_values[i] = RandomValue(std::numeric_limits<std::uint32_t>::max());
h_keys[i] = RandomValue((std::numeric_limits<int>::max)());
h_values[i] = RandomValue((std::numeric_limits<std::uint32_t>::max)());
}
}
#endif
Expand Down

0 comments on commit 6261346

Please sign in to comment.