CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
cms::cuda::ScopedSetDevice Class Reference

#include <ScopedSetDevice.h>

Public Member Functions

 ScopedSetDevice ()
 
 ScopedSetDevice (int device)
 
void set (int device)
 
 ~ScopedSetDevice ()
 

Private Attributes

int originalDevice_
 

Detailed Description

Definition at line 10 of file ScopedSetDevice.h.

Constructor & Destructor Documentation

◆ ScopedSetDevice() [1/2]

cms::cuda::ScopedSetDevice::ScopedSetDevice ( )
inline

Definition at line 13 of file ScopedSetDevice.h.

References cudaCheck, and originalDevice_.

13  {
14  // Store the original device
15  cudaCheck(cudaGetDevice(&originalDevice_));
16  }
#define cudaCheck(ARG,...)
Definition: cudaCheck.h:69

◆ ScopedSetDevice() [2/2]

cms::cuda::ScopedSetDevice::ScopedSetDevice ( int  device)
inlineexplicit

Definition at line 19 of file ScopedSetDevice.h.

19  : ScopedSetDevice() {
20  // Change the current device
21  set(device);
22  }

◆ ~ScopedSetDevice()

cms::cuda::ScopedSetDevice::~ScopedSetDevice ( )
inline

Definition at line 25 of file ScopedSetDevice.h.

References originalDevice_.

25  {
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  }

Member Function Documentation

◆ set()

void cms::cuda::ScopedSetDevice::set ( int  device)
inline

Definition at line 34 of file ScopedSetDevice.h.

References cudaCheck.

Referenced by cms::cuda::ESProduct< HcalGainWidthsGPU::Product >::ESProduct().

34  {
35  // Change the current device
36  cudaCheck(cudaSetDevice(device));
37  }
#define cudaCheck(ARG,...)
Definition: cudaCheck.h:69

Member Data Documentation

◆ originalDevice_

int cms::cuda::ScopedSetDevice::originalDevice_
private

Definition at line 40 of file ScopedSetDevice.h.

Referenced by ScopedSetDevice(), and ~ScopedSetDevice().