11 #ifndef CUBBYFLOW_CUDA_ARRAY_BASE_HPP 12 #define CUBBYFLOW_CUDA_ARRAY_BASE_HPP 14 #ifdef CUBBYFLOW_USE_CUDA 21 template <
typename T,
size_t N,
typename DerivedArray>
25 using Derived = DerivedArray;
27 using HostReference =
typename CUDAStdVector<T>::ReferenceType;
29 using ConstReference =
const T&;
31 using ConstPointer =
const T*;
33 CUBBYFLOW_CUDA_HOST_DEVICE
size_t Index(
size_t i)
const;
35 template <
typename... Args>
36 CUBBYFLOW_CUDA_HOST_DEVICE
size_t Index(
size_t i, Args... args)
const;
38 template <
size_t... I>
39 CUBBYFLOW_CUDA_HOST_DEVICE
size_t 40 Index(
const CUDAStdArray<size_t, N>& idx)
const;
42 CUBBYFLOW_CUDA_HOST_DEVICE T* data();
44 CUBBYFLOW_CUDA_HOST_DEVICE
const T* data()
const;
46 CUBBYFLOW_CUDA_HOST_DEVICE
const CUDAStdArray<size_t, N>& Size()
const;
48 template <
size_t M = N>
49 CUBBYFLOW_CUDA_HOST_DEVICE std::enable_if_t<(M > 0),
size_t> Width()
const;
51 template <
size_t M = N>
52 CUBBYFLOW_CUDA_HOST_DEVICE std::enable_if_t<(M > 1),
size_t> Height()
const;
54 template <
size_t M = N>
55 CUBBYFLOW_CUDA_HOST_DEVICE std::enable_if_t<(M > 2),
size_t> Depth()
const;
57 CUBBYFLOW_CUDA_HOST_DEVICE
size_t Length()
const;
60 CUBBYFLOW_CUDA_DEVICE Reference At(
size_t i);
62 CUBBYFLOW_CUDA_DEVICE ConstReference At(
size_t i)
const;
64 template <
typename... Args>
65 CUBBYFLOW_CUDA_DEVICE Reference At(
size_t i, Args... args);
67 template <
typename... Args>
68 CUBBYFLOW_CUDA_DEVICE ConstReference At(
size_t i, Args... args)
const;
70 CUBBYFLOW_CUDA_DEVICE Reference At(
const CUDAStdArray<size_t, N>& idx);
72 CUBBYFLOW_CUDA_DEVICE ConstReference
73 At(
const CUDAStdArray<size_t, N>& idx)
const;
75 CUBBYFLOW_CUDA_DEVICE Reference operator[](
size_t i);
77 CUBBYFLOW_CUDA_DEVICE ConstReference operator[](
size_t i)
const;
79 template <
typename... Args>
80 CUBBYFLOW_CUDA_DEVICE Reference operator()(
size_t i, Args... args);
82 template <
typename... Args>
83 CUBBYFLOW_CUDA_DEVICE ConstReference operator()(
size_t i,
86 CUBBYFLOW_CUDA_DEVICE Reference
87 operator()(
const CUDAStdArray<size_t, N>& idx);
89 CUBBYFLOW_CUDA_DEVICE ConstReference
90 operator()(
const CUDAStdArray<size_t, N>& idx)
const;
92 CUBBYFLOW_CUDA_HOST HostReference At(
size_t i);
94 CUBBYFLOW_CUDA_HOST ValueType At(
size_t i)
const;
96 template <
typename... Args>
97 CUBBYFLOW_CUDA_HOST HostReference At(
size_t i, Args... args);
99 template <
typename... Args>
100 CUBBYFLOW_CUDA_HOST ValueType At(
size_t i, Args... args)
const;
102 CUBBYFLOW_CUDA_HOST HostReference At(
const CUDAStdArray<size_t, N>& idx);
104 CUBBYFLOW_CUDA_HOST ValueType At(
const CUDAStdArray<size_t, N>& idx)
const;
106 CUBBYFLOW_CUDA_HOST HostReference operator[](
size_t i);
108 CUBBYFLOW_CUDA_HOST ValueType operator[](
size_t i)
const;
110 template <
typename... Args>
111 CUBBYFLOW_CUDA_HOST HostReference operator()(
size_t i, Args... args);
113 template <
typename... Args>
114 CUBBYFLOW_CUDA_HOST ValueType operator()(
size_t i, Args... args)
const;
116 CUBBYFLOW_CUDA_HOST HostReference
117 operator()(
const CUDAStdArray<size_t, N>& idx);
119 CUBBYFLOW_CUDA_HOST ValueType
120 operator()(
const CUDAStdArray<size_t, N>& idx)
const;
124 CUBBYFLOW_CUDA_HOST_DEVICE CUDAArrayBase();
126 CUBBYFLOW_CUDA_HOST_DEVICE CUDAArrayBase(
const CUDAArrayBase& other);
128 CUBBYFLOW_CUDA_HOST_DEVICE CUDAArrayBase(CUDAArrayBase&& other) noexcept;
130 ~CUDAArrayBase() =
default;
132 CUBBYFLOW_CUDA_HOST_DEVICE CUDAArrayBase& operator=(
133 const CUDAArrayBase& other);
135 CUBBYFLOW_CUDA_HOST_DEVICE CUDAArrayBase& operator=(
136 CUDAArrayBase&& other) noexcept;
138 template <
typename... Args>
139 CUBBYFLOW_CUDA_HOST_DEVICE
void SetPtrAndSize(Pointer ptr,
size_t ni,
142 CUBBYFLOW_CUDA_HOST_DEVICE
void SetPtrAndSize(Pointer data,
143 CUDAStdArray<size_t, N> size);
145 CUBBYFLOW_CUDA_HOST_DEVICE
void SwapPtrAndSize(CUDAArrayBase& other);
147 CUBBYFLOW_CUDA_HOST_DEVICE
void ClearPtrAndSize();
149 Pointer m_ptr =
nullptr;
150 CUDAStdArray<size_t, N> m_size;
153 template <
typename... Args>
154 CUBBYFLOW_CUDA_HOST_DEVICE
size_t IndexInternal(
size_t d,
size_t i,
157 CUBBYFLOW_CUDA_HOST_DEVICE
size_t IndexInternal(
size_t,
size_t i)
const;
159 template <
size_t... I>
160 CUBBYFLOW_CUDA_HOST_DEVICE
size_t IndexInternal(
161 const CUDAStdArray<size_t, N>& idx, std::index_sequence<I...>)
const;
Definition: pybind11Utils.hpp:20