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