ReUseX  0.0.1
3D Point Cloud Processing for Building Reuse
Loading...
Searching...
No Matches
device.hpp
Go to the documentation of this file.
1#pragma once
2#include <cuda_runtime.h>
3
5class AutoDevice {
6 public:
7 explicit AutoDevice(int device_id) {
8 cudaGetDevice(&prev_device_);
9 if (prev_device_ != device_id) {
10 cudaSetDevice(device_id);
11 switched_ = true;
12 }
13 }
14
16 if (switched_) {
17 cudaSetDevice(prev_device_);
18 }
19 }
20
21 // Copy and assignment are prohibited
22 AutoDevice(const AutoDevice &) = delete;
23 AutoDevice &operator=(const AutoDevice &) = delete;
24
25 private:
26 int prev_device_ = 0;
27 bool switched_ = false;
28};
29} // namespace ReUseX::vision::tensor_rt
AutoDevice(const AutoDevice &)=delete
AutoDevice & operator=(const AutoDevice &)=delete