Skip to content

Commit

Permalink
Use CUDA min/max built-in functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
ptal committed Aug 26, 2024
1 parent eb46ab9 commit b19c84e
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions include/battery/utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,23 +113,25 @@ CUDA inline int strcmp(const char* s1, const char* s2) {
#endif
}

template<class T> CUDA constexpr T min(T a, T b) {
template<class T> CUDA INLINE constexpr T min(T a, T b) {
#ifdef __CUDA_ARCH__
// When C++23 is available
// if !consteval { return ::min(a, b); }
// else { return std::min(a, b); }
return a < b ? a : b;
// return a < b ? a : b;
return ::min(a, b);
#else
return std::min(a, b);
#endif
}

template<class T> CUDA constexpr T max(T a, T b) {
template<class T> CUDA INLINE constexpr T max(T a, T b) {
#ifdef __CUDA_ARCH__
// When C++23 is available
// if !consteval { return ::max(a, b); }
// else { return std::max(a, b); }
return a > b ? a : b;
// return a > b ? a : b;
return ::max(a, b); // a > b ? a : b;
#else
return std::max(a, b);
#endif
Expand Down

0 comments on commit b19c84e

Please sign in to comment.