gpu.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023-2024, NVIDIA CORPORATION.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #pragma once
21 
22 #include <raft/util/cudart_utils.hpp>
23 
24 #include <cuda_runtime_api.h>
25 
26 namespace raft_proto {
27 namespace detail {
28 
30 template <>
33  : prev_device_{[]() {
34  auto result = int{};
35  raft_proto::cuda_check(cudaGetDevice(&result));
36  return result;
37  }()}
38  {
39  raft_proto::cuda_check(cudaSetDevice(device.value()));
40  }
41 
42  ~device_setter() { RAFT_CUDA_TRY_NO_THROW(cudaSetDevice(prev_device_.value())); }
43 
44  private:
45  device_id<device_type::gpu> prev_device_;
46 };
47 
48 } // namespace detail
49 } // namespace raft_proto
Definition: buffer.hpp:35
void cuda_check(error_t const &err) noexcept(!GPU_ENABLED)
Definition: cuda_check.hpp:26
device_type
Definition: device_type.hpp:18
Definition: base.hpp:22
device_setter(raft_proto::device_id< device_type::gpu > device) noexcept(false)
Definition: gpu.hpp:32
Definition: base.hpp:25