CUDAArrayView.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_VIEW_HPP
12 #define CUBBYFLOW_CUDA_ARRAY_VIEW_HPP
13 
14 #ifdef CUBBYFLOW_USE_CUDA
15 
16 #include <Core/CUDA/CUDAArray.hpp>
17 
18 namespace CubbyFlow
19 {
20 template <typename T, size_t N>
21 class CUDAArrayView final : public CUDAArrayBase<T, N, CUDAArrayView<T, N>>
22 {
23  using Base = CUDAArrayBase<T, N, CUDAArrayView<T, N>>;
24  using Base::At;
25  using Base::m_size;
26  using Base::SetPtrAndSize;
27 
28  public:
29  using Base::data;
30 
31  CUBBYFLOW_CUDA_HOST_DEVICE CUDAArrayView();
32 
33  CUBBYFLOW_CUDA_HOST_DEVICE CUDAArrayView(
34  T* ptr, const CUDAStdArray<size_t, N>& size);
35 
36  template <size_t M = N>
37  CUBBYFLOW_CUDA_HOST_DEVICE CUDAArrayView(
38  typename std::enable_if<(M == 1), T>::type* ptr, size_t size);
39 
40  CUBBYFLOW_CUDA_HOST_DEVICE CUDAArrayView(CUDAArray<T, N>& other);
41 
42  CUBBYFLOW_CUDA_HOST_DEVICE CUDAArrayView(const CUDAArrayView& other);
43 
44  CUBBYFLOW_CUDA_HOST_DEVICE CUDAArrayView(CUDAArrayView&& other) noexcept;
45 
46  CUBBYFLOW_CUDA_HOST_DEVICE CUDAArrayView& operator=(
47  const CUDAArrayView& other);
48 
49  CUBBYFLOW_CUDA_HOST_DEVICE CUDAArrayView& operator=(
50  CUDAArrayView&& other) noexcept;
51 
52  CUBBYFLOW_CUDA_HOST_DEVICE void Set(CUDAArray<T, N>& other);
53 
54  CUBBYFLOW_CUDA_HOST_DEVICE void Set(const CUDAArrayView& other);
55 
56  CUBBYFLOW_CUDA_HOST void Fill(const T& val);
57 };
58 
59 template <typename T, size_t N>
60 class CUDAArrayView<const T, N> final
61  : public CUDAArrayBase<const T, N, CUDAArrayView<const T, N>>
62 {
63  using Base = CUDAArrayBase<const T, N, CUDAArrayView<const T, N>>;
64  using Base::m_size;
65  using Base::SetPtrAndSize;
66 
67  public:
68  using Base::data;
69 
70  CUBBYFLOW_CUDA_HOST_DEVICE CUDAArrayView();
71 
72  CUBBYFLOW_CUDA_HOST_DEVICE CUDAArrayView(
73  const T* ptr, const CUDAStdArray<size_t, N>& size);
74 
75  template <size_t M = N>
76  CUBBYFLOW_CUDA_HOST_DEVICE CUDAArrayView(
77  const typename std::enable_if<(M == 1), T>::type* ptr, size_t size);
78 
79  CUBBYFLOW_CUDA_HOST_DEVICE CUDAArrayView(const CUDAArray<T, N>& other);
80 
81  CUBBYFLOW_CUDA_HOST_DEVICE CUDAArrayView(const CUDAArrayView<T, N>& other);
82 
83  CUBBYFLOW_CUDA_HOST_DEVICE CUDAArrayView(const CUDAArrayView& other);
84 
85  CUBBYFLOW_CUDA_HOST_DEVICE CUDAArrayView(CUDAArrayView&&) noexcept;
86 
87  CUBBYFLOW_CUDA_HOST_DEVICE CUDAArrayView& operator=(
88  const CUDAArrayView<T, N>& other);
89 
90  CUBBYFLOW_CUDA_HOST_DEVICE CUDAArrayView& operator=(
91  const CUDAArrayView& other);
92 
93  CUBBYFLOW_CUDA_HOST_DEVICE CUDAArrayView& operator=(
94  CUDAArrayView&& other) noexcept;
95 
96  CUBBYFLOW_CUDA_HOST_DEVICE void Set(const CUDAArray<T, N>& other);
97 
98  CUBBYFLOW_CUDA_HOST_DEVICE void Set(const CUDAArrayView<T, N>& other);
99 
100  CUBBYFLOW_CUDA_HOST_DEVICE void Set(const CUDAArrayView& other);
101 };
102 
103 template <class T>
104 using CUDAArrayView1 = CUDAArrayView<T, 1>;
105 
106 template <class T>
107 using CUDAArrayView2 = CUDAArrayView<T, 2>;
108 
109 template <class T>
110 using CUDAArrayView3 = CUDAArrayView<T, 3>;
111 
112 template <class T>
113 using CUDAArrayView4 = CUDAArrayView<T, 4>;
114 
115 template <class T>
116 using ConstCUDAArrayView1 = CUDAArrayView<const T, 1>;
117 
118 template <class T>
119 using ConstCUDAArrayView2 = CUDAArrayView<const T, 2>;
120 
121 template <class T>
122 using ConstCUDAArrayView3 = CUDAArrayView<const T, 3>;
123 
124 template <class T>
125 using ConstCUDAArrayView4 = CUDAArrayView<const T, 4>;
126 } // namespace CubbyFlow
127 
128 #include <Core/CUDA/CUDAArrayView-Impl.hpp>
129 
130 #endif
131 
132 #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