Proto
Proto_PAssert.H
1 #pragma once
2 
3 #include <cassert>
4 #include <cstdio>
5 #include <stdio.h>
6 #include <cstdlib>
7 
8 // Custom Assert macro with printf-style reporting
9 #ifdef __CUDA_ARCH__
10 
11 #define PROTO_ASSERT(stmt,args...)
12 #define PR_assert(stmt)
13 #define PR_error(stmt)
14 #define PR_warning(stmt)
15 
16 #elif NDEBUG
17 
18 #define PROTO_ASSERT(stmt,args...)
19 #define PR_assert(stmt)
20 #define PR_error(stmt)
21 #define PR_warning(stmt)
22 
23 
24 #else
25 
26 
27 #ifndef PROTO_HIP
28 
29 #define PROTO_ASSERT(stmt,args...) \
30  assert( (stmt) || \
31  (fprintf(stderr,"%s:%d: error: ",__FILE__,__LINE__) && \
32  fprintf(stderr,"Assertion `" #stmt "` failed.\n\t") && \
33  fprintf(stderr,args) && \
34  fprintf(stderr,"\n"))); \
35  if (!(stmt)){std::abort();}
36 
50 #define PR_assert(stmt) assert( (stmt) );
51 
52 
53 #define PR_error(stmt) \
54  fprintf(stderr,"error thrown = `" #stmt "`!!!\n\t"); \
55  std::abort();
56 
57 #define PR_warning(stmt) \
58  fprintf(stderr,"warning thrown = `" #stmt "` !!!\n\t");
59 
60 #else // PROTO_HIP
61 #define PROTO_ASSERT(stmt,args...)
62 #define PR_assert(stmt)
63 #define PR_error(stmt)
64 #define PR_warning(stmt)
65 
66 #endif
67 #endif