CUDAStdArray.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_STD_ARRAY_HPP
12 #define CUBBYFLOW_CUDA_STD_ARRAY_HPP
13 
14 #ifdef CUBBYFLOW_USE_CUDA
15 
16 #include <Core/Matrix/Matrix.hpp>
17 
18 #include <array>
19 
20 namespace CubbyFlow
21 {
22 template <typename T, size_t N>
23 class CUDAStdArray
24 {
25  public:
26  using ValueType = T;
27  using Reference = T&;
28  using ConstReference = const T&;
29  using Pointer = T*;
30  using ConstPointer = const T*;
31  using Iterator = Pointer;
32  using ConstIterator = ConstPointer;
33 
34  CUBBYFLOW_CUDA_HOST_DEVICE CUDAStdArray();
35 
36  template <typename... Args>
37  CUBBYFLOW_CUDA_HOST_DEVICE CUDAStdArray(ConstReference first, Args... rest);
38 
39  CUBBYFLOW_CUDA_HOST CUDAStdArray(const std::array<T, N>& other);
40 
41  CUBBYFLOW_CUDA_HOST CUDAStdArray(const Vector<T, N>& other);
42 
43  ~CUDAStdArray() = default;
44 
45  CUBBYFLOW_CUDA_HOST_DEVICE CUDAStdArray(const CUDAStdArray& other);
46 
47  CUBBYFLOW_CUDA_HOST_DEVICE CUDAStdArray(CUDAStdArray&& other) noexcept;
48 
49  CUBBYFLOW_CUDA_HOST_DEVICE CUDAStdArray& operator=(
50  const CUDAStdArray& other);
51 
52  CUBBYFLOW_CUDA_HOST_DEVICE CUDAStdArray& operator=(
53  CUDAStdArray&& other) noexcept;
54 
55  CUBBYFLOW_CUDA_HOST_DEVICE void Fill(ConstReference val);
56 
57  CUBBYFLOW_CUDA_HOST Vector<T, N> ToVector() const;
58 
59  CUBBYFLOW_CUDA_HOST_DEVICE Reference operator[](size_t i);
60 
61  CUBBYFLOW_CUDA_HOST_DEVICE ConstReference operator[](size_t i) const;
62 
63  CUBBYFLOW_CUDA_HOST_DEVICE bool operator==(const CUDAStdArray& other) const;
64 
65  CUBBYFLOW_CUDA_HOST_DEVICE bool operator!=(const CUDAStdArray& other) const;
66 
67  private:
68  template <typename... Args>
69  CUBBYFLOW_CUDA_HOST_DEVICE void SetAt(size_t i, ConstReference first,
70  Args... rest);
71 
72  template <typename... Args>
73  CUBBYFLOW_CUDA_HOST_DEVICE void SetAt(size_t i, ConstReference first);
74 
75  T m_elements[N];
76 };
77 } // namespace CubbyFlow
78 
80 
81 #endif
82 
83 #endif
constexpr std::enable_if_t< IsMatrixSizeStatic< Rows, Cols >), bool > operator==(const MatrixExpression< T, Rows, Cols, M1 > &a, const MatrixExpression< T, Rows, Cols, M2 > &b)
Definition: Matrix-Impl.hpp:1408
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
bool operator!=(const MatrixExpression< T, R1, C1, M1 > &a, const MatrixExpression< T, R2, C2, M2 > &b)
Definition: Matrix-Impl.hpp:1443