-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcudaCheck.h
53 lines (43 loc) · 1.4 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
#ifndef HeterogeneousCore_CUDAUtilities_cudaCheck_h
#define HeterogeneousCore_CUDAUtilities_cudaCheck_h
#include <iostream>
#include <sstream>
#include <cuda.h>
#include <cuda_runtime.h>
namespace {
inline
void printCudaErrorMessage(const char* file, int line, const char* cmd, const char* error, const char* message) {
std::ostringstream out;
out << "\n";
out << file << ", line " << line << ":\n";
out << "cudaCheck(" << cmd << ");\n";
out << error << ": " << message << "\n";
std::cerr << out.rdbuf() << std::endl;
}
}
inline
bool cudaCheck_(const char* file, int line, const char* cmd, CUresult result)
{
if (__builtin_expect(result == CUDA_SUCCESS, true))
return true;
const char* error;
const char* message;
cuGetErrorName(result, &error);
cuGetErrorString(result, &message);
printCudaErrorMessage(file, line, cmd, error, message);
abort();
return false;
}
inline
bool cudaCheck_(const char* file, int line, const char* cmd, cudaError_t result)
{
if (__builtin_expect(result == cudaSuccess, true))
return true;
const char* error = cudaGetErrorName(result);
const char* message = cudaGetErrorString(result);
printCudaErrorMessage(file, line, cmd, error, message);
abort();
return false;
}
#define cudaCheck(ARG) (cudaCheck_(__FILE__, __LINE__, #ARG, (ARG)))
#endif // HeterogeneousCore_CUDAUtilities_cudaCheck_h