ReUseX
0.0.1
3D Point Cloud Processing for Building Reuse
Loading...
Searching...
No Matches
check.hpp
Go to the documentation of this file.
1
#pragma once
2
#include <assert.h>
3
#include <cuda_runtime.h>
4
#include <spdlog/spdlog.h>
5
#include <stdarg.h>
6
#include <stdio.h>
7
8
#include <string>
9
10
namespace
ReUseX::vision::tensor_rt::nv
{
11
12
#define NVUNUSED2(a, b) \
13
{ \
14
(void)(a); \
15
(void)(b); \
16
}
17
#define NVUNUSED(a) \
18
{ \
19
(void)(a); \
20
}
21
22
#if DEBUG
23
#define checkRuntime(call) \
24
ReUseX::vision::tensor_rt::nv::check_runtime(call, #call, __LINE__, __FILE__)
25
#define checkKernel(...) \
26
[&] { \
27
__VA_ARGS__; \
28
checkRuntime(cudaStreamSynchronize(nullptr)); \
29
return ReUseX::vision::tensor_rt::nv::check_runtime( \
30
cudaGetLastError(), #__VA_ARGS__, __LINE__, __FILE__); \
31
}()
32
#define dprintf printf
33
#else
34
#define checkRuntime(call) \
35
ReUseX::vision::tensor_rt::nv::check_runtime(call, #call, __LINE__, __FILE__)
36
#define checkKernel(...) \
37
do { \
38
__VA_ARGS__; \
39
ReUseX::vision::tensor_rt::nv::check_runtime( \
40
cudaPeekAtLastError(), #__VA_ARGS__, __LINE__, __FILE__); \
41
} while (false)
42
#define dprintf(...)
43
#endif
44
45
// #define Assertf(cond, fmt, ...) \
46
// do { \
47
// if (!(cond)) { \
48
// fprintf(stderr, \
49
// "Assert failed 💀. %s in file %s:%d, message: " fmt "\n",
50
// #cond,
51
// __FILE__, __LINE__, __VA_ARGS__); \
52
// abort(); \
53
// } \
54
// } while (false)
55
56
// #define Asserts(cond, s) \
57
// do { \
58
// if (!(cond)) { \
59
// fprintf(stderr, "Assert failed 💀. %s in file %s:%d, message: " s "\n",
60
61
// #cond, __FILE__, __LINE__); \
62
// abort(); \
63
// } \
64
// } while (false)
65
66
// #define Assert(cond) \
67
// do { \
68
// if (!(cond)) { \
69
// fprintf(stderr, "Assert failed 💀. %s in file %s:%d\n", #cond,
70
//__FILE__, // __LINE__); \
71
// abort(); \
72
// } \
73
// } while (false)
74
//
75
76
static
inline
bool
check_runtime
(cudaError_t e,
const
char
*call,
int
line,
77
const
char
*file) {
78
if
(e != cudaSuccess) {
79
fprintf(stderr,
80
"CUDA Runtime error %s # %s, code = %s [ %d ] in file "
81
"%s:%d\n"
,
82
call, cudaGetErrorString(e), cudaGetErrorName(e), e, file, line);
83
abort();
84
return
false
;
85
}
86
return
true
;
87
}
88
89
};
// namespace ReUseX::vision::tensor_rt::nv
90
91
namespace
ReUseX::vision::tensor_rt
{
92
93
template
<
typename
... Args>
94
constexpr
void
Assertf
(
bool
cond,
const
char
*fmt, Args... args) {
95
do
{
96
if
(!(cond)) {
97
spdlog::error(
"Assert failed 💀. {} in file {}:{}, message: {}"
, cond,
98
__FILE__, __LINE__,
/*__VA_ARGS__,*/
fmt);
99
abort();
100
}
101
}
while
(
false
);
102
}
103
104
constexpr
void
Asserts
(
bool
cond,
const
char
*s) {
105
if
(!cond) {
106
spdlog::error(
"Assert failed 💀. in file {}:{}, message: {}"
, __FILE__,
107
__LINE__, s);
108
abort();
109
}
110
}
111
112
constexpr
void
Assert
(
bool
cond) {
113
if
(!cond) {
114
spdlog::error(
"Assert failed 💀. in file {}:{}"
, __FILE__, __LINE__);
115
abort();
116
}
117
}
118
}
// namespace ReUseX::vision::tensor_rt
ReUseX::vision::tensor_rt::nv
Definition
check.hpp:10
ReUseX::vision::tensor_rt::nv::check_runtime
static bool check_runtime(cudaError_t e, const char *call, int line, const char *file)
Definition
check.hpp:76
ReUseX::vision::tensor_rt
Definition
Backend.hpp:6
ReUseX::vision::tensor_rt::Assertf
constexpr void Assertf(bool cond, const char *fmt, Args... args)
Definition
check.hpp:94
ReUseX::vision::tensor_rt::Assert
constexpr void Assert(bool cond)
Definition
check.hpp:112
ReUseX::vision::tensor_rt::Asserts
constexpr void Asserts(bool cond, const char *s)
Definition
check.hpp:104
libs
reusex
include
ReUseX
vision
tensor_rt
common
check.hpp
Generated by
1.16.1