fixed_size_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/fixed_size_memory_resource_impl.hpp>
9 #include <rmm/resource_ref.hpp>
10 
11 #include <cuda/memory_resource>
12 
13 #include <cstddef>
14 
15 namespace RMM_NAMESPACE {
16 namespace mr {
32  : public cuda::mr::shared_resource<detail::fixed_size_memory_resource_impl> {
33  using shared_base = cuda::mr::shared_resource<detail::fixed_size_memory_resource_impl>;
34 
35  public:
41  RMM_CONSTEXPR_FRIEND void get_property(fixed_size_memory_resource const&,
42  cuda::mr::device_accessible) noexcept
43  {
44  }
45 
46  static constexpr std::size_t default_block_size = 1 << 20;
47 
50  static constexpr std::size_t default_blocks_to_preallocate = 128;
51 
64  cuda::mr::any_resource<cuda::mr::device_accessible> upstream,
65  // NOLINTNEXTLINE bugprone-easily-swappable-parameters
66  std::size_t block_size = default_block_size,
67  std::size_t blocks_to_preallocate = default_blocks_to_preallocate);
68 
69  ~fixed_size_memory_resource() = default;
70 
74  [[nodiscard]] device_async_resource_ref get_upstream_resource() const noexcept;
75 
81  [[nodiscard]] std::size_t get_block_size() const noexcept;
82 };
83 
84 static_assert(cuda::mr::resource_with<fixed_size_memory_resource, cuda::mr::device_accessible>,
85  "fixed_size_memory_resource does not satisfy the cuda::mr::resource concept");
86  // end of group
88 } // namespace mr
89 } // namespace RMM_NAMESPACE
A memory resource which allocates memory blocks of a single fixed size.
Definition: fixed_size_memory_resource.hpp:32
friend void get_property(fixed_size_memory_resource const &, cuda::mr::device_accessible) noexcept
Enables the cuda::mr::device_accessible property.
Definition: fixed_size_memory_resource.hpp:41
fixed_size_memory_resource(cuda::mr::any_resource< cuda::mr::device_accessible > upstream, std::size_t block_size=default_block_size, std::size_t blocks_to_preallocate=default_blocks_to_preallocate)
Construct a new fixed_size_memory_resource that allocates memory from upstream.
device_async_resource_ref get_upstream_resource() const noexcept
device_async_resource_ref to the upstream resource
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