9 #include <rmm/detail/aligned.hpp>
10 #include <rmm/detail/error.hpp>
11 #include <rmm/detail/export.hpp>
12 #include <rmm/detail/format.hpp>
14 #include <cuda/memory_resource>
15 #include <cuda/stream_ref>
16 #include <cuda_runtime_api.h>
21 namespace RMM_NAMESPACE {
34 int pageableMemoryAccess;
35 RMM_CUDA_TRY(cudaDeviceGetAttribute(
36 &pageableMemoryAccess, cudaDevAttrPageableMemoryAccess, device_id.
value()));
37 return pageableMemoryAccess == 1;
73 "System memory allocator is not supported with this hardware/software version.");
95 void*
allocate([[maybe_unused]] cuda::stream_ref stream,
100 return rmm::detail::aligned_host_allocate(
102 return ::operator
new(size);
104 }
catch (std::bad_alloc
const& e) {
105 auto const msg = std::string(
"Failed to allocate ") + rmm::detail::format_bytes(bytes) +
106 std::string(
"of memory: ") + e.what();
131 RMM_ASSERT_CUDA_SUCCESS_SAFE_SHUTDOWN(cudaStreamSynchronize(stream.get()));
133 rmm::detail::aligned_host_deallocate(
146 auto* ptr = allocate(cuda::stream_ref{cudaStream_t{
nullptr}}, bytes, alignment);
147 RMM_CUDA_TRY(cudaStreamSynchronize(cudaStream_t{
nullptr}));
162 deallocate(cuda::stream_ref{cudaStream_t{
nullptr}}, ptr, bytes, alignment);
171 cuda::mr::device_accessible) noexcept
181 cuda::mr::host_accessible) noexcept
201 static_assert(cuda::mr::synchronous_resource<system_memory_resource>);
202 static_assert(cuda::mr::resource<system_memory_resource>);
204 cuda::mr::synchronous_resource_with<system_memory_resource, cuda::mr::device_accessible>);
206 cuda::mr::synchronous_resource_with<system_memory_resource, cuda::mr::host_accessible>);
207 static_assert(cuda::mr::resource_with<system_memory_resource, cuda::mr::device_accessible>);
208 static_assert(cuda::mr::resource_with<system_memory_resource, cuda::mr::host_accessible>);
Memory resource that uses malloc/free for allocation/deallocation.
Definition: system_memory_resource.hpp:68
system_memory_resource(system_memory_resource const &)=default
Default copy constructor.
void deallocate(cuda::stream_ref stream, void *ptr, std::size_t bytes, [[maybe_unused]] std::size_t alignment=rmm::CUDA_ALLOCATION_ALIGNMENT) noexcept
Deallocate memory pointed to by ptr.
Definition: system_memory_resource.hpp:122
system_memory_resource(system_memory_resource &&)=default
Default copy constructor.
void * allocate([[maybe_unused]] cuda::stream_ref stream, std::size_t bytes, [[maybe_unused]] std::size_t alignment=rmm::CUDA_ALLOCATION_ALIGNMENT)
Allocates memory of size at least bytes.
Definition: system_memory_resource.hpp:95
system_memory_resource & operator=(system_memory_resource const &)=default
Default copy assignment operator.
bool operator==(system_memory_resource const &) const noexcept
Compare this resource to another.
Definition: system_memory_resource.hpp:192
friend void get_property(system_memory_resource const &, cuda::mr::device_accessible) noexcept
Enables the cuda::mr::device_accessible property.
Definition: system_memory_resource.hpp:170
bool operator!=(system_memory_resource const &) const noexcept
Compare this resource to another.
Definition: system_memory_resource.hpp:197
void * allocate_sync(std::size_t bytes, std::size_t alignment=rmm::CUDA_ALLOCATION_ALIGNMENT)
Allocates memory of size at least bytes synchronously.
Definition: system_memory_resource.hpp:144
void deallocate_sync(void *ptr, std::size_t bytes, std::size_t alignment=rmm::CUDA_ALLOCATION_ALIGNMENT) noexcept
Deallocate memory pointed to by ptr synchronously.
Definition: system_memory_resource.hpp:158
friend void get_property(system_memory_resource const &, cuda::mr::host_accessible) noexcept
Enables the cuda::mr::host_accessible property.
Definition: system_memory_resource.hpp:180
system_memory_resource & operator=(system_memory_resource &&)=default
Default move assignment operator.
Exception thrown when RMM runs out of memory.
Definition: error.hpp:76
cuda_device_id get_current_cuda_device()
Returns a cuda_device_id for the current device.
static constexpr std::size_t CUDA_ALLOCATION_ALIGNMENT
Default alignment used for CUDA memory allocation.
Definition: aligned.hpp:25
Strong type for a CUDA device identifier.
Definition: cuda_device.hpp:27
constexpr value_type value() const noexcept
The wrapped integer value.
Definition: cuda_device.hpp:43
static bool is_system_memory_supported(cuda_device_id device_id)
Check if system allocated memory (SAM) is supported on the specified device.
Definition: system_memory_resource.hpp:31