cuda_async_view_memory_resource.hpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2021-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
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 RMM_NAMESPACE_BEGIN
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  [[nodiscard]] 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  [[nodiscard]] void* allocate_sync(std::size_t bytes,
96  std::size_t alignment = rmm::CUDA_ALLOCATION_ALIGNMENT);
97 
105  void deallocate_sync(void* ptr,
106  std::size_t bytes,
107  std::size_t alignment = rmm::CUDA_ALLOCATION_ALIGNMENT) noexcept;
108 
116  [[nodiscard]] bool operator==(cuda_async_view_memory_resource const& other) const noexcept;
117 
121  [[nodiscard]] bool operator!=(cuda_async_view_memory_resource const& other) const noexcept;
122 
129  RMM_CONSTEXPR_FRIEND void get_property(cuda_async_view_memory_resource const&,
130  cuda::mr::device_accessible) noexcept
131  {
132  }
133 
134  private:
135  cudaMemPool_t cuda_pool_handle_{};
136 };
137 
138 // static property checks
139 static_assert(cuda::mr::synchronous_resource<cuda_async_view_memory_resource>);
140 static_assert(cuda::mr::resource<cuda_async_view_memory_resource>);
141 static_assert(cuda::mr::synchronous_resource_with<cuda_async_view_memory_resource,
142  cuda::mr::device_accessible>);
143 static_assert(
144  cuda::mr::resource_with<cuda_async_view_memory_resource, cuda::mr::device_accessible>);
145  // end of group
147 } // namespace mr
148 RMM_NAMESPACE_END
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.