Viskores  1.0
Invoker.h
Go to the documentation of this file.
1 //============================================================================
2 // The contents of this file are covered by the Viskores license. See
3 // LICENSE.txt for details.
4 //
5 // By contributing to this file, all contributors agree to the Developer
6 // Certificate of Origin Version 1.1 (DCO 1.1) as stated in DCO.txt.
7 //============================================================================
8 
9 //============================================================================
10 // Copyright (c) Kitware, Inc.
11 // All rights reserved.
12 // See LICENSE.txt for details.
13 //
14 // This software is distributed WITHOUT ANY WARRANTY; without even
15 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 // PURPOSE. See the above copyright notice for more information.
17 //============================================================================
18 #ifndef viskores_cont_Invoker_h
19 #define viskores_cont_Invoker_h
20 
23 
25 
26 namespace viskores
27 {
28 namespace cont
29 {
30 
31 namespace detail
32 {
33 template <typename T>
34 using scatter_or_mask = std::integral_constant<bool,
35  viskores::worklet::internal::is_mask<T>::value ||
36  viskores::worklet::internal::is_scatter<T>::value>;
37 }
38 
49 struct Invoker
50 {
51 
55  explicit Invoker()
57  {
58  }
59 
64  : DeviceId(device)
65  {
66  }
67 
72  template <typename Worklet,
73  typename T,
74  typename... Args,
75  typename std::enable_if<detail::scatter_or_mask<T>::value, int>::type* = nullptr>
76  inline void operator()(Worklet&& worklet, T&& scatterOrMask, Args&&... args) const
77  {
78  using WorkletType = viskores::internal::remove_cvref<Worklet>;
79  using DispatcherType = typename WorkletType::template Dispatcher<WorkletType>;
80 
81  DispatcherType dispatcher(worklet, scatterOrMask);
82  dispatcher.SetDevice(this->DeviceId);
83  dispatcher.Invoke(std::forward<Args>(args)...);
84  }
85 
91  template <
92  typename Worklet,
93  typename T,
94  typename U,
95  typename... Args,
96  typename std::enable_if<detail::scatter_or_mask<T>::value && detail::scatter_or_mask<U>::value,
97  int>::type* = nullptr>
98  inline void operator()(Worklet&& worklet,
99  T&& scatterOrMaskA,
100  U&& scatterOrMaskB,
101  Args&&... args) const
102  {
103  using WorkletType = viskores::internal::remove_cvref<Worklet>;
104  using DispatcherType = typename WorkletType::template Dispatcher<WorkletType>;
105 
106  DispatcherType dispatcher(worklet, scatterOrMaskA, scatterOrMaskB);
107  dispatcher.SetDevice(this->DeviceId);
108  dispatcher.Invoke(std::forward<Args>(args)...);
109  }
110 
115  template <typename Worklet,
116  typename T,
117  typename... Args,
118  typename std::enable_if<!detail::scatter_or_mask<T>::value, int>::type* = nullptr>
119  inline void operator()(Worklet&& worklet, T&& t, Args&&... args) const
120  {
121  using WorkletType = viskores::internal::remove_cvref<Worklet>;
122  using DispatcherType = typename WorkletType::template Dispatcher<WorkletType>;
123 
124  DispatcherType dispatcher(worklet);
125  dispatcher.SetDevice(this->DeviceId);
126  dispatcher.Invoke(std::forward<T>(t), std::forward<Args>(args)...);
127  }
128 
132 
133 private:
135 };
136 }
137 }
138 
139 #endif
viskores::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:98
MaskBase.h
viskores::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:76
ScatterBase.h
viskores::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:119
viskores::cont::DeviceAdapterTagAny
Tag for a device adapter used to specify that any device may be used for an operation.
Definition: DeviceAdapterTag.h:194
viskores::cont::Invoker::DeviceId
viskores::cont::DeviceAdapterId DeviceId
Definition: Invoker.h:134
viskores::cont::Invoker::GetDevice
viskores::cont::DeviceAdapterId GetDevice() const
Get the device adapter that this Invoker is bound too.
Definition: Invoker.h:131
viskores
Groups connected points that have the same field value.
Definition: Atomic.h:27
TryExecute.h
viskores::cont::DeviceAdapterId
An object used to specify a device.
Definition: DeviceAdapterTag.h:66
viskores::cont::Invoker::Invoker
Invoker(viskores::cont::DeviceAdapterId device)
Constructs an Invoker that will try to launch worklets only on the provided device adapter.
Definition: Invoker.h:63
viskores::cont::Invoker
Allows launching any worklet without a dispatcher.
Definition: Invoker.h:49
viskores::cont::Invoker::Invoker
Invoker()
Constructs an Invoker that will try to launch worklets on any device that is enabled.
Definition: Invoker.h:55