25 m_size = other.m_size;
26 m_capacity = other.m_capacity;
27 m_data = other.m_data;
30 other.m_data =
nullptr;
39 m_size = other.m_size;
40 m_capacity = other.m_capacity;
41 m_data = other.m_data;
44 other.m_data =
nullptr;
53 void copy_to(std::vector<T>& vec, cudaStream_t stream =
nullptr)
const
56 checkCudaErrors(cudaMemcpyAsync(
57 vec.data(), m_data, m_size *
sizeof(T), cudaMemcpyDeviceToHost, stream));
60 void copy_from(
TempBuffer<T>& other, cudaStream_t stream =
nullptr)
63 checkCudaErrors(cudaMemcpyAsync(
64 m_data, other.data(), other.size() *
sizeof(T), cudaMemcpyDeviceToDevice, stream));
67 void copy_from(
const std::vector<T>& vec, cudaStream_t stream =
nullptr)
70 checkCudaErrors(cudaMemcpyAsync(
71 m_data, vec.data(), vec.size() *
sizeof(T), cudaMemcpyHostToDevice, stream));
74 TempBuffer(
const std::vector<T>& vec) { copy_from(vec); }
76 TempBuffer& operator=(
const std::vector<T>& vec)
82 void reserve(
size_t new_cap, cudaStream_t stream =
nullptr)
84 if(new_cap <= m_capacity)
88 T* new_data =
nullptr;
89 checkCudaErrors(cudaMalloc(&new_data, new_cap *
sizeof(T)));
92 checkCudaErrors(cudaFree(m_data));
98 void resize(
size_t size, cudaStream_t stream =
nullptr)
100 if(size <= m_capacity)
105 reserve(size, stream);
115 checkCudaErrors(cudaFree(m_data));
120 auto size()
const noexcept {
return m_size; }
121 auto data()
const noexcept {
return m_data; }
122 auto capacity()
const noexcept {
return m_capacity; }
126 size_t m_capacity = 0;