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

Fix host only compilation of <cuda/std/cmath> #234

Merged
merged 4 commits into from
Feb 13, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 3 additions & 1 deletion include/cuda/std/cmath
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@

#include "detail/__pragma_push"

#ifndef _LIBCUDACXX_COMPILER_NVRTC
#include <math.h>
#endif
#include "detail/libcxx/include/cmath"

#include "detail/__pragma_pop"

#endif //_CUDA_CMATH


5 changes: 5 additions & 0 deletions include/cuda/std/detail/libcxx/include/__config
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,11 @@ typedef __char32_t char32_t;
#define _LIBCUDACXX_HAS_NO_ASAN
#endif

// GCC implemented P0030R1 in 7.0, maybe only available under experimental?
#if _GNUC_VER < 700
#define _LIBCUDACXX_NO_HOST_CPP17_HYPOT
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see a use of this in cmath that's being removed in this PR. Is this still needed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed!

#endif

#if _GNUC_VER < 600 && defined(_LIBCUDACXX_COMPILER_NVCC)
#define _LIBCUDACXX_MISSING_GCC_MATH_INTRINSICS
#endif
Expand Down
24 changes: 20 additions & 4 deletions include/cuda/std/detail/libcxx/include/cmath
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ using ::tgammal;
using ::truncl;
#endif

#if _LIBCUDACXX_STD_VER > 14 && (defined(_LIBCUDACXX_NO_HOST_CPP17_HYPOT) || !defined(_LIBCUDACXX_COMPILER_NVCC))
#if _LIBCUDACXX_STD_VER > 14 && !defined(__cuda_std__)
inline _LIBCUDACXX_INLINE_VISIBILITY float hypot( float x, float y, float z ) { return sqrt(x*x + y*y + z*z); }
inline _LIBCUDACXX_INLINE_VISIBILITY double hypot( double x, double y, double z ) { return sqrt(x*x + y*y + z*z); }
#ifdef _LIBCUDACXX_HAS_COMPLEX_LONG_DOUBLE
Expand Down Expand Up @@ -596,7 +596,13 @@ _LIBCUDACXX_INLINE_VISIBILITY
_LIBCUDACXX_CONSTEXPR typename enable_if<is_floating_point<_A1>::value, bool>::type
__libcpp_isnan_or_builtin(_A1 __lcpp_x) _NOEXCEPT
{
return isnan(static_cast<double>(__lcpp_x));
#if defined(__CUDA_ARCH__)
return __isnan(__lcpp_x);
#elif __has_builtin(__builtin_isnan)
return __builtin_isnan(__lcpp_x);
#else
return isnan(__lcpp_x);
#endif
}

template <class _A1>
Expand All @@ -612,7 +618,13 @@ _LIBCUDACXX_INLINE_VISIBILITY
_LIBCUDACXX_CONSTEXPR typename enable_if<is_floating_point<_A1>::value, bool>::type
__libcpp_isinf_or_builtin(_A1 __lcpp_x) _NOEXCEPT
{
return isinf(static_cast<double>(__lcpp_x));
#if defined(__CUDA_ARCH__)
return __isinf(__lcpp_x);
#elif __has_builtin(__builtin_isnan)
return __builtin_isinf(__lcpp_x);
#else
return isinf(__lcpp_x);
#endif
}

template <class _A1>
Expand All @@ -628,7 +640,11 @@ _LIBCUDACXX_INLINE_VISIBILITY
_LIBCUDACXX_CONSTEXPR typename enable_if<is_floating_point<_A1>::value, bool>::type
__libcpp_isfinite_or_builtin(_A1 __lcpp_x) _NOEXCEPT
{
return isfinite(static_cast<double>(__lcpp_x));
#if !defined(__CUDA_ARCH__) && __has_builtin(__builtin_isnan)
return __builtin_isfinite(__lcpp_x);
#else
return isfinite(__lcpp_x);
#endif
}

template <class _A1>
Expand Down