File indexing completed on 2024-04-06 12:15:45
0001 #ifndef HeterogeneousCore_CUDAUtilities_ScopedSetDevice_h
0002 #define HeterogeneousCore_CUDAUtilities_ScopedSetDevice_h
0003
0004 #include "HeterogeneousCore/CUDAUtilities/interface/cudaCheck.h"
0005
0006 #include <cuda_runtime.h>
0007
0008 namespace cms {
0009 namespace cuda {
0010 class ScopedSetDevice {
0011 public:
0012
0013 ScopedSetDevice() {
0014
0015 cudaCheck(cudaGetDevice(&originalDevice_));
0016 }
0017
0018
0019 explicit ScopedSetDevice(int device) : ScopedSetDevice() {
0020
0021 set(device);
0022 }
0023
0024
0025 ~ScopedSetDevice() {
0026
0027
0028
0029 cudaSetDevice(originalDevice_);
0030 }
0031
0032
0033
0034 void set(int device) {
0035
0036 cudaCheck(cudaSetDevice(device));
0037 }
0038
0039 private:
0040 int originalDevice_;
0041 };
0042 }
0043 }
0044
0045 #endif