19 #include <rmm/mr/device/device_memory_resource.hpp>
22 #include <thrust/detail/type_traits/pointer_traits.h>
23 #include <thrust/device_malloc_allocator.h>
39 using Base = thrust::device_malloc_allocator<T>;
40 using pointer =
typename Base::pointer;
41 using size_type =
typename Base::size_type;
98 return thrust::device_pointer_cast(
static_cast<T*
>(_mr->
allocate(num *
sizeof(T), _stream)));
110 return _mr->
deallocate(thrust::raw_pointer_cast(ptr), num *
sizeof(T), _stream);
125 device_memory_resource* _mr{rmm::mr::get_current_device_resource()};
thrust_allocator(cuda_stream_view stream, device_memory_resource *mr)
Constructs a thrust_allocator using a device memory resource and stream.
Definition: thrust_allocator_adaptor.hpp:75
An allocator compatible with Thrust containers and algorithms using a device_memory_resource for memo...
Definition: thrust_allocator_adaptor.hpp:37
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.
pointer allocate(size_type num)
Allocate objects of type T
Definition: thrust_allocator_adaptor.hpp:96
Strongly-typed non-owning wrapper for CUDA streams with default constructor.
Definition: cuda_stream_view.hpp:34
thrust_allocator(thrust_allocator< U > const &other)
Copy constructor. Copies the resource pointer and stream.
Definition: thrust_allocator_adaptor.hpp:85
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
Provides the type of a thrust_allocator instantiated with another type.
Definition: thrust_allocator_adaptor.hpp:50
cuda_stream_view stream() const noexcept
Returns the stream used by this allocator.
Definition: thrust_allocator_adaptor.hpp:121
thrust_allocator()=default
Default constructor creates an allocator using the default memory resource and default stream.
thrust_allocator(cuda_stream_view stream)
Constructs a thrust_allocator using the default device memory resource and specified stream.
Definition: thrust_allocator_adaptor.hpp:66
void deallocate(pointer ptr, size_type num)
Deallocates objects of type T
Definition: thrust_allocator_adaptor.hpp:108
Base class for all libcudf device memory allocation.
Definition: device_memory_resource.hpp:82
device_memory_resource * resource() const noexcept
Returns the device memory resource used by this allocator.
Definition: thrust_allocator_adaptor.hpp:116