All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
cuda_memory_resource.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019-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/cuda_stream_view.hpp>
19 #include <rmm/detail/error.hpp>
20 #include <rmm/detail/export.hpp>
22 
23 #include <cstddef>
24 
25 namespace RMM_NAMESPACE {
26 namespace mr {
37  public:
38  cuda_memory_resource() = default;
39  ~cuda_memory_resource() override = default;
43  default;
45  default;
46 
47  private:
59  void* do_allocate(std::size_t bytes, [[maybe_unused]] cuda_stream_view stream) override
60  {
61  void* ptr{nullptr};
62  RMM_CUDA_TRY_ALLOC(cudaMalloc(&ptr, bytes));
63  return ptr;
64  }
65 
76  void do_deallocate(void* ptr,
77  [[maybe_unused]] std::size_t bytes,
78  [[maybe_unused]] cuda_stream_view stream) override
79  {
80  RMM_ASSERT_CUDA_SUCCESS(cudaFree(ptr));
81  }
82 
93  [[nodiscard]] bool do_is_equal(device_memory_resource const& other) const noexcept override
94  {
95  return dynamic_cast<cuda_memory_resource const*>(&other) != nullptr;
96  }
97 }; // end of group
99 } // namespace mr
100 } // namespace RMM_NAMESPACE
Strongly-typed non-owning wrapper for CUDA streams with default constructor.
Definition: cuda_stream_view.hpp:41
device_memory_resource derived class that uses cudaMalloc/Free for allocation/deallocation.
Definition: cuda_memory_resource.hpp:36
cuda_memory_resource(cuda_memory_resource const &)=default
Default copy constructor.
cuda_memory_resource & operator=(cuda_memory_resource const &)=default
Default copy assignment operator.
cuda_memory_resource & operator=(cuda_memory_resource &&)=default
Default move assignment operator.
cuda_memory_resource(cuda_memory_resource &&)=default
Default move constructor.
Base class for all libcudf device memory allocation.
Definition: device_memory_resource.hpp:94