9#include <rmm/detail/export.hpp>
13#include <cuda/memory_resource>
70 : mr_(other.get_upstream_resource())
111 mutable cuda::mr::any_resource<cuda::mr::device_accessible> mr_{
126template <
typename T,
typename U>
144template <
typename T,
typename U>
147 return not(lhs == rhs);
172template <
typename Allocator>
173class stream_allocator_adaptor {
176 typename std::allocator_traits<Allocator>::value_type;
179 stream_allocator_adaptor() =
delete;
191 : alloc_{allocator}, stream_{
stream}
203 template <
typename OtherAllocator>
214 template <
typename T>
216 using other = stream_allocator_adaptor<
typename std::allocator_traits<
217 Allocator>::template rebind_alloc<T>>;
240 alloc_.deallocate(ptr, num,
stream());
246 [[nodiscard]] cuda::stream_ref
stream() const noexcept {
return stream_; }
255 cuda::stream_ref stream_{
256 cuda::invalid_stream_t{}};
270template <
typename A,
typename O>
287template <
typename A,
typename O>
290 return not(lhs == rhs);
A stream ordered Allocator using a device_async_resource_ref to satisfy (de)allocations.
Definition polymorphic_allocator.hpp:41
void deallocate(value_type *ptr, std::size_t num, cuda::stream_ref stream) noexcept
Deallocates storage pointed to by ptr.
Definition polymorphic_allocator.hpp:97
T value_type
T, the value type of objects allocated by this allocator.
Definition polymorphic_allocator.hpp:43
rmm::device_async_resource_ref get_upstream_resource() const noexcept
rmm::device_async_resource_ref to the upstream resource
Definition polymorphic_allocator.hpp:105
value_type * allocate(std::size_t num, cuda::stream_ref stream)
Allocates storage for num objects of type T using the underlying memory resource.
Definition polymorphic_allocator.hpp:81
polymorphic_allocator()=default
Construct a polymorphic_allocator using the return value of rmm::mr::get_current_device_resource_ref(...
polymorphic_allocator(cuda::mr::any_resource< cuda::mr::device_accessible > mr)
Construct a polymorphic_allocator using the provided memory resource.
Definition polymorphic_allocator.hpp:58
polymorphic_allocator(polymorphic_allocator< U > const &other) noexcept
Construct a polymorphic_allocator using the underlying memory resource of other.
Definition polymorphic_allocator.hpp:69
Adapts a stream ordered allocator to provide a standard Allocator interface.
Definition polymorphic_allocator.hpp:173
stream_allocator_adaptor(Allocator const &allocator, cuda::stream_ref stream)
Construct a stream_allocator_adaptor using a as the underlying allocator.
Definition polymorphic_allocator.hpp:190
Allocator underlying_allocator() const noexcept
Definition polymorphic_allocator.hpp:251
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:227
stream_allocator_adaptor(stream_allocator_adaptor< OtherAllocator > const &other)
Construct a stream_allocator_adaptor using other.underlying_allocator() and other....
Definition polymorphic_allocator.hpp:204
void deallocate(value_type *ptr, std::size_t num) noexcept
Deallocates storage pointed to by ptr using the underlying allocator on stream().
Definition polymorphic_allocator.hpp:238
cuda::stream_ref stream() const noexcept
Definition polymorphic_allocator.hpp:246
typename std::allocator_traits< Allocator >::value_type value_type
Definition polymorphic_allocator.hpp:175
bool operator==(polymorphic_allocator< T > const &lhs, polymorphic_allocator< U > const &rhs)
Compare two polymorphic_allocators for equality.
Definition polymorphic_allocator.hpp:127
device_async_resource_ref get_current_device_resource_ref()
Get the device_async_resource_ref for the current device.
Definition per_device_resource.hpp:187
bool operator!=(polymorphic_allocator< T > const &lhs, polymorphic_allocator< U > const &rhs)
Compare two polymorphic_allocators for inequality.
Definition polymorphic_allocator.hpp:145
cuda::mr::resource_ref< cuda::mr::device_accessible > device_async_resource_ref
Alias for a cuda::mr::resource_ref with the property cuda::mr::device_accessible.
Definition resource_ref.hpp:30
static constexpr std::size_t CUDA_ALLOCATION_ALIGNMENT
Default alignment used for CUDA memory allocation.
Definition aligned.hpp:25
Memory Resource classes and adaptors.
Management of per-device memory resources.
Rebinds the allocator to the specified type.
Definition polymorphic_allocator.hpp:215
stream_allocator_adaptor< typename std::allocator_traits< Allocator >::template rebind_alloc< T > > other
The type to bind to.
Definition polymorphic_allocator.hpp:216