RMM  23.12
RAPIDS Memory Manager
new_delete_resource.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020-2021, 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 
19 
20 #include <rmm/detail/aligned.hpp>
21 
22 #include <cstddef>
23 #include <utility>
24 
25 namespace rmm::mr {
37  public:
38  new_delete_resource() = default;
39  ~new_delete_resource() override = default;
43  default;
45  default;
46 
47  private:
60  void* do_allocate(std::size_t bytes,
61  std::size_t alignment = rmm::detail::RMM_DEFAULT_HOST_ALIGNMENT) override
62  {
63  // If the requested alignment isn't supported, use default
64  alignment = (rmm::detail::is_supported_alignment(alignment))
65  ? alignment
66  : rmm::detail::RMM_DEFAULT_HOST_ALIGNMENT;
67 
68  return rmm::detail::aligned_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::detail::RMM_DEFAULT_HOST_ALIGNMENT) override
88  {
89  rmm::detail::aligned_deallocate(
90  ptr, bytes, alignment, [](void* ptr) { ::operator delete(ptr); });
91  }
92 };
93  // end of group
95 } // namespace rmm::mr
Base class for host memory allocation.
Definition: host_memory_resource.hpp:54
A host_memory_resource that uses the global operator new and operator delete to allocate host memory.
Definition: new_delete_resource.hpp:36
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.