pool_memory_resource.hpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2020-2026, NVIDIA CORPORATION.
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 #pragma once
6 
7 #include <rmm/detail/export.hpp>
8 #include <rmm/mr/detail/pool_memory_resource_impl.hpp>
9 #include <rmm/resource_ref.hpp>
10 
11 #include <cuda/memory_resource>
12 
13 #include <cstddef>
14 #include <optional>
15 
16 namespace RMM_NAMESPACE {
17 namespace mr {
34 class RMM_EXPORT pool_memory_resource
35  : public cuda::mr::shared_resource<detail::pool_memory_resource_impl> {
36  using shared_base = cuda::mr::shared_resource<detail::pool_memory_resource_impl>;
37 
38  public:
44  RMM_CONSTEXPR_FRIEND void get_property(pool_memory_resource const&,
45  cuda::mr::device_accessible) noexcept
46  {
47  }
48 
62  explicit pool_memory_resource(cuda::mr::any_resource<cuda::mr::device_accessible> upstream,
63  std::size_t initial_pool_size,
64  std::optional<std::size_t> maximum_pool_size = std::nullopt);
65 
69  [[nodiscard]] device_async_resource_ref get_upstream_resource() const noexcept;
70 
78  [[nodiscard]] std::size_t pool_size() const noexcept;
79 };
80 
81 static_assert(cuda::mr::resource_with<pool_memory_resource, cuda::mr::device_accessible>,
82  "pool_memory_resource does not satisfy the cuda::mr::resource concept");
83  // end of group
85 } // namespace mr
86 } // namespace RMM_NAMESPACE
A coalescing best-fit suballocator which uses a pool of memory allocated from an upstream memory_reso...
Definition: pool_memory_resource.hpp:35
pool_memory_resource(cuda::mr::any_resource< cuda::mr::device_accessible > upstream, std::size_t initial_pool_size, std::optional< std::size_t > maximum_pool_size=std::nullopt)
Construct a pool_memory_resource and allocate the initial device memory pool using upstream.
device_async_resource_ref get_upstream_resource() const noexcept
rmm::device_async_resource_ref to the upstream resource
friend void get_property(pool_memory_resource const &, cuda::mr::device_accessible) noexcept
Enables the cuda::mr::device_accessible property.
Definition: pool_memory_resource.hpp:44
cuda::mr::resource_ref< cuda::mr::device_accessible > device_async_resource_ref
Alias for a cuda::mr::resource_ref with the property cuda::mr::device_accessible.
Definition: resource_ref.hpp:30