9 #include <rmm/detail/export.hpp>
83 namespace RMM_NAMESPACE {
128 static std::map<cuda_device_id::value_type, device_memory_resource*> device_id_to_resource;
129 return device_id_to_resource;
147 static std::map<cuda_device_id::value_type, device_async_resource_ref> device_id_to_resource_ref;
148 return device_id_to_resource_ref;
177 std::lock_guard<std::mutex> lock{detail::map_lock()};
178 auto& map = detail::get_map();
180 auto const found = map.find(device_id.
value());
181 return (found == map.end()) ? (map[device_id.
value()] = detail::initial_resource())
195 auto& map = detail::get_ref_map();
196 auto const old_itr = map.find(device_id.
value());
199 if (old_itr == map.end()) {
200 map.insert({device_id.
value(), new_resource_ref});
204 auto old_resource_ref = old_itr->second;
205 old_itr->second = new_resource_ref;
206 return old_resource_ref;
240 std::lock_guard<std::mutex> lock{detail::map_lock()};
247 detail::set_per_device_resource_ref_unsafe(device_id, new_mr);
249 auto& map = detail::get_map();
250 auto const old_itr = map.find(device_id.
value());
252 auto* old_mr = (old_itr == map.end()) ? detail::initial_resource() : old_itr->second;
253 map[device_id.
value()] = (new_mr ==
nullptr) ? detail::initial_resource() : new_mr;
336 std::lock_guard<std::mutex> lock{detail::ref_map_lock()};
337 auto& map = detail::get_ref_map();
339 auto const found = map.find(device_id.
value());
340 if (found == map.end()) {
341 auto item = map.insert({device_id.
value(), detail::initial_resource()});
342 return item.first->second;
344 return found->second;
374 std::lock_guard<std::mutex> lock{detail::ref_map_lock()};
375 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:83
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:448
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:426
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:466
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:371
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:307
device_async_resource_ref get_current_device_resource_ref()
Get the device_async_resource_ref for the current device.
Definition: per_device_resource.hpp:400
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:334
device_memory_resource * get_current_device_resource()
Get the memory resource for the current device.
Definition: per_device_resource.hpp:278
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:237
device_memory_resource * get_per_device_resource(cuda_device_id device_id)
Get the resource for the specified device.
Definition: per_device_resource.hpp:175
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:126
std::mutex & map_lock()
Reference to the lock.
Definition: per_device_resource.hpp:117
auto & get_ref_map()
Reference to the map from device id -> resource_ref.
Definition: per_device_resource.hpp:145
device_memory_resource * initial_resource()
Returns a pointer to the initial resource.
Definition: per_device_resource.hpp:108
std::mutex & ref_map_lock()
Reference to the lock.
Definition: per_device_resource.hpp:135
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