VTK-m  2.0
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>
15 #include <vtkm/internal/Configure.h>
17 
18 #include <vtkm/cont/vtkm_cont_export.h>
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 
53 {
54  constexpr bool operator==(DeviceAdapterId other) const { return this->Value == other.Value; }
55  constexpr bool operator!=(DeviceAdapterId other) const { return this->Value != other.Value; }
56  constexpr bool operator<(DeviceAdapterId other) const { return this->Value < other.Value; }
57 
58  constexpr bool IsValueValid() const
59  {
60  return this->Value > 0 && this->Value < VTKM_MAX_DEVICE_ADAPTER_ID;
61  }
62 
63  constexpr vtkm::Int8 GetValue() const { return this->Value; }
64 
65  VTKM_CONT_EXPORT
67 
68 protected:
70 
71  constexpr explicit DeviceAdapterId(vtkm::Int8 id)
72  : Value(id)
73  {
74  }
75 
76 private:
78 };
79 
82 VTKM_CONT_EXPORT
84 
95 {
96  return DeviceAdapterId(id);
97 }
98 
99 template <typename DeviceAdapter>
101 }
102 }
103 
107 #define VTKM_VALID_DEVICE_ADAPTER(Name, Id) \
108  namespace vtkm \
109  { \
110  namespace cont \
111  { \
112  struct VTKM_ALWAYS_EXPORT DeviceAdapterTag##Name : DeviceAdapterId \
113  { \
114  constexpr DeviceAdapterTag##Name() \
115  : DeviceAdapterId(Id) \
116  { \
117  } \
118  static constexpr bool IsEnabled = true; \
119  }; \
120  template <> \
121  struct DeviceAdapterTraits<vtkm::cont::DeviceAdapterTag##Name> \
122  { \
123  static DeviceAdapterNameType GetName() { return DeviceAdapterNameType(#Name); } \
124  }; \
125  } \
126  }
127 
131 #define VTKM_INVALID_DEVICE_ADAPTER(Name, Id) \
132  namespace vtkm \
133  { \
134  namespace cont \
135  { \
136  struct VTKM_ALWAYS_EXPORT DeviceAdapterTag##Name : DeviceAdapterId \
137  { \
138  constexpr DeviceAdapterTag##Name() \
139  : DeviceAdapterId(Id) \
140  { \
141  } \
142  static constexpr bool IsEnabled = false; \
143  }; \
144  template <> \
145  struct DeviceAdapterTraits<vtkm::cont::DeviceAdapterTag##Name> \
146  { \
147  static DeviceAdapterNameType GetName() { return DeviceAdapterNameType(#Name); } \
148  }; \
149  } \
150  }
151 
152 // Represents when using TryExecute that the functor
153 // can be executed on any device instead of a specific
154 // one
156 
158 
159 #define VTKM_IS_DEVICE_ADAPTER_TAG(tag) \
165  static_assert(std::is_base_of<vtkm::cont::DeviceAdapterId, tag>::value && \
166  !std::is_same<vtkm::cont::DeviceAdapterId, tag>::value, \
167  "Provided type is not a valid VTK-m device adapter tag.")
168 
169 #endif //vtk_m_cont_DeviceAdapterTag_h
vtkm::cont::DeviceAdapterTraits
Definition: DeviceAdapterTag.h:100
VTKM_DEVICE_ADAPTER_ANY
#define VTKM_DEVICE_ADAPTER_ANY
Definition: DeviceAdapterTag.h:43
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
Definition: DeviceAdapterTag.h:63
vtkm::cont::DeviceAdapterId::operator<
constexpr bool operator<(DeviceAdapterId other) const
Definition: DeviceAdapterTag.h:56
vtkm::cont::DeviceAdapterId::IsValueValid
constexpr bool IsValueValid() const
Definition: DeviceAdapterTag.h:58
ExportMacros.h
vtkm::cont::DeviceAdapterId::operator!=
constexpr bool operator!=(DeviceAdapterId other) const
Definition: DeviceAdapterTag.h:55
vtkm::Int8
int8_t Int8
Definition: Types.h:156
vtkm::cont::DeviceAdapterNameType
std::string DeviceAdapterNameType
Definition: DeviceAdapterTag.h:50
vtkm::cont::make_DeviceAdapterId
VTKM_CONT_EXPORT DeviceAdapterId make_DeviceAdapterId(const DeviceAdapterNameType &name)
Construct a device adapter id from a runtime string The string is case-insensitive.
vtkm::cont::DeviceAdapterId
Definition: DeviceAdapterTag.h:52
StaticAssert.h
vtkm::cont::DeviceAdapterId::operator==
constexpr bool operator==(DeviceAdapterId other) const
Definition: DeviceAdapterTag.h:54
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:107
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:131
vtkm::cont::DeviceAdapterId::GetName
VTKM_CONT_EXPORT DeviceAdapterNameType GetName() const
vtkm::cont::DeviceAdapterId::make_DeviceAdapterId
friend DeviceAdapterId make_DeviceAdapterId(vtkm::Int8 id)
Construct a device adapter id a vtkm::Int8.
Definition: DeviceAdapterTag.h:94
vtkm::cont::DeviceAdapterId::DeviceAdapterId
constexpr DeviceAdapterId(vtkm::Int8 id)
Definition: DeviceAdapterTag.h:71
vtkm::cont::DeviceAdapterId::Value
vtkm::Int8 Value
Definition: DeviceAdapterTag.h:77
VTKM_DEVICE_ADAPTER_UNDEFINED
#define VTKM_DEVICE_ADAPTER_UNDEFINED
Definition: DeviceAdapterTag.h:35