Skip to content

Commit

Permalink
Ensure that we only use the inline variable trait when it is actually…
Browse files Browse the repository at this point in the history
… available (NVIDIA#2712)

* Ensure that we only use the inline variable trait when it is actually available

* Use the right define for internal traits
  • Loading branch information
miscco authored Nov 6, 2024
1 parent c97f2e3 commit 2864f2b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
13 changes: 7 additions & 6 deletions libcudacxx/include/cuda/std/__cccl/dialect.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,6 @@
# define _CCCL_ELSE_IF_CONSTEXPR else if
#endif // _CCCL_STD_VER <= 2014

#if _CCCL_STD_VER >= 2017
# define _CCCL_TRAIT(__TRAIT, ...) __TRAIT##_v<__VA_ARGS__>
#else // ^^^ C++17 ^^^ / vvv C++14 vvv
# define _CCCL_TRAIT(__TRAIT, ...) __TRAIT<__VA_ARGS__>::value
#endif // _CCCL_STD_VER <= 2014

// In nvcc prior to 11.3 global variables could not be marked constexpr
#if defined(_CCCL_CUDACC_BELOW_11_3)
# define _CCCL_CONSTEXPR_GLOBAL const
Expand All @@ -110,6 +104,13 @@
# define _CCCL_NO_VARIABLE_TEMPLATES
#endif // _CCCL_STD_VER <= 2011

// Variable templates are more efficient most of the time, so we want to use them rather than structs when possible
#if defined(_CCCL_NO_VARIABLE_TEMPLATES)
# define _CCCL_TRAIT(__TRAIT, ...) __TRAIT<__VA_ARGS__>::value
#else // ^^^ _CCCL_NO_VARIABLE_TEMPLATES ^^^ / vvv !_CCCL_NO_VARIABLE_TEMPLATES vvv
# define _CCCL_TRAIT(__TRAIT, ...) __TRAIT##_v<__VA_ARGS__>
#endif // !_CCCL_NO_VARIABLE_TEMPLATES

// We need to treat host and device separately
#if defined(__CUDA_ARCH__)
# define _CCCL_GLOBAL_CONSTANT _CCCL_DEVICE _CCCL_CONSTEXPR_GLOBAL
Expand Down
11 changes: 5 additions & 6 deletions libcudacxx/include/cuda/std/__memory/allocator_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,21 @@ _CCCL_NV_DIAG_SUPPRESS(1215)

_LIBCUDACXX_BEGIN_NAMESPACE_STD

#if _CCCL_STD_VER <= 2014
#if defined(_CCCL_NO_VARIABLE_TEMPLATES)
# define _LIBCUDACXX_ALLOCATOR_TRAITS_HAS_XXX(NAME, PROPERTY) \
template <class _Tp, class = void> \
struct NAME : false_type \
{}; \
template <class _Tp> \
struct NAME<_Tp, void_t<typename _Tp::PROPERTY>> : true_type \
{}

#else // ^^^ _CCCL_STD_VER <= 2014 ^^^ / vvv _CCCL_STD_VER >= 2017 vvv
#else // ^^^ _CCCL_NO_VARIABLE_TEMPLATES ^^^ / vvv !_CCCL_NO_VARIABLE_TEMPLATES vvv
# define _LIBCUDACXX_ALLOCATOR_TRAITS_HAS_XXX(NAME, PROPERTY) \
template <class _Tp, class = void> \
inline constexpr bool NAME##_v = false; \
_CCCL_INLINE_VAR constexpr bool NAME##_v = false; \
template <class _Tp> \
inline constexpr bool NAME##_v<_Tp, void_t<typename _Tp::PROPERTY>> = true;
#endif // _CCCL_STD_VER >= 2017
_CCCL_INLINE_VAR constexpr bool NAME##_v<_Tp, void_t<typename _Tp::PROPERTY>> = true;
#endif // !_CCCL_NO_VARIABLE_TEMPLATES

// __pointer
_LIBCUDACXX_ALLOCATOR_TRAITS_HAS_XXX(__has_pointer, pointer);
Expand Down
6 changes: 3 additions & 3 deletions libcudacxx/include/cuda/std/__memory/uses_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

_LIBCUDACXX_BEGIN_NAMESPACE_STD

#if _CCCL_STD_VER <= 2014
#if defined(_CCCL_NO_VARIABLE_TEMPLATES)
template <class _Tp, class = void>
struct __has_allocator_type : false_type
{};
Expand All @@ -42,7 +42,7 @@ struct __uses_allocator : false_type
template <class _Tp, class _Alloc>
struct __uses_allocator<_Tp, _Alloc, true> : is_convertible<_Alloc, typename _Tp::allocator_type>
{};
#else // ^^^ _CCCL_STD_VER <= 2014 ^^^ / vvv _CCCL_STD_VER >= 2017 vvv
#else // ^^^ _CCCL_NO_VARIABLE_TEMPLATES ^^^ / vvv !_CCCL_NO_VARIABLE_TEMPLATES vvv
template <class _Tp, class = void>
_CCCL_INLINE_VAR constexpr bool __has_allocator_type_v = false;
template <class _Tp>
Expand All @@ -53,7 +53,7 @@ _CCCL_INLINE_VAR constexpr bool __uses_allocator_v = false;
template <class _Tp, class _Alloc>
_CCCL_INLINE_VAR constexpr bool __uses_allocator_v<_Tp, _Alloc, true> =
is_convertible_v<_Alloc, typename _Tp::allocator_type>;
#endif // _CCCL_STD_VER >= 2017
#endif // !_CCCL_NO_VARIABLE_TEMPLATES

template <class _Tp, class _Alloc>
struct _CCCL_TYPE_VISIBILITY_DEFAULT uses_allocator
Expand Down

0 comments on commit 2864f2b

Please sign in to comment.