8 #include <rmm/detail/aligned.hpp>
9 #include <rmm/detail/cccl_adaptors.hpp>
10 #include <rmm/detail/cuda_memory_resource.hpp>
11 #include <rmm/detail/error.hpp>
12 #include <rmm/detail/export.hpp>
13 #include <rmm/detail/nvtx/ranges.hpp>
17 namespace RMM_NAMESPACE {
95 #ifdef RMM_ENABLE_LEGACY_MR_INTERFACE
116 #ifdef RMM_DEPRECATE_LEGACY_MR_INTERFACE
118 "This function is deprecated. Use allocate(cuda_stream_view stream, std::size_t bytes, "
119 "std::size_t alignment) instead.")]]
124 return do_allocate(bytes, stream);
145 #ifdef RMM_DEPRECATE_LEGACY_MR_INTERFACE
147 "This function is deprecated. Use deallocate(cuda_stream_view stream, void* ptr, std::size_t "
148 "bytes, std::size_t alignment) instead.")]]
150 void deallocate(
void* ptr,
155 do_deallocate(ptr, bytes, stream);
175 #ifdef RMM_DEPRECATE_LEGACY_MR_INTERFACE
177 "This function is deprecated. Use allocate_sync(std::size_t bytes, std::size_t alignment) "
180 void* allocate(std::size_t bytes, [[maybe_unused]] std::size_t alignment)
183 return do_allocate(bytes, cuda_stream_view{});
201 #ifdef RMM_DEPRECATE_LEGACY_MR_INTERFACE
203 "This function is deprecated. Use deallocate_sync(void* ptr, std::size_t bytes, std::size_t "
204 "alignment) instead.")]]
206 void deallocate(
void* ptr, std::size_t bytes, [[maybe_unused]] std::size_t alignment) noexcept
209 do_deallocate(ptr, bytes, cuda_stream_view{});
230 #ifdef RMM_DEPRECATE_LEGACY_MR_INTERFACE
232 "This function is deprecated. Use allocate(cuda_stream_view stream, std::size_t bytes, "
233 "std::size_t alignment) instead.")]]
235 void* allocate_async(std::size_t bytes,
236 [[maybe_unused]] std::size_t alignment,
237 cuda_stream_view stream)
240 return do_allocate(bytes, stream);
260 #ifdef RMM_DEPRECATE_LEGACY_MR_INTERFACE
262 "This function is deprecated. Use allocate(cuda_stream_view stream, std::size_t bytes, "
263 "std::size_t alignment) instead.")]]
265 void* allocate_async(std::size_t bytes, cuda_stream_view stream)
268 return do_allocate(bytes, stream);
287 #ifdef RMM_DEPRECATE_LEGACY_MR_INTERFACE
289 "This function is deprecated. Use deallocate(cuda_stream_view stream, void* ptr, std::size_t "
290 "bytes, std::size_t alignment) instead.")]]
292 void deallocate_async(
void* ptr,
294 [[maybe_unused]] std::size_t alignment,
295 cuda_stream_view stream) noexcept
298 do_deallocate(ptr, bytes, stream);
316 #ifdef RMM_DEPRECATE_LEGACY_MR_INTERFACE
318 "This function is deprecated. Use deallocate(cuda_stream_view stream, void* ptr, std::size_t "
319 "bytes, std::size_t alignment) instead.")]]
321 void deallocate_async(
void* ptr, std::size_t bytes, cuda_stream_view stream) noexcept
324 do_deallocate(ptr, bytes, stream);
344 "Alignment must be less than or equal to 256 and a power of two",
384 "Alignment must be less than or equal to 256 and a power of two",
386 return do_allocate(bytes, stream);
403 do_deallocate(ptr, bytes, stream);
421 return do_is_equal(other);
433 return do_is_equal(other);
445 return !do_is_equal(other);
481 virtual void do_deallocate(
void* ptr, std::size_t bytes,
cuda_stream_view stream) noexcept = 0;
499 return this == &other;
504 static_assert(rmm::detail::polyfill::resource<device_memory_resource>);
505 static_assert(rmm::detail::polyfill::async_resource<device_memory_resource>);
507 rmm::detail::polyfill::resource_with<device_memory_resource, cuda::mr::device_accessible>);
509 rmm::detail::polyfill::async_resource_with<device_memory_resource, cuda::mr::device_accessible>);
Exception thrown when an RMM allocation fails.
Definition: error.hpp:44
Strongly-typed non-owning wrapper for CUDA streams with default constructor.
Definition: cuda_stream_view.hpp:28
Base class for all librmm device memory allocation.
Definition: device_memory_resource.hpp:83
void * allocate_sync(std::size_t bytes, std::size_t alignment=rmm::CUDA_ALLOCATION_ALIGNMENT)
Allocates memory of size at least bytes.
Definition: device_memory_resource.hpp:340
friend void get_property(device_memory_resource const &, cuda::mr::device_accessible) noexcept
Enables the cuda::mr::device_accessible property.
Definition: device_memory_resource.hpp:453
device_memory_resource(device_memory_resource &&) noexcept=default
Default move constructor.
void deallocate(cuda_stream_view stream, void *ptr, std::size_t bytes, [[maybe_unused]] std::size_t alignment=rmm::CUDA_ALLOCATION_ALIGNMENT) noexcept
Deallocate memory pointed to by ptr on the specified stream.
Definition: device_memory_resource.hpp:398
void * allocate(cuda_stream_view stream, std::size_t bytes, std::size_t alignment=rmm::CUDA_ALLOCATION_ALIGNMENT)
Allocates memory of size at least bytes on the specified stream.
Definition: device_memory_resource.hpp:378
void deallocate_sync(void *ptr, std::size_t bytes, [[maybe_unused]] std::size_t alignment=rmm::CUDA_ALLOCATION_ALIGNMENT) noexcept
Deallocate memory pointed to by p.
Definition: device_memory_resource.hpp:357
bool operator==(device_memory_resource const &other) const noexcept
Comparison operator with another device_memory_resource.
Definition: device_memory_resource.hpp:431
bool operator!=(device_memory_resource const &other) const noexcept
Comparison operator with another device_memory_resource.
Definition: device_memory_resource.hpp:443
device_memory_resource(device_memory_resource const &)=default
Default copy constructor.
bool is_equal(device_memory_resource const &other) const noexcept
Compare this resource to another.
Definition: device_memory_resource.hpp:419
static constexpr std::size_t CUDA_ALLOCATION_ALIGNMENT
Default alignment used for CUDA memory allocation.
Definition: aligned.hpp:33
bool is_supported_alignment(std::size_t alignment) noexcept
Returns whether or not alignment is a valid memory alignment.