-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
remove ALPAKA_ASSERT_OFFLOAD
, introduce ALPAKA_ASSERT_ACC
#2199
remove ALPAKA_ASSERT_OFFLOAD
, introduce ALPAKA_ASSERT_ACC
#2199
Conversation
Hi @psychocoderHPC, thanks for the PR. Is it the intent that people should always use I ask because I'm wondering if the check on Something like /// The assert can be explicitly disabled by defining NDEBUG
#if defined(ALPAKA_ACC_SYCL_ENABLED) && defined(__SYCL_DEVICE_ONLY__)
// SYCL device compilation
# if defined(SYCL_EXT_ONEAPI_ASSERT)
# define ALPAKA_ASSERT(...) assert(__VA_ARGS__)
# else
# define ALPAKA_ASSERT(...) ALPAKA_NOOP(__VA_ARGS__)
# endif
#else
// non-SYCL device compilation
# define ALPAKA_ASSERT(...) assert(__VA_ARGS__)
#endif
/// Assert for usage within device code which can be disabled independently from NDEBUG.
#if defined(ALPAKA_DISABLE_ASSERT_ACC)
# define ALPAKA_ASSERT_ACC(...) ALPAKA_NOOP(__VA_ARGS__)
#else
# define ALPAKA_ASSERT_ACC(...) ALPAKA_ASSERT(__VA_ARGS__)
#endif |
Another thing: when the "device" is actually the cpu (e.g. device code compiled for So, if none of |
Yes from my side it was intended that we have an assert for the host site and the usage within the device code. Never the less I can change it if needed. |
We can handle asserts differently depending on which accelerator is enabled. The drawback would be that in this case, a kernel with asserts executed with the CUDA backend will behave slightly differently compared to the kernel that is running with a CPU accelerator. |
Indeed, by "CPU" I really meant "compiled by the standard compiler, like |
I would say that if we document something like
then it should be changed. If instead we document
there is no need to change it. |
With some delay, here is what I have in mind: // ALPAKA_ASSERT_ACC_IMPL is an assert-like macro.
// It can be disabled setting the ALPAKA_DISABLE_ASSERT_ACC preprocessor symbol or the NDEBUG preprocessor symbol.
#if !defined(ALPAKA_DISABLE_ASSERT_ACC)
# define ALPAKA_ASSERT_ACC_IMPL(...) ALPAKA_ASSERT(__VA_ARGS__)
#else
# define ALPAKA_ASSERT_ACC_IMPL(...) ALPAKA_NOOP(__VA_ARGS__)
#endif
// ALPAKA_ASSERT_ACC is an assert-like macro.
// In device code for a GPU or SYCL backend it can be disabled setting the ALPAKA_DISABLE_ASSERT_ACC preprocessor
// symbol or the NDEBUG preprocessor symbol. In device code for a native C++ CPU backend and in host code, it is
// equivalent to ALPAKA_ASSERT, and can be disabled setting the NDEBUG preprocessor symbol.
#if defined(ALPAKA_ACC_GPU_CUDA_ENABLED) && defined(__CUDA_ARCH__)
// CUDA device code
# define ALPAKA_ASSERT_ACC(...) ALPAKA_ASSERT_ACC_IMPL(__VA_ARGS__)
#elif defined(ALPAKA_ACC_GPU_HIP_ENABLED) && defined(__HIP_DEVICE_COMPILE__)
// HIP/ROCm device code
# define ALPAKA_ASSERT_ACC(...) ALPAKA_ASSERT_ACC_IMPL(__VA_ARGS__)
#elif defined(ALPAKA_ACC_SYCL_ENABLED) && defined(__SYCL_DEVICE_ONLY__)
// SYCL/oneAPI device code
# if defined(SYCL_EXT_ONEAPI_ASSERT)
# define ALPAKA_ASSERT_ACC(...) ALPAKA_ASSERT_ACC_IMPL(__VA_ARGS__)
# else
# define ALPAKA_ASSERT_ACC(...) ALPAKA_NOOP(__VA_ARGS__)
# endif
// add here any other #elif conditions for non-CPU backends
// ...
#else
// CPU backend, or host code
# define ALPAKA_ASSERT_ACC(...) ALPAKA_ASSERT(__VA_ARGS__)
#endif I've split off the check on |
85975ce
to
940c565
Compare
I updated the PR with the suggestion from @fwyzard and added him as a co-author. |
PR can be merged, the failing CI test is not required and is already fixed with #2208 |
fix alpaka-group#2186 fix alpaka-group#2001 Provide a device side assert `ALPAKA_ASSERT_ACC` which can be disabled by defining `ALPAKA_DISABLE_ASSERT_ACC` the C++ code or by the CMake option `alpaka_ASSERT_ACC_ENABLE`. For CPU devices or host side code the assert behaves like`ALPAKA_ASSERT`. Co-authored-by: Andrea Bocci <[email protected]>
940c565
to
4da32a5
Compare
fix #2186
fix #2001
Provide a device side assert
ALPAKA_ASSERT_ACC
that can be disabled by definingALPAKA_DISABLE_ASSERT_ACC
in the C++ code or by the CMake optionalpaka_ASSERT_ACC_ENABLE
In #2186 the footnote says that assert on the device can have a huge impact on the performance, therefore I added the possibility to force disable the device side asserts.
The naming for the CMake option follows the name schema we use for other options in CMake.