ReUseX  0.0.5
3D Point Cloud Processing for Building Reuse
Loading...
Searching...
No Matches
device.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2025 Povl Filip Sonne-Frederiksen
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5#pragma once
6#include <cuda_runtime.h>
7
9class AutoDevice {
10 public:
11 explicit AutoDevice(int device_id) {
12 cudaGetDevice(&prev_device_);
13 if (prev_device_ != device_id) {
14 cudaSetDevice(device_id);
15 switched_ = true;
16 }
17 }
18
20 if (switched_) {
21 cudaSetDevice(prev_device_);
22 }
23 }
24
25 // Copy and assignment are prohibited
26 AutoDevice(const AutoDevice &) = delete;
27 AutoDevice &operator=(const AutoDevice &) = delete;
28
29 private:
30 int prev_device_ = 0;
31 bool switched_ = false;
32};
33} // namespace reusex::vision::tensor_rt
AutoDevice(const AutoDevice &)=delete
AutoDevice & operator=(const AutoDevice &)=delete