11 #include <cuda_runtime_api.h>
13 #include <cuda/memory_resource>
20 #include <rapidsmpf/config.hpp>
21 #include <rapidsmpf/error.hpp>
22 #include <rapidsmpf/memory/host_memory_resource.hpp>
23 #include <rapidsmpf/system_info.hpp>
24 #include <rapidsmpf/utils/misc.hpp>
28 #define RAPIDSMPF_PINNED_MEM_RES_MIN_CUDA_VERSION 12060
29 #define RAPIDSMPF_PINNED_MEM_RES_MIN_CUDA_VERSION_STR "v12.6"
44 static const bool supported = [] {
46 int cuda_pool_supported{};
47 auto attr_result = cudaDeviceGetAttribute(
49 cudaDevAttrMemoryPoolsSupported,
52 if (attr_result != cudaSuccess || cuda_pool_supported != 1) {
56 int cuda_driver_version{};
57 auto driver_result = cudaDriverGetVersion(&cuda_driver_version);
58 int cuda_runtime_version{};
59 auto runtime_result = cudaRuntimeGetVersion(&cuda_runtime_version);
60 return driver_result == cudaSuccess && runtime_result == cudaSuccess
61 && cuda_driver_version >= RAPIDSMPF_PINNED_MEM_RES_MIN_CUDA_VERSION
62 && cuda_runtime_version >= RAPIDSMPF_PINNED_MEM_RES_MIN_CUDA_VERSION;
195 cuda::mr::shared_resource<cuda::pinned_memory_pool> pool_;
198 static_assert(cuda::mr::resource<PinnedMemoryResource>);
199 static_assert(cuda::mr::resource_with<PinnedMemoryResource, cuda::mr::host_accessible>);
200 static_assert(cuda::mr::resource_with<PinnedMemoryResource, cuda::mr::device_accessible>);
Host memory resource using standard CPU allocation.
Memory resource that provides pinned (page-locked) host memory using a pool.
static std::shared_ptr< PinnedMemoryResource > from_options(config::Options options)
Construct from configuration options.
static std::shared_ptr< PinnedMemoryResource > make_if_available(int numa_id=get_current_numa_node(), PinnedPoolProperties pool_properties={})
Create a pinned memory resource if the system supports pinned memory.
bool is_equal(HostMemoryResource const &other) const noexcept override
Compares this resource to another resource.
static constexpr auto Disabled
Sentinel value used to disable pinned host memory.
void * allocate(rmm::cuda_stream_view stream, std::size_t size, std::size_t alignment=rmm::CUDA_ALLOCATION_ALIGNMENT) override
Allocates pinned host memory associated with a CUDA stream.
void deallocate(rmm::cuda_stream_view stream, void *ptr, std::size_t size, std::size_t alignment=rmm::CUDA_ALLOCATION_ALIGNMENT) noexcept override
Deallocates pinned host memory associated with a CUDA stream.
friend void get_property(PinnedMemoryResource const &, cuda::mr::device_accessible) noexcept
Enables the cuda::mr::host_accessible property.
PinnedMemoryResource(int numa_id=get_current_numa_node(), PinnedPoolProperties pool_properties={})
Construct a pinned (page-locked) host memory resource.
Manages configuration options for RapidsMPF operations.
cuda_device_id get_current_cuda_device()
static constexpr std::size_t CUDA_ALLOCATION_ALIGNMENT
RAPIDS Multi-Processor interfaces.
bool is_pinned_memory_resources_supported()
Checks if the PinnedMemoryResource is supported for the current CUDA version.
int get_current_numa_node() noexcept
Get the NUMA node ID associated with the calling CPU thread.
Properties for configuring a pinned memory pool.
std::optional< std::size_t > max_pool_size
Maximum size of the pool. std::nullopt means no limit.
std::size_t initial_pool_size
Initial size of the pool. Initial size is important for pinned memory performance,...