11 #ifndef CUBBYFLOW_CUDA_STD_VECTOR_HPP 12 #define CUBBYFLOW_CUDA_STD_VECTOR_HPP 14 #ifdef CUBBYFLOW_USE_CUDA 23 class CUDAStdVector final
28 using ConstReference =
const T&;
29 using Pointer = ValueType*;
30 using ConstPointer =
const ValueType*;
35 CUBBYFLOW_CUDA_HOST_DEVICE ReferenceType(Pointer p) : m_ptr(p)
40 CUBBYFLOW_CUDA_HOST_DEVICE ReferenceType(
const ReferenceType& other)
46 CUBBYFLOW_CUDA_HOST_DEVICE ReferenceType(ReferenceType&& other) noexcept
47 : m_ptr(std::move(other.m_ptr))
52 ~ReferenceType() =
default;
54 CUBBYFLOW_CUDA_HOST_DEVICE ReferenceType& operator=(
55 const ReferenceType& other)
61 CUBBYFLOW_CUDA_HOST_DEVICE ReferenceType& operator=(
62 ReferenceType&& other) noexcept
64 m_ptr = std::move(other.m_ptr);
69 __device__ ReferenceType& operator=(
const ValueType& val)
75 __device__
operator ValueType()
const 80 CUBBYFLOW_CUDA_HOST ReferenceType& operator=(
const ValueType& val)
82 CUDACopyHostToDevice(&val, 1, m_ptr);
86 CUBBYFLOW_CUDA_HOST
operator ValueType()
const 88 std::remove_const_t<ValueType> tmp{};
89 CUDACopyDeviceToHost(m_ptr, 1, &tmp);
98 CUDAStdVector() =
default;
100 CUDAStdVector(
size_t n,
const ValueType& initVal = ValueType{});
102 template <
typename A>
103 CUDAStdVector(
const std::vector<T, A>& other);
105 CUDAStdVector(
const CUDAStdVector& other);
107 CUDAStdVector(CUDAStdVector&& other) noexcept;
111 template <
typename A>
112 CUDAStdVector& operator=(
const std::vector<T, A>& other);
114 CUDAStdVector& operator=(
const CUDAStdVector& other);
116 CUDAStdVector& operator=(CUDAStdVector&& other) noexcept;
120 ConstPointer data()
const;
125 __device__ Reference At(
size_t i);
127 __device__ ConstReference At(
size_t i)
const;
129 CUBBYFLOW_CUDA_HOST ReferenceType At(
size_t i);
131 CUBBYFLOW_CUDA_HOST T At(
size_t i)
const;
136 void Fill(
const ValueType& val);
138 void Resize(
size_t n,
const ValueType& initVal = ValueType{});
140 void ResizeUninitialized(
size_t n);
142 void Swap(CUDAStdVector& other);
144 void PushBack(
const ValueType& val);
146 void Append(
const ValueType& val);
148 void Append(
const CUDAStdVector& other);
150 template <
typename A>
151 void CopyFrom(
const std::vector<T, A>& other);
153 void CopyFrom(
const CUDAStdVector& other);
155 template <
typename A>
156 void CopyTo(std::vector<T, A>& other);
159 Reference operator[](
size_t i);
161 ConstReference operator[](
size_t i)
const;
163 ReferenceType operator[](
size_t i);
165 T operator[](
size_t i)
const;
169 Pointer m_ptr =
nullptr;
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