19 #include <rmm/detail/error.hpp>
40 template <
typename Upstream>
43 using lock_t = std::lock_guard<std::mutex>;
57 RMM_EXPECTS(
nullptr != upstream,
"Unexpected null upstream resource pointer.");
77 bool supports_streams() const noexcept
override {
return upstream_->supports_streams(); }
86 return upstream_->supports_get_mem_info();
104 return upstream_->allocate(bytes, stream);
114 void do_deallocate(
void* ptr, std::size_t bytes,
cuda_stream_view stream)
override
117 upstream_->deallocate(ptr, bytes, stream);
127 bool do_is_equal(device_memory_resource
const& other)
const noexcept
override
129 if (
this == &other) {
return true; }
130 auto thread_safe_other =
dynamic_cast<thread_safe_resource_adaptor<Upstream> const*
>(&other);
131 if (thread_safe_other !=
nullptr) {
132 return upstream_->is_equal(*thread_safe_other->get_upstream());
134 return upstream_->is_equal(other);
145 std::pair<std::size_t, std::size_t> do_get_mem_info(cuda_stream_view stream)
const override
148 return upstream_->get_mem_info(stream);
151 std::mutex
mutable mtx;
Strongly-typed non-owning wrapper for CUDA streams with default constructor.
Definition: cuda_stream_view.hpp:41
Base class for all libcudf device memory allocation.
Definition: device_memory_resource.hpp:89
Resource that adapts Upstream memory resource adaptor to be thread safe.
Definition: thread_safe_resource_adaptor.hpp:41
std::lock_guard< std::mutex > lock_t
Type of lock used to synchronize access.
Definition: thread_safe_resource_adaptor.hpp:43
bool supports_streams() const noexcept override
Query whether the resource supports use of non-null CUDA streams for allocation/deallocation.
Definition: thread_safe_resource_adaptor.hpp:77
Upstream * get_upstream() const noexcept
Get the upstream memory resource.
Definition: thread_safe_resource_adaptor.hpp:72
bool supports_get_mem_info() const noexcept override
Query whether the resource supports the get_mem_info API.
Definition: thread_safe_resource_adaptor.hpp:84
thread_safe_resource_adaptor(Upstream *upstream)
Construct a new thread safe resource adaptor using upstream to satisfy allocation requests.
Definition: thread_safe_resource_adaptor.hpp:55