VTK-m  1.6
ExecutionObjectBase.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_ExecutionObjectBase_h
11 #define vtk_m_cont_ExecutionObjectBase_h
12 
13 #include <vtkm/Deprecated.h>
14 #include <vtkm/Types.h>
15 
16 #include <vtkm/cont/Token.h>
17 
19 
20 namespace vtkm
21 {
22 namespace cont
23 {
24 
33 {
34 };
35 
36 namespace internal
37 {
38 
39 namespace detail
40 {
41 
42 struct CheckPrepareForExecution
43 {
44  template <typename T>
45  static auto check(T* p) -> decltype(p->PrepareForExecution(vtkm::cont::DeviceAdapterTagSerial{},
46  std::declval<vtkm::cont::Token&>()),
47  std::true_type());
48 
49  template <typename T>
50  static auto check(...) -> std::false_type;
51 };
52 
53 struct CheckPrepareForExecutionDeprecated
54 {
56  template <typename T>
57  static auto check(T* p)
58  -> decltype(p->PrepareForExecution(vtkm::cont::DeviceAdapterTagSerial{}), std::true_type());
60 
61  template <typename T>
62  static auto check(...) -> std::false_type;
63 };
64 
65 } // namespace detail
66 
67 template <typename T>
68 using IsExecutionObjectBase =
69  typename std::is_base_of<vtkm::cont::ExecutionObjectBase, typename std::decay<T>::type>::type;
70 
71 template <typename T>
72 struct HasPrepareForExecution
73  : decltype(detail::CheckPrepareForExecution::check<typename std::decay<T>::type>(nullptr))
74 {
75 };
76 
77 template <typename T>
78 struct HasPrepareForExecutionDeprecated
79  : decltype(
80  detail::CheckPrepareForExecutionDeprecated::check<typename std::decay<T>::type>(nullptr))
81 {
82 };
83 
86 #define VTKM_IS_EXECUTION_OBJECT(execObject) \
87  static_assert(::vtkm::cont::internal::IsExecutionObjectBase<execObject>::value, \
88  "Provided type is not a subclass of vtkm::cont::ExecutionObjectBase."); \
89  static_assert(::vtkm::cont::internal::HasPrepareForExecution<execObject>::value || \
90  ::vtkm::cont::internal::HasPrepareForExecutionDeprecated<execObject>::value, \
91  "Provided type does not have requisite PrepareForExecution method.")
92 
101 template <typename T, typename Device>
102 VTKM_CONT auto CallPrepareForExecution(T&& execObject, Device device, vtkm::cont::Token& token)
103  -> decltype(execObject.PrepareForExecution(device, token))
104 {
107 
108  return execObject.PrepareForExecution(device, token);
109 }
110 
111 template <typename T>
112 VTKM_CONT auto CallPrepareForExecution(T&& execObject,
114  vtkm::cont::Token& token)
115  -> decltype(execObject.PrepareForExecution(device, token))
116 {
118 
119  return execObject.PrepareForExecution(device, token);
120 }
122 
123 // If you get a deprecation warning at this function, it means that an ExecutionObject is using the
124 // old style PrepareForExecution. Update its PrepareForExecution method to accept both a device and
125 // a token.
126 //
127 // Developer note: the third template argument, TokenType, is expected to be a vtkm::cont::Token
128 // (which is ignored). The reason why it is a template argument instead of just the type expected
129 // is so that ExecObjects that implement both versions of PrepareForExecution (for backward
130 // compatibility) will match the non-deprecated version instead of being ambiguous.
131 template <typename T, typename Device, typename TokenType>
133  1.6,
134  "ExecutionObjects now require a PrepareForExecution that takes a vtkm::cont::Token object. "
135  "PrepareForExecution(Device) is deprecated. Implement PrepareForExecution(Device, "
136  "Token).") auto CallPrepareForExecution(T&& execObject, Device device, TokenType&)
137  -> decltype(execObject.PrepareForExecution(device))
138 {
142  (std::is_same<vtkm::cont::Token, typename std::decay<TokenType>::type>::value));
143 
144  return execObject.PrepareForExecution(device);
145 }
146 
154 template <typename ExecutionObject, typename Device = vtkm::cont::DeviceAdapterId>
155 using ExecutionObjectType = decltype(CallPrepareForExecution(std::declval<ExecutionObject>(),
156  std::declval<Device>(),
157  std::declval<vtkm::cont::Token&>()));
158 
159 } // namespace internal
160 }
161 } // namespace vtkm::cont
162 
163 #endif //vtk_m_cont_ExecutionObjectBase_h
vtkm::cont::VTKM_DEPRECATED
struct VTKM_DEPRECATED(1.6, "Use vtkm::ColorSpace.") ColorSpace
Definition: cont/ColorTable.h:36
vtkm
VTKM_NO_DEPRECATED_VIRTUAL.
Definition: Algorithms.h:23
Types.h
VTKM_DEPRECATED_SUPPRESS_END
#define VTKM_DEPRECATED_SUPPRESS_END
Definition: Deprecated.h:123
DeviceAdapterTagSerial.h
vtkm::cont::Token
A token to hold the scope of an ArrayHandle or other object.
Definition: Token.h:35
VTKM_STATIC_ASSERT
#define VTKM_STATIC_ASSERT(condition)
Definition: StaticAssert.h:16
VTKM_IS_EXECUTION_OBJECT
#define VTKM_IS_EXECUTION_OBJECT(execObject)
Checks that the argument is a proper execution object.
Definition: ExecutionObjectBase.h:86
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
VTKM_DEPRECATED_SUPPRESS_BEGIN
#define VTKM_DEPRECATED_SUPPRESS_BEGIN
Definition: Deprecated.h:122
vtkm::cont::ExecutionObjectBase
Base ExecutionObjectBase for execution objects to inherit from so that you can use an arbitrary objec...
Definition: ExecutionObjectBase.h:32
vtkm::cont::DeviceAdapterId
Definition: DeviceAdapterTag.h:52
Deprecated.h
Token.h
VTKM_IS_DEVICE_ADAPTER_TAG
#define VTKM_IS_DEVICE_ADAPTER_TAG(tag)
Checks that the argument is a proper device adapter tag.
Definition: DeviceAdapterTag.h:164