thread_safe_resource_adaptor.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/thread_safe_resource_adaptor_impl.hpp>
9 #include <rmm/resource_ref.hpp>
10 
11 #include <cuda/memory_resource>
12 
13 #include <cstddef>
14 #include <mutex>
15 
16 namespace RMM_NAMESPACE {
17 namespace mr {
34  : public cuda::mr::shared_resource<detail::thread_safe_resource_adaptor_impl> {
35  using shared_base = cuda::mr::shared_resource<detail::thread_safe_resource_adaptor_impl>;
36 
37  public:
38  using lock_t = std::lock_guard<std::mutex>;
39 
43  RMM_CONSTEXPR_FRIEND void get_property(thread_safe_resource_adaptor const&,
44  cuda::mr::device_accessible) noexcept
45  {
46  }
47 
55  cuda::mr::any_resource<cuda::mr::device_accessible> upstream);
56 
57  ~thread_safe_resource_adaptor() = default;
58 
62  [[nodiscard]] device_async_resource_ref get_upstream_resource() const noexcept;
63 };
64 
65 static_assert(cuda::mr::resource_with<thread_safe_resource_adaptor, cuda::mr::device_accessible>,
66  "thread_safe_resource_adaptor does not satisfy the cuda::mr::resource concept");
67  // end of group
69 } // namespace mr
70 } // namespace RMM_NAMESPACE
Resource that adapts an upstream resource to be thread safe.
Definition: thread_safe_resource_adaptor.hpp:34
friend void get_property(thread_safe_resource_adaptor const &, cuda::mr::device_accessible) noexcept
Enables the cuda::mr::device_accessible property.
Definition: thread_safe_resource_adaptor.hpp:43
device_async_resource_ref get_upstream_resource() const noexcept
rmm::device_async_resource_ref to the upstream resource
thread_safe_resource_adaptor(cuda::mr::any_resource< cuda::mr::device_accessible > upstream)
Construct a new thread safe resource adaptor using upstream to satisfy allocation requests.
std::lock_guard< std::mutex > lock_t
Type of lock used to synchronize access.
Definition: thread_safe_resource_adaptor.hpp:38
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