forked from cms-patatrack/pixeltrack-standalone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcudaCheck.h
70 lines (56 loc) · 2.15 KB
/
cudaCheck.h
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#ifndef HeterogeneousCore_CUDAUtilities_cudaCheck_h
#define HeterogeneousCore_CUDAUtilities_cudaCheck_h
// C++ standard headers
#include <iostream>
#include <sstream>
#include <stdexcept>
// Boost headers
#define BOOST_STACKTRACE_USE_BACKTRACE
#include <boost/stacktrace.hpp>
// CUDA headers
#include <cuda.h>
#include <cuda_runtime.h>
namespace cms {
namespace cuda {
[[noreturn]] inline void abortOnCudaError(const char* file,
int line,
const char* cmd,
const char* error,
const char* message,
const char* description = nullptr) {
std::ostringstream out;
out << "\n";
out << file << ", line " << line << ":\n";
out << "cudaCheck(" << cmd << ");\n";
out << error << ": " << message << "\n";
if (description)
out << description << "\n";
out << "\nCurrent stack trace:\n";
out << boost::stacktrace::stacktrace();
out << "\n";
throw std::runtime_error(out.str());
}
inline bool cudaCheck_(
const char* file, int line, const char* cmd, CUresult result, const char* description = nullptr) {
if (result == CUDA_SUCCESS)
return true;
const char* error;
const char* message;
cuGetErrorName(result, &error);
cuGetErrorString(result, &message);
abortOnCudaError(file, line, cmd, error, message, description);
return false;
}
inline bool cudaCheck_(
const char* file, int line, const char* cmd, cudaError_t result, const char* description = nullptr) {
if (result == cudaSuccess)
return true;
const char* error = cudaGetErrorName(result);
const char* message = cudaGetErrorString(result);
abortOnCudaError(file, line, cmd, error, message, description);
return false;
}
} // namespace cuda
} // namespace cms
#define cudaCheck(ARG, ...) (cms::cuda::cudaCheck_(__FILE__, __LINE__, #ARG, (ARG), ##__VA_ARGS__))
#endif // HeterogeneousCore_CUDAUtilities_cudaCheck_h