assert.h 1.3 KB
Newer Older
1 2 3 4 5 6 7
#pragma once

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

#if defined(__APPLE__) && defined(__CUDA_ARCH__) && !defined(NDEBUG)
#include <stdio.h>
8 9 10 11 12 13 14
#define PADDLE_ASSERT(e)                                           \
  do {                                                             \
    if (!(e)) {                                                    \
      printf("%s:%d Assertion `%s` failed.\n", __FILE__, __LINE__, \
             TOSTRING(e));                                         \
      asm("trap;");                                                \
    }                                                              \
15 16
  } while (0)

17 18 19 20 21 22 23
#define PADDLE_ASSERT_MSG(e, m)                                         \
  do {                                                                  \
    if (!(e)) {                                                         \
      printf("%s:%d Assertion `%s` failed (%s).\n", __FILE__, __LINE__, \
             TOSTRING(e), m);                                           \
      asm("trap;");                                                     \
    }                                                                   \
24 25 26
  } while (0)
#else
#include <assert.h>
27 28
#define PADDLE_ASSERT(e) assert(e)
#define PADDLE_ASSERT_MSG(e, m) assert((e) && (m))
29
#endif