host_memory_resource.hpp
1 
5 #pragma once
6 
7 #include <cstddef>
8 #include <cstdlib>
9 #include <cstring>
10 
11 #include <rmm/aligned.hpp>
12 #include <rmm/cuda_stream_view.hpp>
13 #include <rmm/resource_ref.hpp>
14 
15 #include <rapidsmpf/error.hpp>
16 
17 namespace rapidsmpf {
18 
33  public:
34  HostMemoryResource() = default;
35  ~HostMemoryResource() = default;
36 
39 
43 
47 
57  void* allocate_sync(std::size_t, std::size_t) {
58  RAPIDSMPF_FAIL(
59  "only async stream-ordered allocation must be used in RapidsMPF",
60  std::invalid_argument
61  );
62  }
63 
69  void deallocate_sync(void*, std::size_t, std::size_t) {
70  RAPIDSMPF_FAIL(
71  "only async stream-ordered allocation must be used in RapidsMPF",
72  std::invalid_argument
73  );
74  }
75 
87  void* allocate(
88  rmm::cuda_stream_view stream,
89  std::size_t size,
90  std::size_t alignment = rmm::CUDA_ALLOCATION_ALIGNMENT
91  );
92 
105  rmm::cuda_stream_view stream,
106  void* ptr,
107  std::size_t size,
108  std::size_t alignment = rmm::CUDA_ALLOCATION_ALIGNMENT
109  ) noexcept;
110 
120  [[nodiscard]] bool operator==(
121  [[maybe_unused]] HostMemoryResource const& other
122  ) const noexcept {
123  return true;
124  }
125 
127  [[nodiscard]] bool operator!=(
128  [[maybe_unused]] HostMemoryResource const& other
129  ) const noexcept {
130  return false;
131  }
132 
138  friend void get_property(
139  HostMemoryResource const&, cuda::mr::host_accessible
140  ) noexcept {}
141 };
142 
143 static_assert(cuda::mr::resource<HostMemoryResource>);
144 static_assert(cuda::mr::resource_with<HostMemoryResource, cuda::mr::host_accessible>);
145 static_assert(!cuda::mr::resource_with<HostMemoryResource, cuda::mr::device_accessible>);
146 
147 } // namespace rapidsmpf
Host memory resource using standard CPU allocation.
void * allocate(rmm::cuda_stream_view stream, std::size_t size, std::size_t alignment=rmm::CUDA_ALLOCATION_ALIGNMENT)
Allocates host memory associated with a CUDA stream.
bool operator!=([[maybe_unused]] HostMemoryResource const &other) const noexcept
Compares this resource to another resource.
HostMemoryResource & operator=(HostMemoryResource const &)=default
Copy assignment.
void * allocate_sync(std::size_t, std::size_t)
Synchronously allocates host memory is disabled.
HostMemoryResource & operator=(HostMemoryResource &&)=default
Move assignment.
void deallocate_sync(void *, std::size_t, std::size_t)
Synchronously deallocates host memory is disabled.
void deallocate(rmm::cuda_stream_view stream, void *ptr, std::size_t size, std::size_t alignment=rmm::CUDA_ALLOCATION_ALIGNMENT) noexcept
Deallocates host memory associated with a CUDA stream.
HostMemoryResource(HostMemoryResource &&)=default
Movable.
bool operator==([[maybe_unused]] HostMemoryResource const &other) const noexcept
Compares this resource to another resource.
friend void get_property(HostMemoryResource const &, cuda::mr::host_accessible) noexcept
Enables the cuda::mr::host_accessible property.
HostMemoryResource(HostMemoryResource const &)=default
Copyable.
static constexpr std::size_t CUDA_ALLOCATION_ALIGNMENT
RAPIDS Multi-Processor interfaces.
Definition: backend.hpp:14