-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcuda_errors.hpp
More file actions
30 lines (26 loc) · 761 Bytes
/
cuda_errors.hpp
File metadata and controls
30 lines (26 loc) · 761 Bytes
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
#ifndef CUDA_ERRORS_HPP
#define CUDA_ERRORS_HPP
#include <cuda_runtime.h>
#include <iostream>
#define cudaSafeCall(err) _cudaSafeCall(err, __FILE__, __LINE__)
#define cudaCheckError() _cudaCheckError(__FILE__, __LINE__)
/**
* cuda version of error handling functions
*/
inline void _cudaSafeCall(cudaError err, const char *file, const int line)
{
if (err != cudaSuccess)
{
std::cerr << "CUDA failed at [" << file
<< "] line: " << line
<< " error: " << cudaGetErrorString(err)
<< std::endl;
exit(-1);
}
}
inline void _cudaCheckError(const char *file, const int line)
{
cudaError err = cudaGetLastError();
_cudaSafeCall(err, file, line);
}
#endif // CUDA_ERRORS_HPP