Loading...
Searching...
No Matches
pinned_host_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#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#include <cuda_runtime_api.h>
13
14#include <cstddef>
15
16RMM_NAMESPACE_BEGIN
17namespace mr {
18
24
32class RMM_EXPORT pinned_host_memory_resource final {
33 public:
34 pinned_host_memory_resource() = default;
35 ~pinned_host_memory_resource() = default;
36 pinned_host_memory_resource(pinned_host_memory_resource const&) =
37 default;
38 pinned_host_memory_resource(pinned_host_memory_resource&&) =
39 default;
40 pinned_host_memory_resource& operator=(pinned_host_memory_resource const&) =
41 default;
42 pinned_host_memory_resource& operator=(pinned_host_memory_resource&&) =
43 default;
44
61 [[nodiscard]] void* allocate([[maybe_unused]] cuda::stream_ref stream,
62 std::size_t bytes,
63 std::size_t alignment = rmm::CUDA_ALLOCATION_ALIGNMENT);
64
76 void deallocate([[maybe_unused]] cuda::stream_ref stream,
77 void* ptr,
78 std::size_t bytes,
79 std::size_t alignment = rmm::CUDA_ALLOCATION_ALIGNMENT) noexcept;
80
88 [[nodiscard]] void* allocate_sync(std::size_t bytes,
89 std::size_t alignment = rmm::CUDA_ALLOCATION_ALIGNMENT);
90
98 void deallocate_sync(void* ptr,
99 std::size_t bytes,
100 std::size_t alignment = rmm::CUDA_ALLOCATION_ALIGNMENT) noexcept;
101
107 RMM_CONSTEXPR_FRIEND void get_property(pinned_host_memory_resource const&,
108 cuda::mr::device_accessible) noexcept
109 {
110 }
111
117 RMM_CONSTEXPR_FRIEND void get_property(pinned_host_memory_resource const&,
118 cuda::mr::host_accessible) noexcept
119 {
120 }
121
129 [[nodiscard]] bool operator==(pinned_host_memory_resource const&) const noexcept;
130
134 [[nodiscard]] bool operator!=(pinned_host_memory_resource const&) const noexcept;
135};
136
137// static property checks
138static_assert(cuda::mr::synchronous_resource<pinned_host_memory_resource>);
139static_assert(cuda::mr::resource<pinned_host_memory_resource>);
140static_assert(
141 cuda::mr::synchronous_resource_with<pinned_host_memory_resource, cuda::mr::device_accessible>);
142static_assert(
143 cuda::mr::synchronous_resource_with<pinned_host_memory_resource, cuda::mr::host_accessible>);
144static_assert(cuda::mr::resource_with<pinned_host_memory_resource, cuda::mr::device_accessible>);
145static_assert(cuda::mr::resource_with<pinned_host_memory_resource, cuda::mr::host_accessible>);
146 // end of group
148} // namespace mr
149RMM_NAMESPACE_END
bool operator==(pinned_host_memory_resource const &) const noexcept
Compare this resource to another.
bool operator!=(pinned_host_memory_resource const &) const noexcept
Compare this resource to another.
pinned_host_memory_resource(pinned_host_memory_resource &&)=default
Default move constructor.
pinned_host_memory_resource & operator=(pinned_host_memory_resource const &)=default
Default copy assignment operator.
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_sync(std::size_t bytes, std::size_t alignment=rmm::CUDA_ALLOCATION_ALIGNMENT)
Allocates pinned host memory of size at least bytes bytes synchronously.
friend void get_property(pinned_host_memory_resource const &, cuda::mr::host_accessible) noexcept
Enables the cuda::mr::host_accessible property.
Definition pinned_host_memory_resource.hpp:117
void * allocate(cuda::stream_ref stream, std::size_t bytes, std::size_t alignment=rmm::CUDA_ALLOCATION_ALIGNMENT)
Allocates pinned host memory of size at least bytes bytes.
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.
pinned_host_memory_resource(pinned_host_memory_resource const &)=default
Default copy constructor.
pinned_host_memory_resource & operator=(pinned_host_memory_resource &&)=default
Default move assignment operator.
friend void get_property(pinned_host_memory_resource const &, cuda::mr::device_accessible) noexcept
Enables the cuda::mr::device_accessible property.
Definition pinned_host_memory_resource.hpp:107