12 #include <cuda_runtime_api.h>
14 #include <cuda/memory_resource>
21 #include <rapidsmpf/config.hpp>
22 #include <rapidsmpf/detail/rmm_resource_adaptor_impl.hpp>
23 #include <rapidsmpf/error.hpp>
24 #include <rapidsmpf/system_info.hpp>
25 #include <rapidsmpf/utils/misc.hpp>
29 #define RAPIDSMPF_PINNED_MEM_RES_MIN_CUDA_VERSION 12060
30 #define RAPIDSMPF_PINNED_MEM_RES_MIN_CUDA_VERSION_STR "v12.6"
45 static const bool supported = [] {
47 int cuda_pool_supported{};
48 auto attr_result = cudaDeviceGetAttribute(
50 cudaDevAttrMemoryPoolsSupported,
53 if (attr_result != cudaSuccess || cuda_pool_supported != 1) {
57 int cuda_driver_version{};
58 auto driver_result = cudaDriverGetVersion(&cuda_driver_version);
59 int cuda_runtime_version{};
60 auto runtime_result = cudaRuntimeGetVersion(&cuda_runtime_version);
61 return driver_result == cudaSuccess && runtime_result == cudaSuccess
62 && cuda_driver_version >= RAPIDSMPF_PINNED_MEM_RES_MIN_CUDA_VERSION
63 && cuda_runtime_version >= RAPIDSMPF_PINNED_MEM_RES_MIN_CUDA_VERSION;
94 :
public cuda::mr::shared_resource<
95 detail::RmmResourceAdaptorImpl<cuda::pinned_memory_pool>> {
96 using shared_base = cuda::mr::shared_resource<
101 static constexpr std::nullopt_t
Disabled = std::nullopt;
171 cuda::stream_ref stream,
175 return get().allocate(stream, size, alignment);
187 cuda::stream_ref stream,
192 get().deallocate(stream, ptr, size, alignment);
202 return get() == other.get();
211 return get().current_allocated();
220 return get().get_main_record();
229 return pool_properties_;
263 PinnedPoolProperties pool_properties_;
266 static_assert(cuda::mr::resource<PinnedMemoryResource>);
267 static_assert(cuda::mr::resource_with<PinnedMemoryResource, cuda::mr::host_accessible>);
268 static_assert(cuda::mr::resource_with<PinnedMemoryResource, cuda::mr::device_accessible>);
Memory resource that provides pinned (page-locked) host memory using a pool.
static constexpr std::string_view DefaultInitiPoolSizeFactor
Fraction of total host memory per GPU used as the initial pinned pool size when no explicit pinned_in...
static constexpr std::nullopt_t Disabled
Sentinel value indicating that pinned host memory is disabled.
ScopedMemoryRecord get_main_memory_record() const
Returns the main memory record for the pinned pool.
std::function< std::int64_t()> get_memory_available_cb() const
Returns a memory-availability callback for the pinned pool, if the pool has a configured maximum size...
std::int64_t current_allocated() const noexcept
Returns the total number of currently allocated bytes.
bool operator==(PinnedMemoryResource const &other) const noexcept
Equality comparison.
static constexpr bool EnabledByDefault
Whether pinned host memory is enabled by default.
static std::optional< PinnedMemoryResource > from_options(config::Options options)
Construct from configuration options.
static constexpr std::string_view DefaultMaxPoolSizeFactor
Fraction of total host memory per GPU used as the maximum pinned pool size when no explicit pinned_ma...
static std::optional< 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.
void * allocate(cuda::stream_ref stream, std::size_t size, std::size_t alignment=rmm::CUDA_ALLOCATION_ALIGNMENT)
Allocates pinned host memory associated with a CUDA stream.
constexpr PinnedPoolProperties const & properties() const noexcept
Returns the properties used to configure the pool.
void deallocate(cuda::stream_ref stream, void *ptr, std::size_t size, std::size_t alignment=rmm::CUDA_ALLOCATION_ALIGNMENT) noexcept
Deallocates pinned host memory associated with a CUDA stream.
friend void get_property(PinnedMemoryResource const &, cuda::mr::host_accessible) noexcept
Enables the cuda::mr::host_accessible property.
Manages configuration options for RapidsMPF operations.
Implementation class for RmmResourceAdaptor.
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,...
Memory statistics for a specific scope.