QMCPACK
CUDAerror.h
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 //// This file is distributed under the University of Illinois/NCSA Open Source License.
3 //// See LICENSE file in top directory for details.
4 ////
5 //// Copyright (c) 2019 QMCPACK developers.
6 ////
7 //// File developed by: Ye Luo, yeluo@anl.gov, Argonne National Laboratory
8 ////
9 //// File created by: Ye Luo, yeluo@anl.gov, Argonne National Laboratory
10 ////////////////////////////////////////////////////////////////////////////////////////
11 
12 
13 #ifndef QMCPLUSPLUS_CUDA_ERROR_H
14 #define QMCPLUSPLUS_CUDA_ERROR_H
15 
16 #include <iostream>
17 #include <string>
18 #include <sstream>
19 #include <stdexcept>
20 
21 #define cudaErrorCheck(ans, cause) \
22  { \
23  cudaAssert((ans), cause, __FILE__, __LINE__); \
24  }
25 
26 // If the cause is largely redundant with the __FILE__ and __LINE__ information
27 #define cudaCheck(ans) \
28  { \
29  cudaAssert((ans), "", __FILE__, __LINE__); \
30  }
31 
32 /// prints CUDA error messages. Always use cudaErrorCheck macro.
33 inline void cudaAssert(cudaError_t code, const std::string& cause, const char* filename, int line, bool abort = true)
34 {
35  if (code != cudaSuccess)
36  {
37  std::ostringstream err;
38  err << "cudaAssert: " << cudaGetErrorName(code) << " " << cudaGetErrorString(code) << ", file " << filename
39  << ", line " << line << std::endl
40  << cause << std::endl;
41  std::cerr << err.str();
42  if (abort)
43  throw std::runtime_error(cause);
44  }
45 }
46 
47 #endif
#define cudaError_t
Definition: cuda2hip.h:89
#define cudaGetErrorName
Definition: cuda2hip.h:104
#define cudaSuccess
Definition: cuda2hip.h:154
void cudaAssert(cudaError_t code, const std::string &cause, const char *filename, int line, bool abort=true)
prints CUDA error messages. Always use cudaErrorCheck macro.
Definition: CUDAerror.h:33
#define cudaGetErrorString
Definition: cuda2hip.h:105