Skip to content

Commit 874ec9b

Browse files
authored
Fix nvcc warnings about using std::numeric_limits in device functions (#440)
* Fix nvcc warnings about using std::numeric_limits in device functions * Use using-declarations
1 parent bcfcc9e commit 874ec9b

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

include/experimental/__p0009_bits/utility.hpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
#include <type_traits>
55
#include <array>
66
#include <utility>
7+
#ifdef MDSPAN_IMPL_HAS_CUDA
8+
#include <cuda/std/limits>
9+
#else
10+
#include <limits>
11+
#endif
712
#include "macros.hpp"
813

914
namespace MDSPAN_IMPL_STANDARD_NAMESPACE {
@@ -198,8 +203,13 @@ MDSPAN_INLINE_FUNCTION constexpr bool cmp_greater_equal(T t, U u) noexcept {
198203

199204
template <class R, class T>
200205
MDSPAN_INLINE_FUNCTION constexpr bool in_range(T t) noexcept {
201-
return cmp_greater_equal(t, std::numeric_limits<R>::min()) &&
202-
cmp_less_equal(t, std::numeric_limits<R>::max());
206+
#ifdef MDSPAN_IMPL_HAS_CUDA
207+
using cuda::std::numeric_limits;
208+
#else
209+
using std::numeric_limits;
210+
#endif
211+
return cmp_greater_equal(t, numeric_limits<R>::min()) &&
212+
cmp_less_equal(t, numeric_limits<R>::max());
203213
}
204214

205215
template <typename T >
@@ -216,7 +226,12 @@ check_mul_result_is_nonnegative_and_representable(T a, T b) {
216226
if constexpr (std::is_signed_v<T>) {
217227
if ( a < 0 || b < 0 ) return false;
218228
}
219-
return a <= std::numeric_limits<T>::max() / b;
229+
#ifdef MDSPAN_IMPL_HAS_CUDA
230+
using cuda::std::numeric_limits;
231+
#else
232+
using std::numeric_limits;
233+
#endif
234+
return a <= numeric_limits<T>::max() / b;
220235
#endif
221236
}
222237
#endif

0 commit comments

Comments
 (0)