Loading...
Searching...
No Matches
CUDAArrayView-Impl.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_IMPL_HPP
12#define CUBBYFLOW_CUDA_ARRAY_VIEW_IMPL_HPP
13
14#ifdef CUBBYFLOW_USE_CUDA
15
16namespace CubbyFlow
17{
18template <typename T, size_t N>
19CUDAArrayView<T, N>::CUDAArrayView() : Base()
20{
21 // Do nothing
22}
23
24template <typename T, size_t N>
25CUDAArrayView<T, N>::CUDAArrayView(T* ptr, const CUDAStdArray<size_t, N>& size)
26 : CUDAArrayView{}
27{
28 Base::SetPtrAndSize(ptr, size);
29}
30
31template <typename T, size_t N>
32template <size_t M>
33CUDAArrayView<T, N>::CUDAArrayView(
34 typename std::enable_if<(M == 1), T>::type* ptr, size_t size)
35 : CUDAArrayView(ptr, CUDAStdArray<size_t, N>{ size })
36{
37 // Do nothing
38}
39
40template <typename T, size_t N>
41CUDAArrayView<T, N>::CUDAArrayView(CUDAArray<T, N>& other) : CUDAArrayView{}
42{
43 Set(other);
44}
45
46template <typename T, size_t N>
47CUDAArrayView<T, N>::CUDAArrayView(const CUDAArrayView& other)
48{
49 Set(other);
50}
51
52template <typename T, size_t N>
53CUDAArrayView<T, N>::CUDAArrayView(CUDAArrayView&& other) noexcept
54 : CUDAArrayView{}
55{
56 *this = std::move(other);
57}
58
59template <typename T, size_t N>
60CUDAArrayView<T, N>& CUDAArrayView<T, N>::operator=(const CUDAArrayView& other)
61{
62 Set(other);
63 return *this;
64}
65
66template <typename T, size_t N>
67CUDAArrayView<T, N>& CUDAArrayView<T, N>::operator=(
68 CUDAArrayView&& other) noexcept
69{
70 Base::SetPtrAndSize(other.data(), other.Size());
71 other.SetPtrAndSize(nullptr, CUDAStdArray<size_t, N>{});
72 return *this;
73}
74
75template <typename T, size_t N>
76void CUDAArrayView<T, N>::Set(CUDAArray<T, N>& other)
77{
78 Base::SetPtrAndSize(other.data(), other.Size());
79}
80
81template <typename T, size_t N>
82void CUDAArrayView<T, N>::Set(const CUDAArrayView& other)
83{
84 Base::SetPtrAndSize(const_cast<T*>(other.data()), other.Size());
85}
86
87template <typename T, size_t N>
88void CUDAArrayView<T, N>::Fill(const T& val)
89{
90 CUDAFill(data(), val);
91}
92
93template <typename T, size_t N>
94CUDAArrayView<const T, N>::CUDAArrayView() : Base()
95{
96 // Do nothing
97}
98
99template <typename T, size_t N>
100CUDAArrayView<const T, N>::CUDAArrayView(const T* ptr,
101 const CUDAStdArray<size_t, N>& size)
102 : CUDAArrayView{}
103{
104 Base::SetPtrAndSize(MemoryHandle(ptr), size);
105}
106
107template <typename T, size_t N>
108template <size_t M>
109CUDAArrayView<const T, N>::CUDAArrayView(
110 const typename std::enable_if<(M == 1), T>::type* ptr, size_t size)
111 : CUDAArrayView(ptr, CUDAStdArray<size_t, N>{ size })
112{
113 // Do nothing
114}
115
116template <typename T, size_t N>
117CUDAArrayView<const T, N>::CUDAArrayView(const CUDAArray<T, N>& other)
118 : CUDAArrayView{}
119{
120 Set(other);
121}
122
123template <typename T, size_t N>
124CUDAArrayView<const T, N>::CUDAArrayView(const CUDAArrayView<T, N>& other)
125{
126 Set(other);
127}
128
129template <typename T, size_t N>
130CUDAArrayView<const T, N>::CUDAArrayView(const CUDAArrayView& other)
131{
132 Set(other);
133}
134
135template <typename T, size_t N>
136CUDAArrayView<const T, N>::CUDAArrayView(CUDAArrayView&& other) noexcept
137 : CUDAArrayView{}
138{
139 *this = std::move(other);
140}
141
142template <typename T, size_t N>
143CUDAArrayView<const T, N>& CUDAArrayView<const T, N>::operator=(
144 const CUDAArrayView<T, N>& other)
145{
146 Set(other);
147 return *this;
148}
149
150template <typename T, size_t N>
151CUDAArrayView<const T, N>& CUDAArrayView<const T, N>::operator=(
152 const CUDAArrayView& other)
153{
154 Set(other);
155 return *this;
156}
157
158template <typename T, size_t N>
159CUDAArrayView<const T, N>& CUDAArrayView<const T, N>::operator=(
160 CUDAArrayView&& other) noexcept
161{
162 Base::SetPtrAndSize(other.data(), other.Size());
163 other.SetPtrAndSize(nullptr, CUDAStdArray<size_t, N>{});
164 return *this;
165}
166
167template <typename T, size_t N>
168void CUDAArrayView<const T, N>::Set(const CUDAArray<T, N>& other)
169{
170 Base::SetPtrAndSize(other.data(), other.Size());
171}
172
173template <typename T, size_t N>
174void CUDAArrayView<const T, N>::Set(const CUDAArrayView<T, N>& other)
175{
176 Base::SetPtrAndSize(other.data(), other.Size());
177}
178
179template <typename T, size_t N>
180void CUDAArrayView<const T, N>::Set(const CUDAArrayView& other)
181{
182 Base::SetPtrAndSize(other.data(), other.Size());
183}
184} // namespace CubbyFlow
185
186#endif
187
188#endif
Definition pybind11Utils.hpp:21