File: Assert.h

package info (click to toggle)
veccore 0.8.1%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,988 kB
  • sloc: cpp: 2,894; ansic: 1,338; makefile: 2
file content (47 lines) | stat: -rw-r--r-- 1,894 bytes parent folder | download | duplicates (3)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#ifndef VECCORE_ASSERT_H
#define VECCORE_ASSERT_H

#if !defined(__NVCC__)
#include <cassert>
#else

// NVCC sometimes cannot process plain assert() from <cassert>, so
// we need to provide our own implementation that works around the bug
// by avoiding the __PRETTY_FUNCTION__ macro where it causes problems.
// A bug for this has been filed by Philippe Canal at the link below:
// https://developer.nvidia.com/nvbugs/cuda/edit/1729798

#ifdef assert
#undef assert
#endif

#ifdef NDEBUG
#define assert(x)
#else

#include <cstdio>

#ifndef __CUDA_ARCH__
#define assert(x)                                                                 \
  do {                                                                            \
    if (!(x)) {                                                                   \
      fprintf(stderr, "%s:%d: Assertion failed: '%s'\n", __FILE__, __LINE__, #x); \
      abort();                                                                    \
    }                                                                             \
  } while (0)
#else
#define assert(x)                                                                                  \
  do {                                                                                             \
    if (!(x)) {                                                                                    \
      printf("%s:%d:\n%s: Assertion failed: '%s'\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #x); \
      __syncthreads();                                                                             \
      asm("trap;");                                                                                \
    }                                                                                              \
  } while (0)
#endif // ifndef __CUDA_ARCH__

#endif // ifdef NDEBUG

#endif // if !defined(__NVCC__)

#endif