HeterogeneousCore
CUDAUtilities
interface
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
#include <string>
9
#include <string_view>
10
11
// CUDA headers
12
#include <cuda.h>
13
#include <cuda_runtime.h>
14
15
// CMSSW headers
16
#include "
FWCore/Utilities/interface/Likely.h
"
17
18
namespace
cms
{
19
namespace
cuda
{
20
21
[[noreturn]]
inline
void
abortOnCudaError
(
const
char
*
file
,
22
int
line
,
23
const
char
*
cmd
,
24
const
char
*
error
,
25
const
char
* message,
26
std::string_view
description
= std::string_view()) {
27
std::ostringstream
out
;
28
out
<<
"\n"
;
29
out
<<
file
<<
", line "
<<
line
<<
":\n"
;
30
out
<<
"cudaCheck("
<<
cmd
<<
");\n"
;
31
out
<<
error
<<
": "
<< message <<
"\n"
;
32
if
(!
description
.empty())
33
out
<<
description
<<
"\n"
;
34
throw
std::runtime_error(
out
.str());
35
}
36
37
inline
bool
cudaCheck_
(
const
char
*
file
,
38
int
line
,
39
const
char
*
cmd
,
40
CUresult
result
,
41
std::string_view
description
= std::string_view()) {
42
if
(
LIKELY
(
result
== CUDA_SUCCESS))
43
return
true
;
44
45
const
char
*
error
=
nullptr
;
46
const
char
* message =
nullptr
;
47
cuGetErrorName(
result
, &
error
);
48
cuGetErrorString(
result
, &message);
49
abortOnCudaError
(
file
,
line
,
cmd
,
error
, message,
description
);
50
return
false
;
51
}
52
53
inline
bool
cudaCheck_
(
const
char
*
file
,
54
int
line
,
55
const
char
*
cmd
,
56
cudaError_t
result
,
57
std::string_view
description
= std::string_view()) {
58
if
(
LIKELY
(
result
== cudaSuccess))
59
return
true
;
60
61
const
char
*
error
= cudaGetErrorName(
result
);
62
const
char
* message = cudaGetErrorString(
result
);
63
abortOnCudaError
(
file
,
line
,
cmd
,
error
, message,
description
);
64
return
false
;
65
}
66
}
// namespace cuda
67
}
// namespace cms
68
69
#define cudaCheck(ARG, ...) (cms::cuda::cudaCheck_(__FILE__, __LINE__, #ARG, (ARG), ##__VA_ARGS__))
70
71
#endif // HeterogeneousCore_CUDAUtilities_cudaCheck_h
relativeConstraints.error
error
Definition:
relativeConstraints.py:53
mps_fire.result
result
Definition:
mps_fire.py:311
LIKELY
#define LIKELY(x)
Definition:
Likely.h:20
mps_splice.line
line
Definition:
mps_splice.py:76
cms::cuda::cudaCheck_
bool cudaCheck_(const char *file, int line, const char *cmd, CUresult result, std::string_view description=std::string_view())
Definition:
cudaCheck.h:37
cms
Namespace of DDCMS conversion namespace.
Definition:
ProducerAnalyzer.cc:41
geometryDiff.file
file
Definition:
geometryDiff.py:13
MillePedeFileConverter_cfg.out
out
Definition:
MillePedeFileConverter_cfg.py:31
cms::cuda::abortOnCudaError
void abortOnCudaError(const char *file, int line, const char *cmd, const char *error, const char *message, std::string_view description=std::string_view())
Definition:
cudaCheck.h:21
ecalDigis_cff.cuda
cuda
Definition:
ecalDigis_cff.py:35
mps_setup.cmd
list cmd
Definition:
mps_setup.py:244
Likely.h
makeListRunsInFiles.description
description
Definition:
makeListRunsInFiles.py:15
Generated for CMSSW Reference Manual by
1.8.14