Loading...
Searching...
No Matches
tracking_resource_adaptor.hpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: Copyright (c) 2020-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3 * SPDX-License-Identifier: Apache-2.0
4 */
5#pragma once
6
7#include <rmm/detail/export.hpp>
8#include <rmm/mr/detail/tracking_resource_adaptor_impl.hpp>
10
11#include <cuda/memory_resource>
12
13#include <cstddef>
14#include <map>
15#include <memory>
16#include <string>
17
18RMM_NAMESPACE_BEGIN
19namespace mr {
35 : public cuda::mr::shared_resource<detail::tracking_resource_adaptor_impl> {
36 using shared_base = cuda::mr::shared_resource<detail::tracking_resource_adaptor_impl>;
37
38 public:
40 using allocation_info = detail::tracking_resource_adaptor_impl::allocation_info;
42 using read_lock_t = detail::tracking_resource_adaptor_impl::read_lock_t;
44 using write_lock_t = detail::tracking_resource_adaptor_impl::write_lock_t;
45
49 RMM_CONSTEXPR_FRIEND void get_property(tracking_resource_adaptor const&,
50 cuda::mr::device_accessible) noexcept
51 {
52 }
53
60 tracking_resource_adaptor(cuda::mr::any_resource<cuda::mr::device_accessible> upstream,
61 bool capture_stacks = false);
62
64
68 [[nodiscard]] device_async_resource_ref get_upstream_resource() const noexcept;
69
79 [[nodiscard]] std::map<void*, allocation_info> const& get_outstanding_allocations()
80 const noexcept;
81
87 [[nodiscard]] std::size_t get_allocated_bytes() const noexcept;
88
94 [[nodiscard]] std::string get_outstanding_allocations_str() const;
95
100};
101
102static_assert(cuda::mr::resource_with<tracking_resource_adaptor, cuda::mr::device_accessible>,
103 "tracking_resource_adaptor does not satisfy the cuda::mr::resource concept");
104 // end of group
106} // namespace mr
107RMM_NAMESPACE_END
detail::tracking_resource_adaptor_impl::allocation_info allocation_info
Allocation info type (pointer, size, optional stack trace).
Definition tracking_resource_adaptor.hpp:40
void log_outstanding_allocations() const
Log any outstanding allocations via RMM_LOG_DEBUG.
std::map< void *, allocation_info > const & get_outstanding_allocations() const noexcept
Get the outstanding allocations map.
std::size_t get_allocated_bytes() const noexcept
Query the number of bytes currently allocated.
std::string get_outstanding_allocations_str() const
Gets a string describing all outstanding allocations (pointer, size, optional stack).
device_async_resource_ref get_upstream_resource() const noexcept
rmm::device_async_resource_ref to the upstream resource
detail::tracking_resource_adaptor_impl::read_lock_t read_lock_t
Shared-reader lock type used to protect the allocations map.
Definition tracking_resource_adaptor.hpp:42
friend void get_property(tracking_resource_adaptor const &, cuda::mr::device_accessible) noexcept
Enables the cuda::mr::device_accessible property.
Definition tracking_resource_adaptor.hpp:49
detail::tracking_resource_adaptor_impl::write_lock_t write_lock_t
Exclusive-writer lock type used to protect the allocations map.
Definition tracking_resource_adaptor.hpp:44
tracking_resource_adaptor(cuda::mr::any_resource< cuda::mr::device_accessible > upstream, bool capture_stacks=false)
Construct a tracking resource adaptor using upstream to satisfy allocation requests.
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
Memory Resource classes and adaptors.