1 //============================================================================
2 //  Copyright (c) Kitware, Inc.
3 //  All rights reserved.
4 //  See LICENSE.txt for details.
5 //
6 //  This software is distributed WITHOUT ANY WARRANTY; without even
7 //  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 //  PURPOSE.  See the above copyright notice for more information.
9 //============================================================================
10 #ifndef vtk_m_exec_ExecutionWholeArray_h
11 #define vtk_m_exec_ExecutionWholeArray_h
12 
13 #include <vtkm/cont/ArrayHandle.h>
14 #include <vtkm/cont/DeviceAdapter.h>
15 
16 #include <vtkm/Deprecated.h>
17 
18 namespace vtkm
19 {
20 namespace exec
21 {
22 
23 /// The following classes have been sort of deprecated and are meant to be used
24 /// internally only. Please use the \c WholeArrayIn, \c WholeArrayOut, and
25 /// \c WholeArrayInOut \c ControlSignature tags instead.
26 
27 /// \c ExecutionWholeArray is an execution object that allows an array handle
28 /// content to be a parameter in an execution environment
29 /// function. This can be used to allow worklets to have a shared search
30 /// structure.
31 ///
32 template <typename T, typename StorageTag, typename... MaybeDevice>
33 class ExecutionWholeArray;
34 
35 template <typename T, typename StorageTag>
36 class ExecutionWholeArray<T, StorageTag>
37 {
38 public:
39   using ValueType = T;
40   using HandleType = vtkm::cont::ArrayHandle<T, StorageTag>;
41   using PortalType = typename HandleType::WritePortalType;
42 
43   VTKM_CONT
ExecutionWholeArray()44   ExecutionWholeArray()
45     : Portal()
46   {
47   }
48 
49   VTKM_CONT
ExecutionWholeArray(HandleType & handle,vtkm::cont::DeviceAdapterId device,vtkm::cont::Token & token)50   ExecutionWholeArray(HandleType& handle,
51                       vtkm::cont::DeviceAdapterId device,
52                       vtkm::cont::Token& token)
53     : Portal(handle.PrepareForInPlace(device, token))
54   {
55   }
56 
57   VTKM_CONT
ExecutionWholeArray(HandleType & handle,vtkm::Id length,vtkm::cont::DeviceAdapterId device,vtkm::cont::Token & token)58   ExecutionWholeArray(HandleType& handle,
59                       vtkm::Id length,
60                       vtkm::cont::DeviceAdapterId device,
61                       vtkm::cont::Token& token)
62     : Portal(handle.PrepareForOutput(length, device, token))
63   {
64   }
65 
66   VTKM_EXEC
GetNumberOfValues()67   vtkm::Id GetNumberOfValues() const { return this->Portal.GetNumberOfValues(); }
68 
69   VTKM_EXEC
Get(vtkm::Id index)70   T Get(vtkm::Id index) const { return this->Portal.Get(index); }
71 
72   VTKM_EXEC
73   T operator[](vtkm::Id index) const { return this->Portal.Get(index); }
74 
75   VTKM_EXEC
Set(vtkm::Id index,const T & t)76   void Set(vtkm::Id index, const T& t) const { this->Portal.Set(index, t); }
77 
78   VTKM_EXEC
GetPortal()79   const PortalType& GetPortal() const { return this->Portal; }
80 
81 private:
82   PortalType Portal;
83 };
84 
85 template <typename T, typename StorageTag, typename Device>
86 class VTKM_DEPRECATED(1.6, "ExecutionWholeArray no longer uses Device template parameter.")
87   ExecutionWholeArray<T, StorageTag, Device> : public ExecutionWholeArray<T, StorageTag>
88 {
89   using Superclass = ExecutionWholeArray<T, StorageTag>;
90   using HandleType = typename Superclass::HandleType;
91 
92 public:
93   using Superclass::Superclass;
94 
ExecutionWholeArray(HandleType & handle)95   VTKM_CONT ExecutionWholeArray(HandleType& handle)
96     : Superclass(handle, Device{}, vtkm::cont::Token{})
97   {
98   }
99 
100   VTKM_CONT
ExecutionWholeArray(HandleType & handle,vtkm::Id length)101   ExecutionWholeArray(HandleType& handle, vtkm::Id length)
102     : Superclass(handle, length, Device{}, vtkm::cont::Token{})
103   {
104   }
105 
106   VTKM_CONT
ExecutionWholeArray(HandleType & handle,vtkm::cont::Token & token)107   ExecutionWholeArray(HandleType& handle, vtkm::cont::Token& token)
108     : Superclass(handle, Device{}, token)
109   {
110   }
111 
112   VTKM_CONT
ExecutionWholeArray(HandleType & handle,vtkm::Id length,vtkm::cont::Token & token)113   ExecutionWholeArray(HandleType& handle, vtkm::Id length, vtkm::cont::Token& token)
114     : Superclass(handle, length, Device{}, token)
115   {
116   }
117 };
118 
119 /// \c ExecutionWholeArrayConst is an execution object that allows an array handle
120 /// content to be a parameter in an execution environment
121 /// function. This can be used to allow worklets to have a shared search
122 /// structure
123 ///
124 template <typename T, typename StorageTag, typename... MaybeDevice>
125 class ExecutionWholeArrayConst;
126 
127 template <typename T, typename StorageTag>
128 class ExecutionWholeArrayConst<T, StorageTag>
129 {
130 public:
131   using ValueType = T;
132   using HandleType = vtkm::cont::ArrayHandle<T, StorageTag>;
133   using PortalType = typename HandleType::ReadPortalType;
134 
135   VTKM_CONT
ExecutionWholeArrayConst()136   ExecutionWholeArrayConst()
137     : Portal()
138   {
139   }
140 
141   VTKM_CONT
ExecutionWholeArrayConst(const HandleType & handle,vtkm::cont::DeviceAdapterId device,vtkm::cont::Token & token)142   ExecutionWholeArrayConst(const HandleType& handle,
143                            vtkm::cont::DeviceAdapterId device,
144                            vtkm::cont::Token& token)
145     : Portal(handle.PrepareForInput(device, token))
146   {
147   }
148 
149   VTKM_EXEC
GetNumberOfValues()150   vtkm::Id GetNumberOfValues() const { return this->Portal.GetNumberOfValues(); }
151 
152   VTKM_EXEC
Get(vtkm::Id index)153   T Get(vtkm::Id index) const { return this->Portal.Get(index); }
154 
155   VTKM_EXEC
156   T operator[](vtkm::Id index) const { return this->Portal.Get(index); }
157 
158   VTKM_EXEC
GetPortal()159   const PortalType& GetPortal() const { return this->Portal; }
160 
161 private:
162   PortalType Portal;
163 };
164 
165 template <typename T, typename StorageTag, typename Device>
166 class VTKM_DEPRECATED(1.6, "ExecutionWholeArray no longer uses Device template parameter.")
167   ExecutionWholeArrayConst<T, StorageTag, Device> : public ExecutionWholeArrayConst<T, StorageTag>
168 {
169   using Superclass = ExecutionWholeArrayConst<T, StorageTag>;
170   using HandleType = typename Superclass::HandleType;
171 
172 public:
173   using Superclass::Superclass;
174 
ExecutionWholeArrayConst(HandleType & handle)175   VTKM_CONT ExecutionWholeArrayConst(HandleType& handle)
176     : Superclass(handle, Device{}, vtkm::cont::Token{})
177   {
178   }
179 
180   VTKM_CONT
ExecutionWholeArrayConst(HandleType & handle,vtkm::cont::Token & token)181   ExecutionWholeArrayConst(HandleType& handle, vtkm::cont::Token& token)
182     : Superclass(handle, Device{}, token)
183   {
184   }
185 };
186 
187 
188 }
189 } // namespace vtkm::exec
190 
191 #endif //vtk_m_exec_ExecutionWholeArray_h
192