CMS 3D CMS Logo

cudaCheck.h
Go to the documentation of this file.
1 #ifndef HeterogeneousCore_CUDAUtilities_cudaCheck_h
2 #define HeterogeneousCore_CUDAUtilities_cudaCheck_h
3 
4 // C++ standard headers
5 #include <iostream>
6 #include <sstream>
7 #include <stdexcept>
8 
9 // CUDA headers
10 #include <cuda.h>
11 #include <cuda_runtime.h>
12 
13 // CMSSW headers
15 
16 namespace cms {
17  namespace cuda {
18 
19  [[noreturn]] inline void abortOnCudaError(const char* file,
20  int line,
21  const char* cmd,
22  const char* error,
23  const char* message,
24  const char* description = nullptr) {
25  std::ostringstream out;
26  out << "\n";
27  out << file << ", line " << line << ":\n";
28  out << "cudaCheck(" << cmd << ");\n";
29  out << error << ": " << message << "\n";
30  if (description)
31  out << description << "\n";
32  throw std::runtime_error(out.str());
33  }
34 
35  inline bool cudaCheck_(
36  const char* file, int line, const char* cmd, CUresult result, const char* description = nullptr) {
37  if (LIKELY(result == CUDA_SUCCESS))
38  return true;
39 
40  const char* error;
41  const char* message;
42  cuGetErrorName(result, &error);
43  cuGetErrorString(result, &message);
45  return false;
46  }
47 
48  inline bool cudaCheck_(
49  const char* file, int line, const char* cmd, cudaError_t result, const char* description = nullptr) {
50  if (LIKELY(result == cudaSuccess))
51  return true;
52 
53  const char* error = cudaGetErrorName(result);
54  const char* message = cudaGetErrorString(result);
56  return false;
57  }
58 
59  } // namespace cuda
60 } // namespace cms
61 
62 #define cudaCheck(ARG, ...) (cms::cuda::cudaCheck_(__FILE__, __LINE__, #ARG, (ARG), ##__VA_ARGS__))
63 
64 #endif // HeterogeneousCore_CUDAUtilities_cudaCheck_h
Likely.h
mps_setup.cmd
list cmd
Definition: mps_setup.py:244
edmLumisInFiles.description
description
Definition: edmLumisInFiles.py:11
relativeConstraints.error
error
Definition: relativeConstraints.py:53
cms::cuda::cudaCheck_
bool cudaCheck_(const char *file, int line, const char *cmd, CUresult result, const char *description=nullptr)
Definition: cudaCheck.h:35
prod1Switch_cff.cuda
cuda
Definition: prod1Switch_cff.py:11
FrontierConditions_GlobalTag_cff.file
file
Definition: FrontierConditions_GlobalTag_cff.py:13
LIKELY
#define LIKELY(x)
Definition: Likely.h:20
cms::cuda::abortOnCudaError
void abortOnCudaError(const char *file, int line, const char *cmd, const char *error, const char *message, const char *description=nullptr)
Definition: cudaCheck.h:19
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
mps_fire.result
result
Definition: mps_fire.py:303
mps_splice.line
line
Definition: mps_splice.py:76
cms
Namespace of DDCMS conversion namespace.
Definition: ProducerAnalyzer.cc:21