11#ifndef CUBBYFLOW_CUDA_STD_VECTOR_IMPL_HPP
12#define CUBBYFLOW_CUDA_STD_VECTOR_IMPL_HPP
14#ifdef CUBBYFLOW_USE_CUDA
23CUDAStdVector<T>::CUDAStdVector(
size_t n,
const ValueType&
initVal)
31CUDAStdVector<T>::CUDAStdVector(
const std::vector<T, A>&
other)
34 CUDACopyHostToDevice(other.data(), m_size, m_ptr);
38CUDAStdVector<T>::CUDAStdVector(
const CUDAStdVector& other)
39 : CUDAStdVector{ other.Size() }
41 CUDACopyDeviceToDevice(other.m_ptr, m_size, m_ptr);
45CUDAStdVector<T>::CUDAStdVector(CUDAStdVector&& other)
noexcept
47 *
this = std::move(other);
51CUDAStdVector<T>::~CUDAStdVector()
58CUDAStdVector<T>& CUDAStdVector<T>::operator=(
const std::vector<T, A>& other)
65CUDAStdVector<T>& CUDAStdVector<T>::operator=(
const CUDAStdVector& other)
72CUDAStdVector<T>& CUDAStdVector<T>::operator=(CUDAStdVector&& other)
noexcept
81typename CUDAStdVector<T>::Pointer CUDAStdVector<T>::data()
87typename CUDAStdVector<T>::ConstPointer CUDAStdVector<T>::data()
const
93size_t CUDAStdVector<T>::Size()
const
100__device__
typename CUDAStdVector<T>::Reference CUDAStdVector<T>::At(
size_t i)
106__device__
typename CUDAStdVector<T>::ConstReference CUDAStdVector<T>::At(
113typename CUDAStdVector<T>::ReferenceType CUDAStdVector<T>::At(
size_t i)
115 ReferenceType r(m_ptr + i);
120T CUDAStdVector<T>::At(
size_t i)
const
123 CUDACopyDeviceToHost(m_ptr + i, 1, &tmp);
129void CUDAStdVector<T>::Clear()
131 if (m_ptr !=
nullptr)
133 CUBBYFLOW_CUDA_CHECK(cudaFree(m_ptr));
141void CUDAStdVector<T>::Fill(
const ValueType& val)
143 CUDAFill(m_ptr, m_size, val);
147void CUDAStdVector<T>::Resize(
size_t n,
const ValueType& initVal)
149 CUDAStdVector newBuffer(n, initVal);
151 CUDACopy(m_ptr, std::min(n, m_size), newBuffer.m_ptr);
156void CUDAStdVector<T>::ResizeUninitialized(
size_t n)
160 CUBBYFLOW_CUDA_CHECK(cudaMalloc(&m_ptr, n *
sizeof(T)));
165void CUDAStdVector<T>::Swap(CUDAStdVector& other)
167 std::swap(m_ptr, other.m_ptr);
168 std::swap(m_size, other.m_size);
172void CUDAStdVector<T>::PushBack(
const ValueType& val)
174 CUDAStdVector newBuffer;
175 newBuffer.ResizeUninitialized(m_size + 1);
177 CUDACopy(m_ptr, m_size, newBuffer.m_ptr);
178 CUDACopyHostToDevice(&val, 1, newBuffer.m_ptr + m_size);
183void CUDAStdVector<T>::Append(
const ValueType& val)
189void CUDAStdVector<T>::Append(
const CUDAStdVector& other)
191 CUDAStdVector newBuffer;
192 newBuffer.ResizeUninitialized(m_size + other.m_size);
194 CUDACopy(m_ptr, m_size, newBuffer.m_ptr);
195 CUDACopy(other.m_ptr, other.m_size, newBuffer.m_ptr + m_size);
201void CUDAStdVector<T>::CopyFrom(
const std::vector<T, A>& other)
203 if (m_size == other.size())
205 CUDACopyHostToDevice(other.data(), m_size, m_ptr);
209 CUDAStdVector newBuffer(other);
215void CUDAStdVector<T>::CopyFrom(
const CUDAStdVector& other)
217 if (m_size == other.Size())
219 CUDACopyDeviceToDevice(other.data(), m_size, m_ptr);
223 CUDAStdVector newBuffer(other);
230void CUDAStdVector<T>::CopyTo(std::vector<T, A>& other)
232 other.resize(m_size);
233 CUDACopyDeviceToHost(m_ptr, m_size, other.data());
238typename CUDAStdVector<T>::Reference CUDAStdVector<T>::operator[](
size_t i)
244typename CUDAStdVector<T>::ConstReference CUDAStdVector<T>::operator[](
251typename CUDAStdVector<T>::ReferenceType CUDAStdVector<T>::operator[](
size_t i)
257T CUDAStdVector<T>::operator[](
size_t i)
const
Definition pybind11Utils.hpp:21
Matrix< T, Rows, 1 > Vector
Definition Matrix.hpp:738