memory_resource.hpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2024-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 
6 #pragma once
7 
8 #include <rmm/cuda_device.hpp>
10 #include <rmm/resource_ref.hpp>
11 
12 #include <cuda/memory_resource>
13 
14 #include <concepts>
15 #include <utility>
16 
22 namespace cudf {
23 
35 {
37 }
38 
48  public:
59  template <typename Resource>
60  memory_resources(Resource&& output_mr)
61 #ifndef DOXYGEN_SHOULD_SKIP_THIS
62  requires std::constructible_from<rmm::device_async_resource_ref, Resource&&>
63 #endif
64  : _output_mr{std::forward<Resource>(output_mr)},
66  {
67  }
68 
79  template <typename OutputResource, typename TemporaryResource>
80  memory_resources(OutputResource&& output_mr, TemporaryResource&& temporary_mr)
81 #ifndef DOXYGEN_SHOULD_SKIP_THIS
82  requires(std::constructible_from<rmm::device_async_resource_ref, OutputResource &&> and
83  std::constructible_from<rmm::device_async_resource_ref, TemporaryResource &&>)
84 #endif
85  : _output_mr{std::forward<OutputResource>(output_mr)},
86  _temporary_mr{std::forward<TemporaryResource>(temporary_mr)}
87  {
88  }
89 
95  [[nodiscard]] rmm::device_async_resource_ref get_output_mr() const noexcept { return _output_mr; }
96 
102  [[nodiscard]] rmm::device_async_resource_ref get_temporary_mr() const noexcept
103  {
104  return _temporary_mr;
105  }
106 
107  private:
109  rmm::device_async_resource_ref _temporary_mr;
110 };
111 
118 inline cuda::mr::any_resource<cuda::mr::device_accessible> set_current_device_resource(
119  cuda::mr::any_resource<cuda::mr::device_accessible> mr)
120 {
121  return rmm::mr::set_current_device_resource(std::move(mr));
122 }
123 
135 [[deprecated("Use set_current_device_resource instead.")]] //
136 inline cuda::mr::any_resource<cuda::mr::device_accessible>
138 {
139  return set_current_device_resource(cuda::mr::any_resource<cuda::mr::device_accessible>{mr});
140 }
141 
147 inline cuda::mr::any_resource<cuda::mr::device_accessible> reset_current_device_resource()
148 {
150 }
151 
159 [[deprecated("Use reset_current_device_resource instead.")]] //
160 inline cuda::mr::any_resource<cuda::mr::device_accessible>
162 {
164 }
165  // end of group
167 } // namespace cudf
Non-owning references to the memory resources used by a cuDF operation.
memory_resources(Resource &&output_mr)
Construct with an explicit output resource and capture the current resource for temporaries.
memory_resources(OutputResource &&output_mr, TemporaryResource &&temporary_mr)
Construct with explicit output and temporary resources.
rmm::device_async_resource_ref get_temporary_mr() const noexcept
Return the resource used for intermediate allocations.
rmm::device_async_resource_ref get_output_mr() const noexcept
Return the resource used for allocations returned to the caller.
cuda::mr::any_resource< cuda::mr::device_accessible > set_current_device_resource_ref(rmm::device_async_resource_ref mr)
Set the current device memory resource reference.
cuda::mr::any_resource< cuda::mr::device_accessible > reset_current_device_resource()
Reset the current device memory resource to the initial resource.
cuda::mr::any_resource< cuda::mr::device_accessible > set_current_device_resource(cuda::mr::any_resource< cuda::mr::device_accessible > mr)
Set the current device memory resource.
rmm::device_async_resource_ref get_current_device_resource_ref()
Get the current device memory resource reference.
cuda::mr::any_resource< cuda::mr::device_accessible > reset_current_device_resource_ref()
Reset the current device memory resource reference to the initial resource.
device_async_resource_ref get_current_device_resource_ref()
cuda::mr::any_resource< cuda::mr::device_accessible > reset_current_device_resource()
cuda::mr::resource_ref< cuda::mr::device_accessible > device_async_resource_ref
cuda::mr::any_resource< cuda::mr::device_accessible > set_current_device_resource(cuda::mr::any_resource< cuda::mr::device_accessible > new_resource)
cuDF interfaces
Definition: host_udf.hpp:26
requires(is_index_type< IndexType >() &&is_relationally_comparable< KeyType, KeyType >()) struct dictionary_element
A type tag to specify that a column should be treated as a dictionary column.