Loading...
Searching...
No Matches
managed_memory_resource.hpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: Copyright (c) 2019-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3 * SPDX-License-Identifier: Apache-2.0
4 */
5#pragma once
6
7#include <rmm/aligned.hpp>
8#include <rmm/detail/export.hpp>
9
10#include <cuda/memory_resource>
11#include <cuda/stream>
12
13#include <cstddef>
14
15RMM_NAMESPACE_BEGIN
16namespace mr {
25class RMM_EXPORT managed_memory_resource final {
26 public:
27 managed_memory_resource() = default;
28 ~managed_memory_resource() = default;
29 managed_memory_resource(managed_memory_resource const&) = default;
30 managed_memory_resource(managed_memory_resource&&) = default;
31 managed_memory_resource& operator=(managed_memory_resource const&) =
32 default;
33 managed_memory_resource& operator=(managed_memory_resource&&) =
34 default;
35
48 [[nodiscard]] void* allocate([[maybe_unused]] cuda::stream_ref stream,
49 std::size_t bytes,
50 std::size_t alignment = rmm::CUDA_ALLOCATION_ALIGNMENT);
51
63 void deallocate([[maybe_unused]] cuda::stream_ref stream,
64 void* ptr,
65 std::size_t bytes,
66 std::size_t alignment = rmm::CUDA_ALLOCATION_ALIGNMENT) noexcept;
67
75 [[nodiscard]] void* allocate_sync(std::size_t bytes,
76 std::size_t alignment = rmm::CUDA_ALLOCATION_ALIGNMENT);
77
85 void deallocate_sync(void* ptr,
86 std::size_t bytes,
87 std::size_t alignment = rmm::CUDA_ALLOCATION_ALIGNMENT) noexcept;
88
94 RMM_CONSTEXPR_FRIEND void get_property(managed_memory_resource const&,
95 cuda::mr::device_accessible) noexcept
96 {
97 }
98
104 RMM_CONSTEXPR_FRIEND void get_property(managed_memory_resource const&,
105 cuda::mr::host_accessible) noexcept
106 {
107 }
108
116 [[nodiscard]] bool operator==(managed_memory_resource const&) const noexcept;
117
121 [[nodiscard]] bool operator!=(managed_memory_resource const&) const noexcept;
122};
123
124// static property checks
125static_assert(cuda::mr::synchronous_resource<managed_memory_resource>);
126static_assert(cuda::mr::resource<managed_memory_resource>);
127static_assert(
128 cuda::mr::synchronous_resource_with<managed_memory_resource, cuda::mr::device_accessible>);
129static_assert(
130 cuda::mr::synchronous_resource_with<managed_memory_resource, cuda::mr::host_accessible>);
131static_assert(cuda::mr::resource_with<managed_memory_resource, cuda::mr::device_accessible>);
132static_assert(cuda::mr::resource_with<managed_memory_resource, cuda::mr::host_accessible>);
133 // end of group
135} // namespace mr
136RMM_NAMESPACE_END
void * allocate_sync(std::size_t bytes, std::size_t alignment=rmm::CUDA_ALLOCATION_ALIGNMENT)
Allocates memory of size at least bytes synchronously.
managed_memory_resource(managed_memory_resource &&)=default
Default move constructor.
managed_memory_resource & operator=(managed_memory_resource const &)=default
Default copy assignment operator.
bool operator==(managed_memory_resource const &) const noexcept
Compare this resource to another.
friend void get_property(managed_memory_resource const &, cuda::mr::host_accessible) noexcept
Enables the cuda::mr::host_accessible property.
Definition managed_memory_resource.hpp:104
void deallocate(cuda::stream_ref stream, void *ptr, std::size_t bytes, std::size_t alignment=rmm::CUDA_ALLOCATION_ALIGNMENT) noexcept
Deallocate memory pointed to by ptr.
void * allocate(cuda::stream_ref stream, std::size_t bytes, std::size_t alignment=rmm::CUDA_ALLOCATION_ALIGNMENT)
Allocates memory of size at least bytes.
friend void get_property(managed_memory_resource const &, cuda::mr::device_accessible) noexcept
Enables the cuda::mr::device_accessible property.
Definition managed_memory_resource.hpp:94
void deallocate_sync(void *ptr, std::size_t bytes, std::size_t alignment=rmm::CUDA_ALLOCATION_ALIGNMENT) noexcept
Deallocate memory pointed to by ptr synchronously.
bool operator!=(managed_memory_resource const &) const noexcept
Compare this resource to another.
managed_memory_resource & operator=(managed_memory_resource &&)=default
Default move assignment operator.
managed_memory_resource(managed_memory_resource const &)=default
Default copy constructor.