Skip to content
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

improve ALPAKA_ASSERT_OFFLOAD #2001

Closed
fwyzard opened this issue Jul 11, 2023 · 0 comments · Fixed by #2199
Closed

improve ALPAKA_ASSERT_OFFLOAD #2001

fwyzard opened this issue Jul 11, 2023 · 0 comments · Fixed by #2199

Comments

@fwyzard
Copy link
Contributor

fwyzard commented Jul 11, 2023

It's not clear to me what the meaning of ALPAKA_ASSERT_OFFLOAD is :-)

The current definition is

#define ALPAKA_ASSERT(...) assert(__VA_ARGS__)

#if defined(ALPAKA_DEBUG_OFFLOAD_ASSUME_HOST) || defined(SYCL_EXT_ONEAPI_ASSERT)
#    define ALPAKA_ASSERT_OFFLOAD(EXPRESSION) ALPAKA_ASSERT(EXPRESSION)
#elif defined __AMDGCN__ && (!defined NDEBUG)
#    define ALPAKA_ASSERT_OFFLOAD(EXPRESSION)                                                                         \
        do                                                                                                            \
        {                                                                                                             \
            if(!(EXPRESSION))                                                                                         \
                __builtin_trap();                                                                                     \
        } while(false)
#else
#    define ALPAKA_ASSERT_OFFLOAD(EXPRESSION)                                                                         \
        do                                                                                                            \
        {                                                                                                             \
        } while(false)
#endif

So, if I interpret it correctly:

  • if ALPAKA_DEBUG_OFFLOAD_ASSUME_HOST is defined, ALPAKA_ASSERT_OFFLOAD expands to ALPAKA_ASSERT, which expands to assert, which expands to a runtime check only if NDEBUG is not defined;

  • if ALPAKA_DEBUG_OFFLOAD_ASSUME_HOST is not defined:

    • for the CPU backends, ALPAKA_ASSERT_OFFLOAD always expands to a no-op;
    • for the CUDA backend, ALPAKA_ASSERT_OFFLOAD always expands to a no-op;
    • for the ROCm backend, ALPAKA_ASSERT_OFFLOAD expands to a runtime check if NDEBUG is not defined;
    • for the SYCL backend, ALPAKA_ASSERT_OFFLOAD always expands to assert, so it expands to a runtime check if NDEBUG is not defined.

It looks like the behaviour is different for the different backends, which seems counter intuitive.

So... what is the expected behaviour ?

  1. always compile to a runtime check
  2. compile to a runtime check if NDEBUG is not defined
  3. compile to a runtime check if some other macro is not defined
  4. always compile to a runtime check on the CPU, and compile to a runtime check on the other devices if NDEBUG is not defined
  5. always compile to a runtime check on the CPU, and compile to a runtime check on the other devices if some other macro is not defined
  6. something else
  7. always compile to a no-op
psychocoderHPC added a commit to psychocoderHPC/alpaka that referenced this issue Dec 1, 2023
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` in the C++ code or by the CMake
option `alpaka_ASSERT_ACC_ENABLE`
psychocoderHPC added a commit to psychocoderHPC/alpaka that referenced this issue Dec 19, 2023
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 <andrea.bocci@cern.ch>
psychocoderHPC added a commit to psychocoderHPC/alpaka that referenced this issue Dec 20, 2023
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 <andrea.bocci@cern.ch>
bernhardmgruber pushed a commit that referenced this issue Dec 20, 2023
fix #2186
fix #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 <andrea.bocci@cern.ch>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants