19 #include <rmm/detail/error.hpp>
20 #include <rmm/detail/export.hpp>
22 #include <cuda_runtime_api.h>
27 namespace RMM_NAMESPACE {
29 struct cuda_device_id;
72 return lhs.value() == rhs.value();
82 [[nodiscard]] constexpr
friend bool operator!=(cuda_device_id
const& lhs,
83 cuda_device_id
const& rhs) noexcept
85 return lhs.value() != rhs.value();
102 RMM_ASSERT_CUDA_SUCCESS(cudaGetDevice(&dev_id));
114 RMM_ASSERT_CUDA_SUCCESS(cudaGetDeviceCount(&num_dev));
127 RMM_CUDA_TRY(cudaMemGetInfo(&free, &total));
128 return {free, total};
142 auto fraction =
static_cast<double>(percent) / 100.0;
143 return rmm::align_down(
static_cast<std::size_t
>(
static_cast<double>(free) * fraction),
159 needs_reset_{dev_id.value() >= 0 && old_device_ != dev_id}
161 if (needs_reset_) { RMM_ASSERT_CUDA_SUCCESS(cudaSetDevice(dev_id.
value())); }
168 if (needs_reset_) { RMM_ASSERT_CUDA_SUCCESS(cudaSetDevice(old_device_.value())); }
std::pair< std::size_t, std::size_t > available_device_memory()
Returns the available and total device memory in bytes for the current device.
Definition: cuda_device.hpp:123
cuda_device_id get_current_cuda_device()
Returns a cuda_device_id for the current device.
Definition: cuda_device.hpp:99
int get_num_cuda_devices()
Returns the number of CUDA devices in the system.
Definition: cuda_device.hpp:111
std::size_t percent_of_free_device_memory(int percent)
Returns the approximate specified percent of available device memory on the current CUDA device,...
Definition: cuda_device.hpp:139
bool operator==(cuda_stream_view lhs, cuda_stream_view rhs)
Equality comparison operator for streams.
Definition: cuda_stream_view.hpp:175
bool operator!=(cuda_stream_view lhs, cuda_stream_view rhs)
Inequality comparison operator for streams.
Definition: cuda_stream_view.hpp:187
static constexpr std::size_t CUDA_ALLOCATION_ALIGNMENT
Default alignment used for CUDA memory allocation.
Definition: aligned.hpp:43
constexpr std::size_t align_down(std::size_t value, std::size_t alignment) noexcept
Align down to the nearest multiple of specified power of 2.
Definition: aligned.hpp:91
Strong type for a CUDA device identifier.
Definition: cuda_device.hpp:41
constexpr cuda_device_id(value_type dev_id) noexcept
Construct a cuda_device_id from the specified integer value.
Definition: cuda_device.hpp:54
cuda_device_id() noexcept
Construct a cuda_device_id from the current device.
Definition: cuda_device.hpp:47
constexpr value_type value() const noexcept
The wrapped integer value.
Definition: cuda_device.hpp:57
int value_type
Integer type used for device identifier.
Definition: cuda_device.hpp:42
RAII class that sets the current CUDA device to the specified device on construction and restores the...
Definition: cuda_device.hpp:151
~cuda_set_device_raii() noexcept
Reactivates the previous CUDA device.
Definition: cuda_device.hpp:166
cuda_set_device_raii(cuda_device_id dev_id)
Construct a new cuda_set_device_raii object and sets the current CUDA device to dev_id
Definition: cuda_device.hpp:157