Loading...
Searching...
No Matches
cuda_async_view_memory_resource.hpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: Copyright (c) 2021-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 {
23
28class RMM_EXPORT cuda_async_view_memory_resource final {
29 public:
41
47 [[nodiscard]] cudaMemPool_t pool_handle() const noexcept;
48
52 default;
54 default;
56 default;
58 default;
59
70 [[nodiscard]] void* allocate(cuda::stream_ref stream,
71 std::size_t bytes,
72 std::size_t alignment = rmm::CUDA_ALLOCATION_ALIGNMENT);
73
83 void deallocate(cuda::stream_ref stream,
84 void* ptr,
85 std::size_t bytes,
86 std::size_t alignment = rmm::CUDA_ALLOCATION_ALIGNMENT) noexcept;
87
95 [[nodiscard]] void* allocate_sync(std::size_t bytes,
96 std::size_t alignment = rmm::CUDA_ALLOCATION_ALIGNMENT);
97
105 void deallocate_sync(void* ptr,
106 std::size_t bytes,
107 std::size_t alignment = rmm::CUDA_ALLOCATION_ALIGNMENT) noexcept;
108
116 [[nodiscard]] bool operator==(cuda_async_view_memory_resource const& other) const noexcept;
117
121 [[nodiscard]] bool operator!=(cuda_async_view_memory_resource const& other) const noexcept;
122
129 RMM_CONSTEXPR_FRIEND void get_property(cuda_async_view_memory_resource const&,
130 cuda::mr::device_accessible) noexcept
131 {
132 }
133
134 private:
135 cudaMemPool_t cuda_pool_handle_{};
136};
137
138// static property checks
139static_assert(cuda::mr::synchronous_resource<cuda_async_view_memory_resource>);
140static_assert(cuda::mr::resource<cuda_async_view_memory_resource>);
141static_assert(cuda::mr::synchronous_resource_with<cuda_async_view_memory_resource,
142 cuda::mr::device_accessible>);
143static_assert(
144 cuda::mr::resource_with<cuda_async_view_memory_resource, cuda::mr::device_accessible>);
145 // end of group
147} // namespace mr
148RMM_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.
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.
cudaMemPool_t pool_handle() const noexcept
Returns the underlying native handle to the CUDA pool.
cuda_async_view_memory_resource(cudaMemPool_t pool_handle)
Constructs a cuda_async_view_memory_resource which uses an existing CUDA memory pool....
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(cuda_async_view_memory_resource const &, cuda::mr::device_accessible) noexcept
Enables the cuda::mr::device_accessible property.
Definition cuda_async_view_memory_resource.hpp:129
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.
Memory Resource classes and adaptors.
The top-level namespace containing all RMM functionality.