cuda_assert.h 1.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
#pragma once

#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)

#if defined(__APPLE__) && defined(__CUDA_ARCH__) && !defined(NDEBUG)
#include <stdio.h>
#define MAJEL_ASSERT(e)                                                       \
  do {                                                                        \
    if (!(e)) {                                                               \
      printf(                                                                 \
          "%s:%d Assertion `%s` failed.\n", __FILE__, __LINE__, TOSTRING(e)); \
      asm("trap;");                                                           \
    }                                                                         \
  } while (0)

#define MAJEL_ASSERT_MSG(e, m)                      \
  do {                                              \
    if (!(e)) {                                     \
      printf("%s:%d Assertion `%s` failed (%s).\n", \
             __FILE__,                              \
             __LINE__,                              \
             TOSTRING(e),                           \
             m);                                    \
      asm("trap;");                                 \
    }                                               \
  } while (0)
#else
#include <assert.h>
#define MAJEL_ASSERT(e) assert(e)
#define MAJEL_ASSERT_MSG(e, m) assert((e) && (m))
#endif