Loading...
Searching...
No Matches
system_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/cuda_device.hpp>
9#include <rmm/detail/export.hpp>
10
11#include <cuda/memory_resource>
12#include <cuda/stream>
13#include <cuda_runtime_api.h>
14
15#include <cstddef>
16
17RMM_NAMESPACE_BEGIN
18namespace mr {
19
20namespace detail {
27RMM_EXPORT bool is_system_memory_supported(cuda_device_id device_id);
28} // namespace detail
29
57class RMM_EXPORT system_memory_resource final {
58 public:
59 system_memory_resource();
60 ~system_memory_resource() = default;
61 system_memory_resource(system_memory_resource const&) = default;
62 system_memory_resource(system_memory_resource&&) = default;
63 system_memory_resource& operator=(system_memory_resource const&) =
64 default;
65 system_memory_resource& operator=(system_memory_resource&&) =
66 default;
67
80 [[nodiscard]] void* allocate([[maybe_unused]] cuda::stream_ref stream,
81 std::size_t bytes,
82 std::size_t alignment = rmm::CUDA_ALLOCATION_ALIGNMENT);
83
95 void deallocate(cuda::stream_ref stream,
96 void* ptr,
97 std::size_t bytes,
98 std::size_t alignment = rmm::CUDA_ALLOCATION_ALIGNMENT) noexcept;
99
107 [[nodiscard]] void* allocate_sync(std::size_t bytes,
108 std::size_t alignment = rmm::CUDA_ALLOCATION_ALIGNMENT);
109
117 void deallocate_sync(void* ptr,
118 std::size_t bytes,
119 std::size_t alignment = rmm::CUDA_ALLOCATION_ALIGNMENT) noexcept;
120
126 RMM_CONSTEXPR_FRIEND void get_property(system_memory_resource const&,
127 cuda::mr::device_accessible) noexcept
128 {
129 }
130
136 RMM_CONSTEXPR_FRIEND void get_property(system_memory_resource const&,
137 cuda::mr::host_accessible) noexcept
138 {
139 }
140
148 [[nodiscard]] bool operator==(system_memory_resource const&) const noexcept;
149
153 [[nodiscard]] bool operator!=(system_memory_resource const&) const noexcept;
154};
155
156// static property checks
157static_assert(cuda::mr::synchronous_resource<system_memory_resource>);
158static_assert(cuda::mr::resource<system_memory_resource>);
159static_assert(
160 cuda::mr::synchronous_resource_with<system_memory_resource, cuda::mr::device_accessible>);
161static_assert(
162 cuda::mr::synchronous_resource_with<system_memory_resource, cuda::mr::host_accessible>);
163static_assert(cuda::mr::resource_with<system_memory_resource, cuda::mr::device_accessible>);
164static_assert(cuda::mr::resource_with<system_memory_resource, cuda::mr::host_accessible>); // end of group
166} // namespace mr
167RMM_NAMESPACE_END
system_memory_resource(system_memory_resource const &)=default
Default copy constructor.
system_memory_resource & operator=(system_memory_resource const &)=default
Default copy assignment operator.
system_memory_resource & operator=(system_memory_resource &&)=default
Default move assignment operator.
system_memory_resource(system_memory_resource &&)=default
Default copy constructor.
void * allocate_sync(std::size_t bytes, std::size_t alignment=rmm::CUDA_ALLOCATION_ALIGNMENT)
Allocates memory of size at least bytes synchronously.
bool operator==(system_memory_resource const &) const noexcept
Compare this resource to another.
friend void get_property(system_memory_resource const &, cuda::mr::device_accessible) noexcept
Enables the cuda::mr::device_accessible property.
Definition system_memory_resource.hpp:126
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.
bool operator!=(system_memory_resource const &) const noexcept
Compare this resource to another.
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.
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.
friend void get_property(system_memory_resource const &, cuda::mr::host_accessible) noexcept
Enables the cuda::mr::host_accessible property.
Definition system_memory_resource.hpp:136
Strong type for a CUDA device identifier.
Definition cuda_device.hpp:27
bool is_system_memory_supported(cuda_device_id device_id)
Check if system allocated memory (SAM) is supported on the specified device.