Loading [MathJax]/jax/output/HTML-CSS/config.js
cuML C++ API  23.12
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
gpu.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023, 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 #include <cuda_runtime_api.h>
22 #include <rmm/device_buffer.hpp>
23 #include <type_traits>
24 
25 namespace raft_proto {
26 namespace detail {
27 template <typename T>
29  // TODO(wphicks): Assess need for buffers of const T
30  using value_type = std::remove_const_t<T>;
31  owning_buffer() : data_{} {}
32 
34  std::size_t size,
35  cudaStream_t stream) noexcept(false)
36  : data_{[&device_id, &size, &stream]() {
37  auto device_context = device_setter{device_id};
38  return rmm::device_buffer{size * sizeof(value_type), rmm::cuda_stream_view{stream}};
39  }()}
40  {
41  }
42 
43  auto* get() const { return reinterpret_cast<T*>(data_.data()); }
44 
45  private:
46  mutable rmm::device_buffer data_;
47 };
48 } // namespace detail
49 } // namespace raft_proto
Definition: buffer.hpp:33
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:30
owning_buffer(device_id< device_type::gpu > device_id, std::size_t size, cudaStream_t stream) noexcept(false)
Definition: gpu.hpp:33
Definition: base.hpp:26