MUDA
Loading...
Searching...
No Matches
device_buffer.h
Go to the documentation of this file.
1/*****************************************************************/
11#pragma once
12#include <cuda.h>
13#include <cuda_runtime.h>
14#include <cuda_runtime_api.h>
15#include <vector>
16#include <muda/viewer/dense.h>
18
19namespace muda
20{
21class NDReshaper;
22
23template <typename T>
24class DeviceVector;
25
26template <typename T>
27class HostVector;
28
29
44template <typename T>
46{
47 private:
48 friend class BufferLaunch;
49 friend class NDReshaper;
50
51 size_t m_size = 0;
52 size_t m_capacity = 0;
53 T* m_data = nullptr;
54
55 public:
56 using value_type = T;
57
58 DeviceBuffer(size_t n);
60
61 DeviceBuffer(const DeviceBuffer<T>& other);
62 DeviceBuffer(DeviceBuffer&& other) MUDA_NOEXCEPT;
63 DeviceBuffer& operator=(const DeviceBuffer<T>& other);
64 DeviceBuffer& operator=(DeviceBuffer<T>&& other);
65
67 DeviceBuffer(const std::vector<T>& host);
68 DeviceBuffer& operator=(CBufferView<T> other);
69 DeviceBuffer& operator=(const std::vector<T>& other);
70
71 void copy_to(std::vector<T>& host) const;
72 void copy_from(const std::vector<T>& host);
73
74 void resize(size_t new_size);
75 void resize(size_t new_size, const T& value);
76 void reserve(size_t new_capacity);
77 void clear();
78 void shrink_to_fit();
79 void fill(const T& v);
80
81 Dense1D<T> viewer() MUDA_NOEXCEPT;
82 CDense1D<T> cviewer() const MUDA_NOEXCEPT;
83
84 BufferView<T> view(size_t offset, size_t size = ~0) MUDA_NOEXCEPT;
85 BufferView<T> view() MUDA_NOEXCEPT;
86 CBufferView<T> view(size_t offset, size_t size = ~0) const MUDA_NOEXCEPT;
87 CBufferView<T> view() const MUDA_NOEXCEPT;
88 operator BufferView<T>() MUDA_NOEXCEPT { return view(); }
89 operator CBufferView<T>() const MUDA_NOEXCEPT { return view(); }
90
92
93 auto size() const MUDA_NOEXCEPT { return m_size; }
94 auto capacity() const MUDA_NOEXCEPT { return m_capacity; }
95 T* data() MUDA_NOEXCEPT { return m_data; }
96 const T* data() const MUDA_NOEXCEPT { return m_data; }
97};
98} // namespace muda
99
100#include "details/device_buffer.inl"
A view interface for any array-like liner memory, which can be constructed from DeviceBuffer/DeviceVe...
Definition buffer_launch.h:13
Definition buffer_view.h:24
Definition dense_1d.h:27
A std::vector like wrapper of cuda device memory, allows user to:
Definition device_buffer.h:46
Definition nd_reshaper.h:16