VTK-m  2.2
DeviceAdapterTag.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_DeviceAdapterTag_h
11 #define vtk_m_cont_DeviceAdapterTag_h
12 
13 #include <vtkm/StaticAssert.h>
14 #include <vtkm/Types.h>
17 
19 
20 #include <string>
21 
22 #ifdef VTKM_DEVICE_ADAPTER
23 // Rather than use defines to specify the default device adapter
24 // VTK-m now builds for all device adapters and uses runtime controls
25 // to determine where execution occurs
26 #error The VTKM_DEVICE_ADAPTER define is no longer obeyed and needs to be removed
27 #endif
28 #ifdef VTKM_DEFAULT_DEVICE_ADAPTER_TAG
29 // Rather than use device adapter tag that had no shared parent
30 // VTK-m now uses a runtime device adapter implementation that
31 // allows for runtime execution selection of what device to execute on
32 #error The VTKM_DEFAULT_DEVICE_ADAPTER_TAG define is no longer required and needs to be removed
33 #endif
34 
35 #define VTKM_DEVICE_ADAPTER_UNDEFINED -1
36 #define VTKM_DEVICE_ADAPTER_SERIAL 1
37 #define VTKM_DEVICE_ADAPTER_CUDA 2
38 #define VTKM_DEVICE_ADAPTER_TBB 3
39 #define VTKM_DEVICE_ADAPTER_OPENMP 4
40 #define VTKM_DEVICE_ADAPTER_KOKKOS 5
41 //VTKM_DEVICE_ADAPTER_TestAlgorithmGeneral 7
42 #define VTKM_MAX_DEVICE_ADAPTER_ID 8
43 #define VTKM_DEVICE_ADAPTER_ANY 127
44 
45 namespace vtkm
46 {
47 namespace cont
48 {
49 
50 using DeviceAdapterNameType = std::string;
51 
59 {
60  constexpr bool operator==(DeviceAdapterId other) const { return this->Value == other.Value; }
61  constexpr bool operator!=(DeviceAdapterId other) const { return this->Value != other.Value; }
62  constexpr bool operator<(DeviceAdapterId other) const { return this->Value < other.Value; }
63 
73  constexpr bool IsValueValid() const
74  {
75  return this->Value > 0 && this->Value < VTKM_MAX_DEVICE_ADAPTER_ID;
76  }
77 
79  constexpr vtkm::Int8 GetValue() const { return this->Value; }
80 
89 
90 protected:
92 
93  constexpr explicit DeviceAdapterId(vtkm::Int8 id)
94  : Value(id)
95  {
96  }
97 
98 private:
100 };
101 
106 
117 {
118  return DeviceAdapterId(id);
119 }
120 
121 template <typename DeviceAdapter>
123 }
124 }
125 
129 #define VTKM_VALID_DEVICE_ADAPTER(Name, Id) \
130  namespace vtkm \
131  { \
132  namespace cont \
133  { \
134  struct VTKM_ALWAYS_EXPORT DeviceAdapterTag##Name : DeviceAdapterId \
135  { \
136  constexpr DeviceAdapterTag##Name() \
137  : DeviceAdapterId(Id) \
138  { \
139  } \
140  static constexpr bool IsEnabled = true; \
141  }; \
142  template <> \
143  struct DeviceAdapterTraits<vtkm::cont::DeviceAdapterTag##Name> \
144  { \
145  static DeviceAdapterNameType GetName() { return DeviceAdapterNameType(#Name); } \
146  }; \
147  } \
148  }
149 
153 #define VTKM_INVALID_DEVICE_ADAPTER(Name, Id) \
154  namespace vtkm \
155  { \
156  namespace cont \
157  { \
158  struct VTKM_ALWAYS_EXPORT DeviceAdapterTag##Name : DeviceAdapterId \
159  { \
160  constexpr DeviceAdapterTag##Name() \
161  : DeviceAdapterId(Id) \
162  { \
163  } \
164  static constexpr bool IsEnabled = false; \
165  }; \
166  template <> \
167  struct DeviceAdapterTraits<vtkm::cont::DeviceAdapterTag##Name> \
168  { \
169  static DeviceAdapterNameType GetName() { return DeviceAdapterNameType(#Name); } \
170  }; \
171  } \
172  }
173 
179 
181 
182 
188 
194 #define VTKM_IS_DEVICE_ADAPTER_TAG(tag) \
195  static_assert(std::is_base_of<vtkm::cont::DeviceAdapterId, tag>::value && \
196  !std::is_same<vtkm::cont::DeviceAdapterId, tag>::value, \
197  "Provided type is not a valid VTK-m device adapter tag.")
198 
199 #endif //vtk_m_cont_DeviceAdapterTag_h
vtkm::cont::DeviceAdapterTraits
Definition: DeviceAdapterTag.h:122
VTKM_DEVICE_ADAPTER_ANY
#define VTKM_DEVICE_ADAPTER_ANY
Definition: DeviceAdapterTag.h:43
vtkm::cont::DeviceAdapterId::GetName
DeviceAdapterNameType GetName() const
Return a name representing the device.
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
Types.h
vtkm::cont::DeviceAdapterId::GetValue
constexpr vtkm::Int8 GetValue() const
Returns the numeric value of the index.
Definition: DeviceAdapterTag.h:79
vtkm::cont::DeviceAdapterId::operator<
constexpr bool operator<(DeviceAdapterId other) const
Definition: DeviceAdapterTag.h:62
vtkm::cont::make_DeviceAdapterId
DeviceAdapterId make_DeviceAdapterId(const DeviceAdapterNameType &name)
Construct a device adapter id from a runtime string The string is case-insensitive.
vtkm::cont::DeviceAdapterId::IsValueValid
constexpr bool IsValueValid() const
Return whether this object represents a valid type of device.
Definition: DeviceAdapterTag.h:73
ExportMacros.h
vtkm::cont::DeviceAdapterId::operator!=
constexpr bool operator!=(DeviceAdapterId other) const
Definition: DeviceAdapterTag.h:61
vtkm::Int8
int8_t Int8
Base type to use for 8-bit signed integer numbers.
Definition: Types.h:165
VTKM_CONT_EXPORT
#define VTKM_CONT_EXPORT
Definition: vtkm_cont_export.h:44
Configure.h
vtkm_cont_export.h
vtkm::cont::DeviceAdapterNameType
std::string DeviceAdapterNameType
Definition: DeviceAdapterTag.h:50
vtkm::cont::DeviceAdapterId
An object used to specify a device.
Definition: DeviceAdapterTag.h:58
StaticAssert.h
vtkm::cont::DeviceAdapterId::operator==
constexpr bool operator==(DeviceAdapterId other) const
Definition: DeviceAdapterTag.h:60
VTKM_MAX_DEVICE_ADAPTER_ID
#define VTKM_MAX_DEVICE_ADAPTER_ID
Definition: DeviceAdapterTag.h:42
VTKM_VALID_DEVICE_ADAPTER
#define VTKM_VALID_DEVICE_ADAPTER(Name, Id)
Creates a tag named vtkm::cont::DeviceAdapterTagName and associated MPL structures to use this tag.
Definition: DeviceAdapterTag.h:129
VTKM_INVALID_DEVICE_ADAPTER
#define VTKM_INVALID_DEVICE_ADAPTER(Name, Id)
Marks the tag named vtkm::cont::DeviceAdapterTagName and associated structures as invalid to use.
Definition: DeviceAdapterTag.h:153
vtkm::cont::DeviceAdapterId::make_DeviceAdapterId
friend DeviceAdapterId make_DeviceAdapterId(vtkm::Int8 id)
Construct a device adapter id a vtkm::Int8.
Definition: DeviceAdapterTag.h:116
vtkm::cont::DeviceAdapterId::DeviceAdapterId
constexpr DeviceAdapterId(vtkm::Int8 id)
Definition: DeviceAdapterTag.h:93
vtkm::cont::DeviceAdapterId::Value
vtkm::Int8 Value
Definition: DeviceAdapterTag.h:99
VTKM_DEVICE_ADAPTER_UNDEFINED
#define VTKM_DEVICE_ADAPTER_UNDEFINED
Definition: DeviceAdapterTag.h:35