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