19 #include <rmm/cuda_stream_view.hpp>
20 #include <rmm/mr/device/device_memory_resource.hpp>
25 #include <type_traits>
84 return static_cast<value_type*
>(
resource()->
allocate(num *
sizeof(T), stream));
114 template <
typename T,
typename U>
115 bool operator==(polymorphic_allocator<T>
const& lhs, polymorphic_allocator<U>
const& rhs)
117 return lhs.resource()->is_equal(*rhs.resource());
120 template <
typename T,
typename U>
121 bool operator!=(polymorphic_allocator<T>
const& lhs, polymorphic_allocator<U>
const& rhs)
123 return not(lhs == rhs);
148 template <
typename Allocator>
151 using value_type =
typename std::allocator_traits<Allocator>::value_type;
165 : alloc_{allocator}, stream_{
stream}
177 template <
typename OtherAllocator>
188 template <
typename T>
212 void deallocate(value_type* ptr, std::size_t num) { alloc_.deallocate(ptr, num,
stream()); }
231 template <
typename A,
typename O>
232 bool operator==(stream_allocator_adaptor<A>
const& lhs, stream_allocator_adaptor<O>
const& rhs)
234 return lhs.underlying_allocator() == rhs.underlying_allocator();
237 template <
typename A,
typename O>
238 bool operator!=(stream_allocator_adaptor<A>
const& lhs, stream_allocator_adaptor<O>
const& rhs)
240 return not(lhs == rhs);
253 template <
typename Allocator>
254 auto make_stream_allocator_adaptor(Allocator
const& allocator, cuda_stream_view stream)
256 return stream_allocator_adaptor<Allocator>{allocator, stream};
polymorphic_allocator(device_memory_resource *mr)
Construct a polymorphic_allocator using the provided memory resource.
Definition: polymorphic_allocator.hpp:61
void * allocate(std::size_t bytes, cuda_stream_view stream=cuda_stream_view{})
Allocates memory of size at least bytes.
Definition: device_memory_resource.hpp:106
Management of per-device device_memory_resources.
Adapts a stream ordered allocator to provide a standard Allocator interface.
Definition: polymorphic_allocator.hpp:149
void deallocate(value_type *ptr, std::size_t num, cuda_stream_view stream)
Deallocates storage pointed to by ptr.
Definition: polymorphic_allocator.hpp:97
Strongly-typed non-owning wrapper for CUDA streams with default constructor.
Definition: cuda_stream_view.hpp:34
stream_allocator_adaptor(Allocator const &allocator, cuda_stream_view stream)
Construct a stream_allocator_adaptor using a as the underlying allocator.
Definition: polymorphic_allocator.hpp:164
polymorphic_allocator()=default
Construct a polymorphic_allocator using the return value of rmm::mr::get_current_device_resource() as...
void deallocate(value_type *ptr, std::size_t num)
Deallocates storage pointed to by ptr using the underlying allocator on stream().
Definition: polymorphic_allocator.hpp:212
A stream ordered Allocator using a rmm::mr::device_memory_resource to satisfy (de)allocations.
Definition: polymorphic_allocator.hpp:44
polymorphic_allocator(polymorphic_allocator< U > const &other) noexcept
Construct a polymorphic_allocator using other.resource() as the underlying memory resource.
Definition: polymorphic_allocator.hpp:71
void deallocate(void *ptr, std::size_t bytes, cuda_stream_view stream=cuda_stream_view{})
Deallocate memory pointed to by p.
Definition: device_memory_resource.hpp:129
Rebinds the allocator to the specified type.
Definition: polymorphic_allocator.hpp:189
value_type * allocate(std::size_t num)
Allocates storage for num objects of type T using the underlying allocator on stream().
Definition: polymorphic_allocator.hpp:201
Allocator underlying_allocator() const noexcept
Returns the underlying stream-ordered allocator.
Definition: polymorphic_allocator.hpp:224
device_memory_resource * resource() const noexcept
Returns pointer to the underlying rmm::mr::device_memory_resource.
Definition: polymorphic_allocator.hpp:107
stream_allocator_adaptor(stream_allocator_adaptor< OtherAllocator > const &other)
Construct a stream_allocator_adaptor using other.underlying_allocator() and other....
Definition: polymorphic_allocator.hpp:178
value_type * allocate(std::size_t num, cuda_stream_view stream)
Allocates storage for num objects of type T using the underlying memory resource.
Definition: polymorphic_allocator.hpp:82
cuda_stream_view stream() const noexcept
Returns the underlying stream on which calls to the underlying allocator are made.
Definition: polymorphic_allocator.hpp:218
Base class for all libcudf device memory allocation.
Definition: device_memory_resource.hpp:82
device_memory_resource * get_current_device_resource()
Get the memory resource for the current device.
Definition: per_device_resource.hpp:197