src
HeterogeneousCore
CUDAUtilities
interface
ScopedSetDevice.h
Go to the documentation of this file.
1
#ifndef HeterogeneousCore_CUDAUtilities_ScopedSetDevice_h
2
#define HeterogeneousCore_CUDAUtilities_ScopedSetDevice_h
3
4
#include "
HeterogeneousCore/CUDAUtilities/interface/cudaCheck.h
"
5
6
#include <cuda_runtime.h>
7
8
namespace
cms
{
9
namespace
cuda
{
10
class
ScopedSetDevice
{
11
public
:
12
// Store the original device, without setting a new one
13
ScopedSetDevice
() {
14
// Store the original device
15
cudaCheck
(cudaGetDevice(&
originalDevice_
));
16
}
17
18
// Store the original device, and set a new current device
19
explicit
ScopedSetDevice
(
int
device) :
ScopedSetDevice
() {
20
// Change the current device
21
set
(device);
22
}
23
24
// Restore the original device
25
~ScopedSetDevice
() {
26
// Intentionally don't check the return value to avoid
27
// exceptions to be thrown. If this call fails, the process is
28
// doomed anyway.
29
cudaSetDevice(
originalDevice_
);
30
}
31
32
// Set a new current device, without changing the original device
33
// that will be restored when this object is destroyed
34
void
set
(
int
device) {
35
// Change the current device
36
cudaCheck
(cudaSetDevice(device));
37
}
38
39
private
:
40
int
originalDevice_
;
41
};
42
}
// namespace cuda
43
}
// namespace cms
44
45
#endif
cms::cuda::ScopedSetDevice::ScopedSetDevice
ScopedSetDevice()
Definition:
ScopedSetDevice.h:13
cms::cuda::ScopedSetDevice
Definition:
ScopedSetDevice.h:10
cms::cuda::ScopedSetDevice::~ScopedSetDevice
~ScopedSetDevice()
Definition:
ScopedSetDevice.h:25
cms
Namespace of DDCMS conversion namespace.
Definition:
ProducerAnalyzer.cc:41
cudaCheck.h
cms::cuda::ScopedSetDevice::ScopedSetDevice
ScopedSetDevice(int device)
Definition:
ScopedSetDevice.h:19
ecalDigis_cff.cuda
cuda
Definition:
ecalDigis_cff.py:29
cudaCheck
#define cudaCheck(ARG,...)
Definition:
cudaCheck.h:69
cms::cuda::ScopedSetDevice::originalDevice_
int originalDevice_
Definition:
ScopedSetDevice.h:40
Generated for CMSSW Reference Manual by
1.8.14