gpu.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023-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
21 
22 #include <rmm/device_buffer.hpp>
23 
24 #include <cuda_runtime_api.h>
25 
26 #include <type_traits>
27 
28 namespace raft_proto {
29 namespace detail {
30 template <typename T>
32  // TODO(wphicks): Assess need for buffers of const T
33  using value_type = std::remove_const_t<T>;
34  owning_buffer() : data_{} {}
35 
37  std::size_t size,
38  cudaStream_t stream) noexcept(false)
39  : data_{[&device_id, &size, &stream]() {
40  auto device_context = device_setter{device_id};
41  return rmm::device_buffer{size * sizeof(value_type), rmm::cuda_stream_view{stream}};
42  }()}
43  {
44  }
45 
46  auto* get() const { return reinterpret_cast<T*>(data_.data()); }
47 
48  private:
49  mutable rmm::device_buffer data_;
50 };
51 } // namespace detail
52 } // namespace raft_proto
Definition: buffer.hpp:35
device_type
Definition: device_type.hpp:18
Definition: base.hpp:22
Definition: base.hpp:25
std::remove_const_t< T > value_type
Definition: gpu.hpp:33
owning_buffer(device_id< device_type::gpu > device_id, std::size_t size, cudaStream_t stream) noexcept(false)
Definition: gpu.hpp:36
Definition: base.hpp:27