gtsam_points
Loading...
Searching...
No Matches
cuda_buffer.hpp
1// SPDX-License-Identifier: MIT
2// Copyright (c) 2021 Kenji Koide (k.koide@aist.go.jp)
3
4#pragma once
5
6#include <string>
7
8struct CUstream_st;
9
10namespace gtsam_points {
11
17public:
18 CUDABuffer(bool use_pinned_buffer = true);
20
27 void resize(size_t size, CUstream_st* stream);
28
33 void upload(CUstream_st* stream);
34
40 void upload(size_t size, CUstream_st* stream);
41
49 void upload(const void* buffer, size_t size, CUstream_st* stream);
50
55 void download(CUstream_st* stream);
56
63 void download(void* buffer, size_t size, CUstream_st* stream);
64
68 size_t size() const;
69
75 void* host_buffer();
76
81
82 template <typename T>
83 void upload(const T* buffer, size_t size, CUstream_st* stream) {
84 upload(reinterpret_cast<const void*>(buffer), size, stream);
85 }
86 template <typename T>
87 void download(T* buffer, size_t size, CUstream_st* stream) {
88 download(reinterpret_cast<void*>(buffer), size, stream);
89 }
90 template <typename T>
91 T* host_buffer() {
92 return reinterpret_cast<T*>(host_buffer());
93 }
94 template <typename T>
95 T* device_buffer() {
96 return reinterpret_cast<T*>(device_buffer());
97 }
98
99private:
100 const bool use_pinned_buffer;
101
102 size_t buffer_size;
103 void* h_buffer;
104 void* d_buffer;
105};
106
107} // namespace gtsam_points
Device buffer for asynchronous data transfer.
Definition cuda_buffer.hpp:16
void * host_buffer()
Pinned host buffer.
void download(CUstream_st *stream)
Download data from the device buffer to the pinned host buffer.
void upload(const void *buffer, size_t size, CUstream_st *stream)
Upload data to the device buffer. If size > buffer_size, the buffers will be resized before uploading...
void download(void *buffer, size_t size, CUstream_st *stream)
Download data from the device buffer.
void * device_buffer()
Pinned device buffer.
size_t size() const
Buffer size.
void resize(size_t size, CUstream_st *stream)
Resize the buffer size. This method only expands the device/host buffers and doesn't shrink them when...
void upload(CUstream_st *stream)
Upload data from the host pinned buffer to the device buffer.
void upload(size_t size, CUstream_st *stream)
Upload data from the host pinned buffer to the device buffer.