limiting_resource_adaptor.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 #include <rmm/mr/detail/limiting_resource_adaptor_impl.hpp>
10 #include <rmm/resource_ref.hpp>
11 
12 #include <cuda/memory_resource>
13 
14 #include <cstddef>
15 
16 namespace RMM_NAMESPACE {
17 namespace mr {
35 class RMM_EXPORT limiting_resource_adaptor
36  : public cuda::mr::shared_resource<detail::limiting_resource_adaptor_impl> {
37  using shared_base = cuda::mr::shared_resource<detail::limiting_resource_adaptor_impl>;
38 
39  public:
43  RMM_CONSTEXPR_FRIEND void get_property(limiting_resource_adaptor const&,
44  cuda::mr::device_accessible) noexcept
45  {
46  }
47 
56  limiting_resource_adaptor(cuda::mr::any_resource<cuda::mr::device_accessible> upstream,
57  std::size_t allocation_limit,
58  std::size_t alignment = rmm::CUDA_ALLOCATION_ALIGNMENT);
59 
60  ~limiting_resource_adaptor() = default;
61 
65  [[nodiscard]] device_async_resource_ref get_upstream_resource() const noexcept;
66 
76  [[nodiscard]] std::size_t get_allocated_bytes() const;
77 
85  [[nodiscard]] std::size_t get_allocation_limit() const;
86 };
87 
88 static_assert(cuda::mr::resource_with<limiting_resource_adaptor, cuda::mr::device_accessible>,
89  "limiting_resource_adaptor does not satisfy the cuda::mr::resource concept");
90  // end of group
92 } // namespace mr
93 } // namespace RMM_NAMESPACE
Resource that uses an upstream resource to allocate memory and limits the total allocations possible.
Definition: limiting_resource_adaptor.hpp:36
limiting_resource_adaptor(cuda::mr::any_resource< cuda::mr::device_accessible > upstream, std::size_t allocation_limit, std::size_t alignment=rmm::CUDA_ALLOCATION_ALIGNMENT)
Construct a new limiting resource adaptor using upstream to satisfy allocation requests and limiting ...
device_async_resource_ref get_upstream_resource() const noexcept
device_async_resource_ref to the upstream resource
friend void get_property(limiting_resource_adaptor const &, cuda::mr::device_accessible) noexcept
Enables the cuda::mr::device_accessible property.
Definition: limiting_resource_adaptor.hpp:43
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
static constexpr std::size_t CUDA_ALLOCATION_ALIGNMENT
Default alignment used for CUDA memory allocation.
Definition: aligned.hpp:25