VTK-m  2.0
Invoker.h
Go to the documentation of this file.
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_cont_Invoker_h
11 #define vtk_m_cont_Invoker_h
12 
15 
16 #include <vtkm/cont/TryExecute.h>
17 
18 namespace vtkm
19 {
20 namespace cont
21 {
22 
23 namespace detail
24 {
25 template <typename T>
26 using scatter_or_mask = std::integral_constant<bool,
27  vtkm::worklet::internal::is_mask<T>::value ||
28  vtkm::worklet::internal::is_scatter<T>::value>;
29 }
30 
41 struct Invoker
42 {
43 
47  explicit Invoker()
48  : DeviceId(vtkm::cont::DeviceAdapterTagAny{})
49  {
50  }
51 
56  : DeviceId(device)
57  {
58  }
59 
64  template <typename Worklet,
65  typename T,
66  typename... Args,
67  typename std::enable_if<detail::scatter_or_mask<T>::value, int>::type* = nullptr>
68  inline void operator()(Worklet&& worklet, T&& scatterOrMask, Args&&... args) const
69  {
70  using WorkletType = vtkm::internal::remove_cvref<Worklet>;
71  using DispatcherType = typename WorkletType::template Dispatcher<WorkletType>;
72 
73  DispatcherType dispatcher(worklet, scatterOrMask);
74  dispatcher.SetDevice(this->DeviceId);
75  dispatcher.Invoke(std::forward<Args>(args)...);
76  }
77 
83  template <
84  typename Worklet,
85  typename T,
86  typename U,
87  typename... Args,
88  typename std::enable_if<detail::scatter_or_mask<T>::value && detail::scatter_or_mask<U>::value,
89  int>::type* = nullptr>
90  inline void operator()(Worklet&& worklet,
91  T&& scatterOrMaskA,
92  U&& scatterOrMaskB,
93  Args&&... args) const
94  {
95  using WorkletType = vtkm::internal::remove_cvref<Worklet>;
96  using DispatcherType = typename WorkletType::template Dispatcher<WorkletType>;
97 
98  DispatcherType dispatcher(worklet, scatterOrMaskA, scatterOrMaskB);
99  dispatcher.SetDevice(this->DeviceId);
100  dispatcher.Invoke(std::forward<Args>(args)...);
101  }
102 
107  template <typename Worklet,
108  typename T,
109  typename... Args,
110  typename std::enable_if<!detail::scatter_or_mask<T>::value, int>::type* = nullptr>
111  inline void operator()(Worklet&& worklet, T&& t, Args&&... args) const
112  {
113  using WorkletType = vtkm::internal::remove_cvref<Worklet>;
114  using DispatcherType = typename WorkletType::template Dispatcher<WorkletType>;
115 
116  DispatcherType dispatcher(worklet);
117  dispatcher.SetDevice(this->DeviceId);
118  dispatcher.Invoke(std::forward<T>(t), std::forward<Args>(args)...);
119  }
120 
124 
125 private:
127 };
128 }
129 }
130 
131 #endif
MaskBase.h
vtkm::cont::Invoker::operator()
void operator()(Worklet &&worklet, T &&scatterOrMask, Args &&... args) const
Launch the worklet that is provided as the first parameter.
Definition: Invoker.h:68
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
ScatterBase.h
vtkm::cont::Invoker::operator()
void operator()(Worklet &&worklet, T &&t, Args &&... args) const
Launch the worklet that is provided as the first parameter.
Definition: Invoker.h:111
vtkm::cont::Invoker::operator()
void operator()(Worklet &&worklet, T &&scatterOrMaskA, U &&scatterOrMaskB, Args &&... args) const
Launch the worklet that is provided as the first parameter.
Definition: Invoker.h:90
vtkm::cont::Invoker::Invoker
Invoker(vtkm::cont::DeviceAdapterId device)
Constructs an Invoker that will try to launch worklets only on the provided device adapter.
Definition: Invoker.h:55
TryExecute.h
vtkm::cont::Invoker
Allows launching any worklet without a dispatcher.
Definition: Invoker.h:41
vtkm::cont::Invoker::Invoker
Invoker()
Constructs an Invoker that will try to launch worklets on any device that is enabled.
Definition: Invoker.h:47
vtkm::cont::DeviceAdapterId
Definition: DeviceAdapterTag.h:52
vtkm::cont::Invoker::DeviceId
vtkm::cont::DeviceAdapterId DeviceId
Definition: Invoker.h:126
vtkm::cont::Invoker::GetDevice
vtkm::cont::DeviceAdapterId GetDevice() const
Get the device adapter that this Invoker is bound too.
Definition: Invoker.h:123