CUDAArray.hpp
Go to the documentation of this file.
1 // This code is based on Jet framework.
2 // Copyright (c) 2018 Doyub Kim
3 // CubbyFlow is voxel-based fluid simulation engine for computer games.
4 // Copyright (c) 2020 CubbyFlow Team
5 // Core Part: Chris Ohk, Junwoo Hwang, Jihong Sin, Seungwoo Yoo
6 // AI Part: Dongheon Cho, Minseo Kim
7 // We are making my contributions/submissions to this project solely in our
8 // personal capacity and are not conveying any rights to any intellectual
9 // property of any third parties.
10 
11 #ifndef CUBBYFLOW_CUDA_ARRAY_HPP
12 #define CUBBYFLOW_CUDA_ARRAY_HPP
13 
14 #ifdef CUBBYFLOW_USE_CUDA
15 
16 #include <Core/Array/Array.hpp>
18 
19 namespace CubbyFlow
20 {
21 template <typename T, size_t N>
22 class CUDAArrayView;
23 
24 template <typename T, size_t N>
25 class CUDAArray final : public CUDAArrayBase<T, N, Array<T, N>>
26 {
27  using Base = CUDAArrayBase<T, N, Array<T, N>>;
28  using Base::m_size;
29  using Base::SetPtrAndSize;
30  using Base::SwapPtrAndSize;
31 
32  public:
33  using Base::At;
34  using Base::ClearPtrAndSize;
35  using Base::data;
36  using Base::Length;
37 
38  CUDAArray();
39 
40  CUDAArray(const CUDAStdArray<size_t, N>& size, const T& initVal = T{});
41 
42  template <typename... Args>
43  CUDAArray(size_t nx, Args... args);
44 
45  CUDAArray(NestedInitializerListsT<T, N> lst);
46 
47  template <size_t M = N>
48  CUDAArray(const std::enable_if_t<(M == 1), std::vector<T>>& vec);
49 
50  template <typename OtherDerived>
51  CUDAArray(const ArrayBase<T, N, OtherDerived>& other);
52 
53  template <typename OtherDerived>
54  CUDAArray(const CUDAArrayBase<T, N, OtherDerived>& other);
55 
56  CUDAArray(const CUDAArray& other);
57 
58  CUDAArray(CUDAArray&& other) noexcept;
59 
60  ~CUDAArray() = default;
61 
62  template <size_t M = N>
63  CUDAArray& operator=(const std::enable_if_t<(M == 1), std::vector<T>>& vec);
64 
65  template <typename OtherDerived>
66  CUDAArray& operator=(const ArrayBase<T, N, OtherDerived>& other);
67 
68  template <typename OtherDerived>
69  CUDAArray& operator=(const ArrayBase<const T, N, OtherDerived>& other);
70 
71  template <typename OtherDerived>
72  CUDAArray& operator=(const CUDAArrayBase<T, N, OtherDerived>& other);
73 
74  template <typename OtherDerived>
75  CUDAArray& operator=(const CUDAArrayBase<const T, N, OtherDerived>& other);
76 
77  CUDAArray& operator=(const CUDAArray& other);
78 
79  CUDAArray& operator=(CUDAArray&& other) noexcept;
80 
81  template <typename A, size_t M = N>
82  std::enable_if_t<(M == 1), void> CopyFrom(const std::vector<T, A>& vec);
83 
84  template <typename OtherDerived>
85  void CopyFrom(const ArrayBase<T, N, OtherDerived>& other);
86 
87  template <typename OtherDerived>
88  void CopyFrom(const ArrayBase<const T, N, OtherDerived>& other);
89 
90  template <typename OtherDerived>
91  void CopyFrom(const CUDAArrayBase<T, N, OtherDerived>& other);
92 
93  template <typename OtherDerived>
94  void CopyFrom(const CUDAArrayBase<const T, N, OtherDerived>& other);
95 
96  template <typename A, size_t M = N>
97  std::enable_if_t<(M == 1), void> CopyTo(std::vector<T, A>& vec);
98 
99  void CopyTo(Array<T, N>& other);
100 
101  void CopyTo(ArrayView<T, N>& other);
102 
103  void CopyTo(CUDAArray<T, N>& other);
104 
105  void CopyTo(CUDAArrayView<T, N>& other);
106 
107  void Fill(const T& val);
108 
109  void Resize(CUDAStdArray<size_t, N> size_, const T& initVal = T{});
110 
111  template <typename... Args>
112  void Resize(size_t nx, Args... args);
113 
114  template <size_t M = N>
115  std::enable_if_t<(M == 1), void> Append(const T& val);
116 
117  template <typename A, size_t M = N>
118  std::enable_if_t<(M == 1), void> Append(const std::vector<T, A>& extra);
119 
120  template <typename OtherDerived, size_t M = N>
121  std::enable_if_t<(M == 1), void> Append(
122  const ArrayBase<T, N, OtherDerived>& extra);
123 
124  template <typename OtherDerived, size_t M = N>
125  std::enable_if_t<(M == 1), void> Append(
126  const CUDAArrayBase<T, N, OtherDerived>& extra);
127 
128  void Clear();
129 
130  void Swap(CUDAArray& other);
131 
132  CUDAArrayView<T, N> View();
133 
134  CUDAArrayView<const T, N> View() const;
135 
136  private:
137  CUDAStdVector<T> m_data;
138 };
139 
140 template <class T>
141 using CUDAArray1 = CUDAArray<T, 1>;
142 
143 template <class T>
144 using CUDAArray2 = CUDAArray<T, 2>;
145 
146 template <class T>
147 using CUDAArray3 = CUDAArray<T, 3>;
148 
149 template <class T>
150 using CUDAArray4 = CUDAArray<T, 4>;
151 } // namespace CubbyFlow
152 
154 
155 #endif
156 
157 #endif
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