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-2024, 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 #include <utility>
25 
26 namespace RMM_NAMESPACE {
27 namespace mr {
39  public:
40  new_delete_resource() = default;
41  ~new_delete_resource() override = default;
45  default;
47  default;
48 
49  private:
62  void* do_allocate(std::size_t bytes,
63  std::size_t alignment = rmm::RMM_DEFAULT_HOST_ALIGNMENT) override
64  {
65  // If the requested alignment isn't supported, use default
66  alignment =
68 
69  return rmm::detail::aligned_host_allocate(
70  bytes, alignment, [](std::size_t size) { return ::operator new(size); });
71  }
72 
86  void do_deallocate(void* ptr,
87  std::size_t bytes,
88  std::size_t alignment = rmm::RMM_DEFAULT_HOST_ALIGNMENT) override
89  {
90  rmm::detail::aligned_host_deallocate(
91  ptr, bytes, alignment, [](void* ptr) { ::operator delete(ptr); });
92  }
93 };
94  // end of group
96 } // namespace mr
97 } // namespace RMM_NAMESPACE
Base class for host memory allocation.
Definition: host_memory_resource.hpp:58
A host_memory_resource that uses the global operator new and operator delete to allocate host memory.
Definition: new_delete_resource.hpp:38
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