22 #include <rmm/detail/thrust_namespace.h>
23 #include <thrust/device_malloc_allocator.h>
24 #include <thrust/device_ptr.h>
25 #include <thrust/memory.h>
27 #include <cuda/memory_resource>
47 using async_resource_ref = cuda::mr::async_resource_ref<cuda::mr::device_accessible>;
50 using Base = thrust::device_malloc_allocator<T>;
95 : _mr(other.resource()), _stream{other.
stream()}
107 return thrust::device_pointer_cast(
108 static_cast<T*
>(_mr.allocate_async(num *
sizeof(T), _stream)));
120 return _mr.deallocate_async(thrust::raw_pointer_cast(ptr), num *
sizeof(T), _stream);
Strongly-typed non-owning wrapper for CUDA streams with default constructor.
Definition: cuda_stream_view.hpp:41
An allocator compatible with Thrust containers and algorithms using a device_memory_resource for memo...
Definition: thrust_allocator_adaptor.hpp:46
thrust_allocator(cuda_stream_view stream, async_resource_ref mr)
Constructs a thrust_allocator using a device memory resource and stream.
Definition: thrust_allocator_adaptor.hpp:86
typename Base::pointer pointer
The pointer type.
Definition: thrust_allocator_adaptor.hpp:51
thrust_allocator(thrust_allocator< U > const &other)
Copy constructor. Copies the resource pointer and stream.
Definition: thrust_allocator_adaptor.hpp:94
pointer allocate(size_type num)
Allocate objects of type T
Definition: thrust_allocator_adaptor.hpp:105
cuda_stream_view stream() const noexcept
The stream used by this allocator.
Definition: thrust_allocator_adaptor.hpp:131
thrust_allocator()=default
Default constructor creates an allocator using the default memory resource and default stream.
async_resource_ref memory_resource() const noexcept
The async_resource_ref used to allocate and deallocate.
Definition: thrust_allocator_adaptor.hpp:126
typename Base::size_type size_type
The size type.
Definition: thrust_allocator_adaptor.hpp:52
thrust::device_malloc_allocator< T > Base
The base type of this allocator.
Definition: thrust_allocator_adaptor.hpp:50
friend void get_property(thrust_allocator const &, cuda::mr::device_accessible) noexcept
Enables the cuda::mr::device_accessible property.
Definition: thrust_allocator_adaptor.hpp:138
void deallocate(pointer ptr, size_type num)
Deallocates objects of type T
Definition: thrust_allocator_adaptor.hpp:118
thrust_allocator(cuda_stream_view stream)
Constructs a thrust_allocator using the default device memory resource and specified stream.
Definition: thrust_allocator_adaptor.hpp:77
device_memory_resource * get_current_device_resource()
Get the memory resource for the current device.
Definition: per_device_resource.hpp:207
Management of per-device device_memory_resources.
Provides the type of a thrust_allocator instantiated with another type.
Definition: thrust_allocator_adaptor.hpp:61