cuda_async_view_memory_resource.hpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2021-2026, NVIDIA CORPORATION.
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 #pragma once
6 
7 #include <rmm/aligned.hpp>
8 #include <rmm/detail/export.hpp>
9 
10 #include <cuda/memory_resource>
11 #include <cuda/stream_ref>
12 #include <cuda_runtime_api.h>
13 
14 #include <cstddef>
15 
16 namespace RMM_NAMESPACE {
17 namespace mr {
28 class RMM_EXPORT cuda_async_view_memory_resource final {
29  public:
40  cuda_async_view_memory_resource(cudaMemPool_t pool_handle);
41 
47  [[nodiscard]] cudaMemPool_t pool_handle() const noexcept;
48 
52  default;
54  default;
56  default;
58  default;
59 
70  void* allocate(cuda::stream_ref stream,
71  std::size_t bytes,
72  std::size_t alignment = rmm::CUDA_ALLOCATION_ALIGNMENT);
73 
83  void deallocate(cuda::stream_ref stream,
84  void* ptr,
85  std::size_t bytes,
86  std::size_t alignment = rmm::CUDA_ALLOCATION_ALIGNMENT) noexcept;
87 
95  void* allocate_sync(std::size_t bytes, std::size_t alignment = rmm::CUDA_ALLOCATION_ALIGNMENT);
96 
104  void deallocate_sync(void* ptr,
105  std::size_t bytes,
106  std::size_t alignment = rmm::CUDA_ALLOCATION_ALIGNMENT) noexcept;
107 
115  [[nodiscard]] bool operator==(cuda_async_view_memory_resource const& other) const noexcept;
116 
120  [[nodiscard]] bool operator!=(cuda_async_view_memory_resource const& other) const noexcept;
121 
128  RMM_CONSTEXPR_FRIEND void get_property(cuda_async_view_memory_resource const&,
129  cuda::mr::device_accessible) noexcept
130  {
131  }
132 
133  private:
134  cudaMemPool_t cuda_pool_handle_{};
135 };
136 
137 // static property checks
138 static_assert(cuda::mr::synchronous_resource<cuda_async_view_memory_resource>);
139 static_assert(cuda::mr::resource<cuda_async_view_memory_resource>);
140 static_assert(cuda::mr::synchronous_resource_with<cuda_async_view_memory_resource,
141  cuda::mr::device_accessible>);
142 static_assert(
143  cuda::mr::resource_with<cuda_async_view_memory_resource, cuda::mr::device_accessible>);
144  // end of group
146 } // namespace mr
147 } // namespace RMM_NAMESPACE
Memory resource that uses cudaMallocAsync/cudaFreeAsync for allocation/deallocation.
Definition: cuda_async_view_memory_resource.hpp:28
cudaMemPool_t pool_handle() const noexcept
Returns the underlying native handle to the CUDA pool.
cuda_async_view_memory_resource(cudaMemPool_t pool_handle)
Constructs a cuda_async_view_memory_resource which uses an existing CUDA memory pool....
static constexpr std::size_t CUDA_ALLOCATION_ALIGNMENT
Default alignment used for CUDA memory allocation.
Definition: aligned.hpp:25
RAPIDS Memory Manager - The top-level namespace for all RMM functionality.