9 #include <rmm/detail/export.hpp>
14 #include <cuda/memory_resource>
85 namespace RMM_NAMESPACE {
130 static std::map<cuda_device_id::value_type, device_memory_resource*> device_id_to_resource;
131 return device_id_to_resource;
149 static std::map<cuda_device_id::value_type, cuda::mr::any_resource<cuda::mr::device_accessible>>
150 device_id_to_resource;
151 return device_id_to_resource;
180 std::lock_guard<std::mutex> lock{detail::map_lock()};
181 auto& map = detail::get_map();
183 auto const found = map.find(device_id.
value());
184 return (found == map.end()) ? (map[device_id.
value()] = detail::initial_resource())
198 using any_device_resource = cuda::mr::any_resource<cuda::mr::device_accessible>;
199 auto& map = detail::get_ref_map();
200 auto const old_itr = map.find(device_id.
value());
202 if (old_itr == map.end()) {
203 map.emplace(device_id.
value(),
static_cast<any_device_resource
>(new_resource_ref));
208 old_itr->second =
static_cast<any_device_resource
>(new_resource_ref);
209 return old_resource_ref;
243 std::lock_guard<std::mutex> lock{detail::map_lock()};
250 if (new_mr !=
nullptr) { detail::set_per_device_resource_ref_unsafe(device_id, new_mr); }
252 auto& map = detail::get_map();
253 auto const old_itr = map.find(device_id.
value());
255 auto* old_mr = (old_itr == map.end()) ? detail::initial_resource() : old_itr->second;
256 map[device_id.
value()] = (new_mr ==
nullptr) ? detail::initial_resource() : new_mr;
339 using any_device_resource = cuda::mr::any_resource<cuda::mr::device_accessible>;
340 std::lock_guard<std::mutex> lock{detail::ref_map_lock()};
341 auto& map = detail::get_ref_map();
343 auto const found = map.find(device_id.
value());
344 if (found == map.end()) {
347 auto item = map.emplace(device_id.
value(),
static_cast<any_device_resource
>(initial_ref));
380 std::lock_guard<std::mutex> lock{detail::ref_map_lock()};
381 return detail::set_per_device_resource_ref_unsafe(device_id, new_resource_ref);
device_memory_resource derived class that uses cudaMalloc/Free for allocation/deallocation.
Definition: cuda_memory_resource.hpp:25
Base class for all librmm device memory allocation.
Definition: device_memory_resource.hpp:82
cuda_device_id get_current_cuda_device()
Returns a cuda_device_id for the current device.
device_async_resource_ref reset_per_device_resource_ref(cuda_device_id device_id)
Reset the device_async_resource_ref for the specified device to the initial resource.
Definition: per_device_resource.hpp:454
device_async_resource_ref set_current_device_resource_ref(device_async_resource_ref new_resource_ref)
Set the device_async_resource_ref for the current device.
Definition: per_device_resource.hpp:432
device_async_resource_ref reset_current_device_resource_ref()
Reset the device_async_resource_ref for the current device to the initial resource.
Definition: per_device_resource.hpp:472
device_async_resource_ref set_per_device_resource_ref(cuda_device_id device_id, device_async_resource_ref new_resource_ref)
Set the device_async_resource_ref for the specified device to new_resource_ref
Definition: per_device_resource.hpp:377
device_memory_resource * set_current_device_resource(device_memory_resource *new_mr)
Set the memory resource for the current device.
Definition: per_device_resource.hpp:310
device_async_resource_ref get_current_device_resource_ref()
Get the device_async_resource_ref for the current device.
Definition: per_device_resource.hpp:406
device_async_resource_ref get_per_device_resource_ref(cuda_device_id device_id)
Get the device_async_resource_ref for the specified device.
Definition: per_device_resource.hpp:337
device_memory_resource * get_current_device_resource()
Get the memory resource for the current device.
Definition: per_device_resource.hpp:281
device_memory_resource * set_per_device_resource(cuda_device_id device_id, device_memory_resource *new_mr)
Set the device_memory_resource for the specified device.
Definition: per_device_resource.hpp:240
device_memory_resource * get_per_device_resource(cuda_device_id device_id)
Get the resource for the specified device.
Definition: per_device_resource.hpp:178
detail::cccl_async_resource_ref< cuda::mr::resource_ref< cuda::mr::device_accessible > > device_async_resource_ref
Alias for a cuda::mr::async_resource_ref with the property cuda::mr::device_accessible.
Definition: resource_ref.hpp:32
auto & get_map()
Reference to the map from device id -> resource.
Definition: per_device_resource.hpp:128
std::mutex & map_lock()
Reference to the lock.
Definition: per_device_resource.hpp:119
auto & get_ref_map()
Reference to the map from device id -> any_resource.
Definition: per_device_resource.hpp:147
device_memory_resource * initial_resource()
Returns a pointer to the initial resource.
Definition: per_device_resource.hpp:110
std::mutex & ref_map_lock()
Reference to the lock.
Definition: per_device_resource.hpp:137
Strong type for a CUDA device identifier.
Definition: cuda_device.hpp:27
constexpr value_type value() const noexcept
The wrapped integer value.
Definition: cuda_device.hpp:43