cuda_device.hpp
1 /*
2  * Copyright (c) 2021, 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
17 
18 #include <rmm/detail/error.hpp>
19 
20 #include <cuda_runtime_api.h>
21 
22 namespace rmm {
23 
29  using value_type = int;
30 
36  explicit constexpr cuda_device_id(value_type dev_id) noexcept : id_{dev_id} {}
37 
39  [[nodiscard]] constexpr value_type value() const noexcept { return id_; }
40 
41  private:
42  value_type id_;
43 };
44 
45 namespace detail {
53 inline cuda_device_id current_device()
54 {
55  int dev_id{};
56  RMM_CUDA_TRY(cudaGetDevice(&dev_id));
57  return cuda_device_id{dev_id};
58 }
59 } // namespace detail
60 } // namespace rmm
rmm::cuda_device_id::cuda_device_id
constexpr cuda_device_id(value_type dev_id) noexcept
Construct a cuda_device_id from the specified integer value.
Definition: cuda_device.hpp:36
rmm::cuda_device_id
Strong type for a CUDA device identifier.
Definition: cuda_device.hpp:28
rmm::cuda_device_id::value
constexpr value_type value() const noexcept
Returns the wrapped integer value.
Definition: cuda_device.hpp:39