binning_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/binning_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 {
30 class RMM_EXPORT binning_memory_resource
31  : public cuda::mr::shared_resource<detail::binning_memory_resource_impl> {
32  using shared_base = cuda::mr::shared_resource<detail::binning_memory_resource_impl>;
33 
34  public:
40  RMM_CONSTEXPR_FRIEND void get_property(binning_memory_resource const&,
41  cuda::mr::device_accessible) noexcept
42  {
43  }
44 
53  explicit binning_memory_resource(cuda::mr::any_resource<cuda::mr::device_accessible> upstream);
54 
67  binning_memory_resource(cuda::mr::any_resource<cuda::mr::device_accessible> upstream,
68  int8_t min_size_exponent, // NOLINT(bugprone-easily-swappable-parameters)
69  int8_t max_size_exponent);
70 
71  ~binning_memory_resource() = default;
72 
76  [[nodiscard]] device_async_resource_ref get_upstream_resource() const noexcept;
77 
93  void add_bin(std::size_t allocation_size,
94  std::optional<device_async_resource_ref> bin_resource = std::nullopt);
95 };
96 
97 static_assert(cuda::mr::resource_with<binning_memory_resource, cuda::mr::device_accessible>,
98  "binning_memory_resource does not satisfy the cuda::mr::resource concept");
99  // end of group
101 } // namespace mr
102 } // namespace RMM_NAMESPACE
Allocates memory from upstream resources associated with bin sizes.
Definition: binning_memory_resource.hpp:31
binning_memory_resource(cuda::mr::any_resource< cuda::mr::device_accessible > upstream, int8_t min_size_exponent, int8_t max_size_exponent)
Construct a new binning memory resource object with a range of initial bins.
device_async_resource_ref get_upstream_resource() const noexcept
device_async_resource_ref to the upstream resource
binning_memory_resource(cuda::mr::any_resource< cuda::mr::device_accessible > upstream)
Construct a new binning memory resource object.
friend void get_property(binning_memory_resource const &, cuda::mr::device_accessible) noexcept
Enables the cuda::mr::device_accessible property.
Definition: binning_memory_resource.hpp:40
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