All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
new_delete_resource.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020-2025, NVIDIA CORPORATION.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #pragma once
17 
18 #include <rmm/aligned.hpp>
19 #include <rmm/detail/aligned.hpp>
20 #include <rmm/detail/export.hpp>
22 
23 #include <cstddef>
24 
25 namespace RMM_NAMESPACE {
26 namespace mr {
38  public:
39  new_delete_resource() = default;
40  ~new_delete_resource() override = default;
44  default;
46  default;
47 
48  private:
61  void* do_allocate(std::size_t bytes,
62  std::size_t alignment = rmm::RMM_DEFAULT_HOST_ALIGNMENT) override
63  {
64  // If the requested alignment isn't supported, use default
65  alignment =
67 
68  return rmm::detail::aligned_host_allocate(
69  bytes, alignment, [](std::size_t size) { return ::operator new(size); });
70  }
71 
85  void do_deallocate(void* ptr,
86  std::size_t bytes,
87  std::size_t alignment = rmm::RMM_DEFAULT_HOST_ALIGNMENT) override
88  {
89  rmm::detail::aligned_host_deallocate(
90  ptr, bytes, alignment, [](void* ptr) { ::operator delete(ptr); });
91  }
92 };
93  // end of group
95 } // namespace mr
96 } // namespace RMM_NAMESPACE
Base class for host memory allocation.
Definition: host_memory_resource.hpp:57
A host_memory_resource that uses the global operator new and operator delete to allocate host memory.
Definition: new_delete_resource.hpp:37
new_delete_resource & operator=(new_delete_resource &&)=default
Default move assignment operator.
new_delete_resource(new_delete_resource &&)=default
Default move constructor.
new_delete_resource(new_delete_resource const &)=default
Default copy constructor.
new_delete_resource & operator=(new_delete_resource const &)=default
Default copy assignment operator.
static constexpr std::size_t RMM_DEFAULT_HOST_ALIGNMENT
Default alignment used for host memory allocated by RMM.
Definition: aligned.hpp:37
constexpr bool is_supported_alignment(std::size_t alignment) noexcept
Returns whether or not alignment is a valid memory alignment.
Definition: aligned.hpp:64