20 #include <rmm/detail/export.hpp>
94 namespace RMM_NAMESPACE {
139 static std::map<cuda_device_id::value_type, device_memory_resource*> device_id_to_resource;
140 return device_id_to_resource;
158 static std::map<cuda_device_id::value_type, device_async_resource_ref> device_id_to_resource_ref;
159 return device_id_to_resource_ref;
188 std::lock_guard<std::mutex> lock{detail::map_lock()};
189 auto& map = detail::get_map();
191 auto const found = map.find(device_id.
value());
192 return (found == map.end()) ? (map[device_id.
value()] = detail::initial_resource())
206 auto& map = detail::get_ref_map();
207 auto const old_itr = map.find(device_id.
value());
210 if (old_itr == map.end()) {
211 map.insert({device_id.
value(), new_resource_ref});
215 auto old_resource_ref = old_itr->second;
216 old_itr->second = new_resource_ref;
217 return old_resource_ref;
251 std::lock_guard<std::mutex> lock{detail::map_lock()};
258 detail::set_per_device_resource_ref_unsafe(device_id, new_mr);
260 auto& map = detail::get_map();
261 auto const old_itr = map.find(device_id.
value());
263 auto* old_mr = (old_itr == map.end()) ? detail::initial_resource() : old_itr->second;
264 map[device_id.
value()] = (new_mr ==
nullptr) ? detail::initial_resource() : new_mr;
347 std::lock_guard<std::mutex> lock{detail::ref_map_lock()};
348 auto& map = detail::get_ref_map();
350 auto const found = map.find(device_id.
value());
351 if (found == map.end()) {
352 auto item = map.insert({device_id.
value(), detail::initial_resource()});
353 return item.first->second;
355 return found->second;
385 std::lock_guard<std::mutex> lock{detail::ref_map_lock()};
386 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:36
Base class for all librmm device memory allocation.
Definition: device_memory_resource.hpp:93
cuda_device_id get_current_cuda_device()
Returns a cuda_device_id for the current device.
Definition: cuda_device.hpp:99
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:459
cuda::mr::async_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:41
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:437
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:477
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:382
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:318
device_async_resource_ref get_current_device_resource_ref()
Get the device_async_resource_ref for the current device.
Definition: per_device_resource.hpp:411
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:345
device_memory_resource * get_current_device_resource()
Get the memory resource for the current device.
Definition: per_device_resource.hpp:289
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:248
device_memory_resource * get_per_device_resource(cuda_device_id device_id)
Get the resource for the specified device.
Definition: per_device_resource.hpp:186
auto & get_map()
Reference to the map from device id -> resource.
Definition: per_device_resource.hpp:137
std::mutex & map_lock()
Reference to the lock.
Definition: per_device_resource.hpp:128
auto & get_ref_map()
Reference to the map from device id -> resource_ref.
Definition: per_device_resource.hpp:156
device_memory_resource * initial_resource()
Returns a pointer to the initial resource.
Definition: per_device_resource.hpp:119
std::mutex & ref_map_lock()
Reference to the lock.
Definition: per_device_resource.hpp:146
Strong type for a CUDA device identifier.
Definition: cuda_device.hpp:41
constexpr value_type value() const noexcept
The wrapped integer value.
Definition: cuda_device.hpp:57