11 #ifndef CUBBYFLOW_CUDA_STD_VECTOR_IMPL_HPP 12 #define CUBBYFLOW_CUDA_STD_VECTOR_IMPL_HPP 14 #ifdef CUBBYFLOW_USE_CUDA 23 CUDAStdVector<T>::CUDAStdVector(
size_t n,
const ValueType& initVal)
25 ResizeUninitialized(n);
26 CUDAFill(m_ptr, n, initVal);
31 CUDAStdVector<T>::CUDAStdVector(
const std::vector<T, A>& other)
32 : CUDAStdVector{ other.size() }
38 CUDAStdVector<T>::CUDAStdVector(
const CUDAStdVector& other)
39 : CUDAStdVector{ other.Size() }
45 CUDAStdVector<T>::CUDAStdVector(CUDAStdVector&& other) noexcept
47 *
this = std::move(other);
51 CUDAStdVector<T>::~CUDAStdVector()
58 CUDAStdVector<T>& CUDAStdVector<T>::operator=(
const std::vector<T, A>& other)
65 CUDAStdVector<T>& CUDAStdVector<T>::operator=(
const CUDAStdVector& other)
72 CUDAStdVector<T>& CUDAStdVector<T>::operator=(CUDAStdVector&& other) noexcept
81 typename CUDAStdVector<T>::Pointer CUDAStdVector<T>::data()
87 typename CUDAStdVector<T>::ConstPointer CUDAStdVector<T>::data()
const 93 size_t CUDAStdVector<T>::Size()
const 100 __device__
typename CUDAStdVector<T>::Reference CUDAStdVector<T>::At(
size_t i)
105 template <
typename T>
106 __device__
typename CUDAStdVector<T>::ConstReference CUDAStdVector<T>::At(
112 template <
typename T>
113 typename CUDAStdVector<T>::ReferenceType CUDAStdVector<T>::At(
size_t i)
115 ReferenceType r(
m_ptr + i);
119 template <
typename T>
120 T CUDAStdVector<T>::At(
size_t i)
const 123 CUDACopyDeviceToHost(
m_ptr + i, 1, &tmp);
128 template <
typename T>
129 void CUDAStdVector<T>::Clear()
131 if (
m_ptr !=
nullptr)
133 CUBBYFLOW_CUDA_CHECK(cudaFree(
m_ptr));
140 template <
typename T>
146 template <
typename T>
147 void 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);
155 template <
typename T>
156 void CUDAStdVector<T>::ResizeUninitialized(
size_t n)
160 CUBBYFLOW_CUDA_CHECK(cudaMalloc(&
m_ptr, n *
sizeof(T)));
164 template <
typename T>
165 void CUDAStdVector<T>::Swap(CUDAStdVector& other)
167 std::swap(
m_ptr, other.m_ptr);
168 std::swap(
m_size, other.m_size);
171 template <
typename T>
172 void CUDAStdVector<T>::PushBack(
const ValueType& val)
174 CUDAStdVector newBuffer;
175 newBuffer.ResizeUninitialized(
m_size + 1);
178 CUDACopyHostToDevice(&val, 1, newBuffer.m_ptr +
m_size);
182 template <
typename T>
183 void CUDAStdVector<T>::Append(
const ValueType& val)
188 template <
typename T>
189 void CUDAStdVector<T>::Append(
const CUDAStdVector& other)
191 CUDAStdVector newBuffer;
192 newBuffer.ResizeUninitialized(
m_size + other.m_size);
195 CUDACopy(other.m_ptr, other.m_size, newBuffer.m_ptr +
m_size);
199 template <
typename T>
200 template <
typename A>
201 void CUDAStdVector<T>::CopyFrom(
const std::vector<T, A>& other)
203 if (
m_size == other.size())
209 CUDAStdVector newBuffer(other);
214 template <
typename T>
215 void CUDAStdVector<T>::CopyFrom(
const CUDAStdVector& other)
217 if (
m_size == other.Size())
219 CUDACopyDeviceToDevice(other.data(),
m_size,
m_ptr);
223 CUDAStdVector newBuffer(other);
228 template <
typename T>
229 template <
typename A>
230 void CUDAStdVector<T>::CopyTo(std::vector<T, A>& other)
237 template <
typename T>
238 typename CUDAStdVector<T>::Reference CUDAStdVector<T>::operator[](
size_t i)
243 template <
typename T>
244 typename CUDAStdVector<T>::ConstReference CUDAStdVector<T>::operator[](
250 template <
typename T>
251 typename CUDAStdVector<T>::ReferenceType CUDAStdVector<T>::operator[](
size_t i)
256 template <
typename T>
257 T CUDAStdVector<T>::operator[](
size_t i)
const T ValueType
Definition: ArrayBase.hpp:23
Pointer m_ptr
Definition: ArrayBase.hpp:124
Vector< size_t, N > m_size
Definition: ArrayBase.hpp:125
Definition: pybind11Utils.hpp:20
void Fill(ArrayView< T, N > a, const Vector< size_t, N > &begin, const Vector< size_t, N > &end, const T &val)
Definition: ArrayUtils-Impl.hpp:19
Reference At(size_t i)
Definition: ArrayBase-Impl.hpp:138