host_memory_resource.hpp
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 
18 #include <cstddef>
19 #include <utility>
20 
21 namespace rmm::mr {
22 
48  public:
49  host_memory_resource() = default;
50  virtual ~host_memory_resource() = default;
52  host_memory_resource& operator=(host_memory_resource const&) = default;
53  host_memory_resource(host_memory_resource&&) noexcept = default;
54  host_memory_resource& operator=(host_memory_resource&&) noexcept = default;
55 
68  void* allocate(std::size_t bytes, std::size_t alignment = alignof(std::max_align_t))
69  {
70  return do_allocate(bytes, alignment);
71  }
72 
89  void deallocate(void* ptr, std::size_t bytes, std::size_t alignment = alignof(std::max_align_t))
90  {
91  do_deallocate(ptr, bytes, alignment);
92  }
93 
106  [[nodiscard]] bool is_equal(host_memory_resource const& other) const noexcept
107  {
108  return do_is_equal(other);
109  }
110 
111  private:
124  virtual void* do_allocate(std::size_t bytes,
125  std::size_t alignment = alignof(std::max_align_t)) = 0;
126 
142  virtual void do_deallocate(void* ptr,
143  std::size_t bytes,
144  std::size_t alignment = alignof(std::max_align_t)) = 0;
145 
158  [[nodiscard]] virtual bool do_is_equal(host_memory_resource const& other) const noexcept
159  {
160  return this == &other;
161  }
162 };
163 } // namespace rmm::mr
rmm::mr::host_memory_resource
Base class for host memory allocation.
Definition: host_memory_resource.hpp:47
rmm::mr::host_memory_resource::is_equal
bool is_equal(host_memory_resource const &other) const noexcept
Compare this resource to another.
Definition: host_memory_resource.hpp:106
rmm::mr::host_memory_resource::allocate
void * allocate(std::size_t bytes, std::size_t alignment=alignof(std::max_align_t))
Allocates memory on the host of size at least bytes bytes.
Definition: host_memory_resource.hpp:68
rmm::mr::host_memory_resource::deallocate
void deallocate(void *ptr, std::size_t bytes, std::size_t alignment=alignof(std::max_align_t))
Deallocate memory pointed to by ptr.
Definition: host_memory_resource.hpp:89