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

[alpaka] Should we define ALPAKA_DEBUG_OFFLOAD_ASSUME_HOST for the CPU backends? #228

Open
makortel opened this issue Oct 7, 2021 · 3 comments
Labels

Comments

@makortel
Copy link
Collaborator

makortel commented Oct 7, 2021

#219 changed all uses of assert() to use ALPAKA_ASSERT_OFFLOAD, and this disables the assertions by default. This behavior corresponds what we do in cuda program, but in cudacompat we have asserts enabled. A ALPAKA_DEBUG_OFFLOAD_ASSUME_HOST macro can be used to enable assertions, so the question is, should we enable that macro for Alpaka CPU backends to be consistent with the behavior of cudacompat?

(or vice versa, should we disable asserts also in cudacompat?)

@fwyzard
Copy link
Contributor

fwyzard commented Oct 7, 2021

I think the rationale is that

  • assert on the cpu is relatively cheap
  • assert on the gpu is expensive

So, yes, to me it would make sense to enable the asserts by default on the cpu backends.

@fwyzard
Copy link
Contributor

fwyzard commented Oct 7, 2021

By the way, we could also (ask the Alpaka developers to) consider replacing

  assert(expression);

with something like

  [[noreturn]] __device__
  inline void printAssertMessage(const char* file, int line, const char* func, const char* expression, const char* message = 0) {
    printf("%s:%d:%s: block: [%d,%d,%d], thread: [%d,%d,%d] Assertion `%s` failed.\n",
        file, line, func,
        blockIdx.x, blockIdx.y, blockIdx.z,
        threadIdx.x, threadIdx.y, threadIdx.z,
        expression);
    if (message) {
      printf("%s\n", message);
    }
    __trap();
  }

  #define my_assert(expression) if (__builtin_expect(not static_cast<bool>(expression), false)) printAssertMessage(__FILE__, __LINE__, __PRETTY_FUNCTION__, #expression, nullptr)

if it is confirmed that it has better performance.

@fwyzard
Copy link
Contributor

fwyzard commented Mar 8, 2022

Looks like __trap() is not available on HIP/ROCm ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants