11 #include <cuda_runtime_api.h>
13 #include <cuda/memory_resource>
20 #include <rapidsmpf/error.hpp>
21 #include <rapidsmpf/memory/host_memory_resource.hpp>
22 #include <rapidsmpf/system_info.hpp>
23 #include <rapidsmpf/utils.hpp>
28 #define RAPIDSMPF_PINNED_MEM_RES_MIN_CUDA_VERSION 12060
29 #define RAPIDSMPF_PINNED_MEM_RES_MIN_CUDA_VERSION_STR "v12.6"
40 inline bool is_pinned_memory_resources_supported() {
41 static const bool supported = [] {
43 int cuda_pool_supported{};
44 auto attr_result = cudaDeviceGetAttribute(
46 cudaDevAttrMemoryPoolsSupported,
49 if (attr_result != cudaSuccess || cuda_pool_supported != 1) {
53 int cuda_driver_version{};
54 auto driver_result = cudaDriverGetVersion(&cuda_driver_version);
55 int cuda_runtime_version{};
56 auto runtime_result = cudaRuntimeGetVersion(&cuda_runtime_version);
57 return driver_result == cudaSuccess && runtime_result == cudaSuccess
58 && cuda_driver_version >= RAPIDSMPF_PINNED_MEM_RES_MIN_CUDA_VERSION
59 && cuda_runtime_version >= RAPIDSMPF_PINNED_MEM_RES_MIN_CUDA_VERSION;
64 class PinnedMemoryResource;
104 int numa_id = get_current_numa_node()
164 struct PinnedMemoryResourceImpl;
165 std::shared_ptr<PinnedMemoryResourceImpl> impl_;
168 static_assert(cuda::mr::resource<PinnedMemoryResource>);
169 static_assert(cuda::mr::resource_with<PinnedMemoryResource, cuda::mr::host_accessible>);
170 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.
bool is_equal(HostMemoryResource const &other) const noexcept override
Compares this resource to another resource.
PinnedMemoryResource(int numa_id=get_current_numa_node())
Construct a pinned (page-locked) host memory 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.
static std::shared_ptr< PinnedMemoryResource > make_if_available(int numa_id=get_current_numa_node())
Create a pinned memory resource if the system supports pinned memory.
cuda_device_id get_current_cuda_device()
static constexpr std::size_t CUDA_ALLOCATION_ALIGNMENT