diff --git a/libcudacxx/include/cuda/std/__cccl/assert.h b/libcudacxx/include/cuda/std/__cccl/assert.h index b774225a61..8a5c483a2f 100644 --- a/libcudacxx/include/cuda/std/__cccl/assert.h +++ b/libcudacxx/include/cuda/std/__cccl/assert.h @@ -24,6 +24,8 @@ #include +#include + #if defined(_DEBUG) || defined(DEBUG) # ifndef _CCCL_ENABLE_DEBUG_MODE # define _CCCL_ENABLE_DEBUG_MODE @@ -51,60 +53,51 @@ # endif // CCCL_ENABLE_ASSERTIONS #endif // !CCCL_ENABLE_DEVICE_ASSERTIONS -//! Use internal nvcc implementation on device or the host library for clang-cuda -#ifdef __CUDA_ARCH__ -# ifdef CCCL_ENABLE_DEVICE_ASSERTIONS -# if defined(_CCCL_CUDA_COMPILER_NVCC) //! Use __assert_fail to implement device side asserts -# include -# define _CCCL_ASSERT_IMPL(expression, message) \ - __builtin_expect(static_cast(expression), 1) \ - ? (void) 0 \ - : __assert_fail(message, __FILE__, __LINE__, __func__) -# else // ^^^ _CCCL_CUDA_COMPILER_NVCC ^^^ / vvv !_CCCL_CUDA_COMPILER_NVCC vvv -# if __has_include(<__assert>) // libc++ uses _LIBCPP_ASSERT from <__assert> -# include <__assert> -# define _CCCL_ASSERT_IMPL(expression, message) _LIBCPP_ASSERT(expression, message) -# else // libstdc++ uses __glibcxx_assert from -# if defined(_GLIBCXX_RELEASE) && _GLIBCXX_RELEASE >= 12 -// libstdc++ does not fully qualify its use of `__is_constant_evaluated` -// It was introduced in the assert handling in 5e8a30d -// libstdc++ : Redefine __glibcxx_assert to work in C++ 23 constexpr -_LIBCUDACXX_BEGIN_NAMESPACE_STD -using ::std::__is_constant_evaluated; -_LIBCUDACXX_END_NAMESPACE_STD -# endif // _GLIBCXX_RELEASE >= 12 -# define _CCCL_ASSERT_IMPL(expression, message) __glibcxx_assert(expression) -# endif // libstdc++ -# endif // !_CCCL_CUDA_COMPILER_NVCC -# else // ^^^ CCCL_ENABLE_DEVICE_ASSERTIONS ^^^ / vvv !CCCL_ENABLE_DEVICE_ASSERTIONS vvv -# define _CCCL_ASSERT_IMPL -# endif // !CCCL_ENABLE_DEVICE_ASSERTIONS -#endif // __CUDA_ARCH__ - //! Use the different standard library implementations to implement host side asserts -#ifndef __CUDA_ARCH__ -# ifdef CCCL_ENABLE_HOST_ASSERTIONS -# if __has_include() // MSVC uses _STL_VERIFY from -# include -# define _CCCL_ASSERT_IMPL(expression, message) _STL_VERIFY(expression, message) -# elif __has_include(<__assert>) // libc++ uses _LIBCPP_ASSERT from <__assert> -# include <__assert> -# define _CCCL_ASSERT_IMPL(expression, message) _LIBCPP_ASSERT(expression, message) -# else // libstdc++ uses __glibcxx_assert from -# if defined(_GLIBCXX_RELEASE) && _GLIBCXX_RELEASE >= 12 +#ifdef CCCL_ENABLE_HOST_ASSERTIONS +# if __has_include() // MSVC uses _STL_VERIFY from +# include +# define _CCCL_ASSERT_HOST(expression, message) _STL_VERIFY(expression, message) +# elif __has_include(<__assert>) // libc++ uses _LIBCPP_ASSERT from <__assert> +# include <__assert> +# define _CCCL_ASSERT_HOST(expression, message) _LIBCPP_ASSERT(expression, message) +# elif __has_include() // libstdc++ uses __glibcxx_assert from +# if defined(_GLIBCXX_RELEASE) && _GLIBCXX_RELEASE >= 12 // libstdc++ does not fully qualify its use of `__is_constant_evaluated` // It was introduced in the assert handling in 5e8a30d // libstdc++ : Redefine __glibcxx_assert to work in C++ 23 constexpr _LIBCUDACXX_BEGIN_NAMESPACE_STD using ::std::__is_constant_evaluated; _LIBCUDACXX_END_NAMESPACE_STD -# endif // _GLIBCXX_RELEASE >= 12 -# define _CCCL_ASSERT_IMPL(expression, message) __glibcxx_assert(expression) -# endif // libstdc++ -# endif // !CCCL_ENABLE_HOST_ASSERTIONS -#endif // !__CUDA_ARCH__ +# endif // _GLIBCXX_RELEASE >= 12 +# define _CCCL_ASSERT_HOST(expression, message) __glibcxx_assert(expression) +# else // ^^^ libstdc++ ^^^ / vvv Unknown standard library vvv +# error "Unknown host standard library used." +# endif // Unknown standard library +#else // ^^^ CCCL_ENABLE_HOST_ASSERTIONS ^^^ / vvv !CCCL_ENABLE_HOST_ASSERTIONS vvv +# define _CCCL_ASSERT_HOST(expression, message) ((void) 0) +#endif // !CCCL_ENABLE_HOST_ASSERTIONS + +//! Use internal nvcc implementation on device or the host library for other cuda compilers +#ifdef CCCL_ENABLE_DEVICE_ASSERTIONS +# if defined(_CCCL_CUDA_COMPILER_NVCC) //! Use __assert_fail to implement device side asserts +# include +# define _CCCL_ASSERT_DEVICE(expression, message) \ + __builtin_expect(static_cast(expression), 1) \ + ? (void) 0 \ + : __assert_fail(message, __FILE__, __LINE__, __func__) +# elif defined(_CCCL_CUDA_COMPILER) +# define _CCCL_ASSERT_DEVICE(expression, message) _CCCL_ASSERT_HOST(expression, message) +# endif // _CCCL_CUDA_COMPILER +#else // ^^^ CCCL_ENABLE_DEVICE_ASSERTIONS ^^^ / vvv !CCCL_ENABLE_DEVICE_ASSERTIONS vvv +# define _CCCL_ASSERT_DEVICE(expression, message) ((void) 0) +#endif // !CCCL_ENABLE_DEVICE_ASSERTIONS + +//! Use the right assert in the right situation +#define _CCCL_ASSERT_IMPL(expression, message) \ + NV_IF_ELSE_TARGET( \ + NV_IS_DEVICE, (_CCCL_ASSERT_DEVICE(expression, message);), (_CCCL_ASSERT_HOST(expression, message);)) //! _CCCL_VERIFY is an unconditionally enabled assertion that is reserved for the most important checks //! Some compilers warn about `is_constant_evaluated()` in a non constexpr function, so silence that right away