Skip to content

Commit

Permalink
Fix assert definition for NVHPC due to constexpr issues (NVIDIA#3418)
Browse files Browse the repository at this point in the history
NVHPC cannot decide at compile time where the code would run so _CCCL_ASSERT within a constexpr function breaks it.

Fix this by always using the host definition which should also work on device.

Fixes NVIDIA#3411
  • Loading branch information
miscco authored and davebayer committed Jan 18, 2025
1 parent f04f0fd commit 79ebc16
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions libcudacxx/include/cuda/std/__cccl/assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,14 @@ _CCCL_HOST_DEVICE

//! _CCCL_VERIFY is enabled unconditionally and reserved for critical checks that are required to always be on
//! _CCCL_ASSERT is enabled conditionally depending on CCCL_ENABLE_HOST_ASSERTIONS and CCCL_ENABLE_DEVICE_ASSERTIONS
#if _CCCL_CUDA_COMPILER(NVHPC) // NVHPC needs to use NV_IF_TARGET instead of __CUDA_ARCH__
# define _CCCL_VERIFY(expression, message) \
NV_IF_ELSE_TARGET( \
NV_IS_DEVICE, (_CCCL_ASSERT_IMPL_DEVICE(expression, message);), (_CCCL_ASSERT_IMPL_HOST(expression, message);))
# define _CCCL_ASSERT(expression, message) \
NV_IF_ELSE_TARGET( \
NV_IS_DEVICE, (_CCCL_ASSERT_DEVICE(expression, message);), (_CCCL_ASSERT_HOST(expression, message);))
#if _CCCL_CUDA_COMPILER(NVHPC) // NVHPC can't have different behavior for host and device.
// The host version of the assert will also work in device code.
# define _CCCL_VERIFY(expression, message) _CCCL_ASSERT_IMPL_HOST(expression, message)
# if defined(CCCL_ENABLE_HOST_ASSERTIONS) || defined(CCCL_ENABLE_DEVICE_ASSERTIONS)
# define _CCCL_ASSERT(expression, message) _CCCL_ASSERT_HOST(expression, message)
# else
# define _CCCL_ASSERT(expression, message) ((void) 0)
# endif
#elif _CCCL_HAS_CUDA_COMPILER
# ifdef __CUDA_ARCH__
# define _CCCL_VERIFY(expression, message) _CCCL_ASSERT_IMPL_DEVICE(expression, message)
Expand Down

0 comments on commit 79ebc16

Please sign in to comment.