Viskores  1.0
DeviceAdapterTag.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_DeviceAdapterTag_h
19 #define viskores_cont_DeviceAdapterTag_h
20 
21 #include <viskores/StaticAssert.h>
22 #include <viskores/Types.h>
25 
27 
28 #include <string>
29 
30 #ifdef VISKORES_DEVICE_ADAPTER
31 // Rather than use defines to specify the default device adapter
32 // Viskores now builds for all device adapters and uses runtime controls
33 // to determine where execution occurs
34 #error The VISKORES_DEVICE_ADAPTER define is no longer obeyed and needs to be removed
35 #endif
36 #ifdef VISKORES_DEFAULT_DEVICE_ADAPTER_TAG
37 // Rather than use device adapter tag that had no shared parent
38 // Viskores now uses a runtime device adapter implementation that
39 // allows for runtime execution selection of what device to execute on
40 #error The VISKORES_DEFAULT_DEVICE_ADAPTER_TAG define is no longer required and needs to be removed
41 #endif
42 
43 #define VISKORES_DEVICE_ADAPTER_UNDEFINED -1
44 #define VISKORES_DEVICE_ADAPTER_SERIAL 1
45 #define VISKORES_DEVICE_ADAPTER_CUDA 2
46 #define VISKORES_DEVICE_ADAPTER_TBB 3
47 #define VISKORES_DEVICE_ADAPTER_OPENMP 4
48 #define VISKORES_DEVICE_ADAPTER_KOKKOS 5
49 //VISKORES_DEVICE_ADAPTER_TestAlgorithmGeneral 7
50 #define VISKORES_MAX_DEVICE_ADAPTER_ID 8
51 #define VISKORES_DEVICE_ADAPTER_ANY 127
52 
53 namespace viskores
54 {
55 namespace cont
56 {
57 
58 using DeviceAdapterNameType = std::string;
59 
67 {
68  constexpr bool operator==(DeviceAdapterId other) const { return this->Value == other.Value; }
69  constexpr bool operator!=(DeviceAdapterId other) const { return this->Value != other.Value; }
70  constexpr bool operator<(DeviceAdapterId other) const { return this->Value < other.Value; }
71 
81  constexpr bool IsValueValid() const
82  {
83  return this->Value > 0 && this->Value < VISKORES_MAX_DEVICE_ADAPTER_ID;
84  }
85 
87  constexpr viskores::Int8 GetValue() const { return this->Value; }
88 
95  VISKORES_CONT_EXPORT
97 
98 protected:
100 
101  constexpr explicit DeviceAdapterId(viskores::Int8 id)
102  : Value(id)
103  {
104  }
105 
106 private:
108 };
109 
112 VISKORES_CONT_EXPORT
114 
125 {
126  return DeviceAdapterId(id);
127 }
128 
129 template <typename DeviceAdapter>
131 }
132 }
133 
137 #define VISKORES_VALID_DEVICE_ADAPTER(Name, Id) \
138  namespace viskores \
139  { \
140  namespace cont \
141  { \
142  struct VISKORES_ALWAYS_EXPORT DeviceAdapterTag##Name : DeviceAdapterId \
143  { \
144  constexpr DeviceAdapterTag##Name() \
145  : DeviceAdapterId(Id) \
146  { \
147  } \
148  static constexpr bool IsEnabled = true; \
149  }; \
150  template <> \
151  struct DeviceAdapterTraits<viskores::cont::DeviceAdapterTag##Name> \
152  { \
153  static DeviceAdapterNameType GetName() \
154  { \
155  return DeviceAdapterNameType(#Name); \
156  } \
157  }; \
158  } \
159  }
160 
164 #define VISKORES_INVALID_DEVICE_ADAPTER(Name, Id) \
165  namespace viskores \
166  { \
167  namespace cont \
168  { \
169  struct VISKORES_ALWAYS_EXPORT DeviceAdapterTag##Name : DeviceAdapterId \
170  { \
171  constexpr DeviceAdapterTag##Name() \
172  : DeviceAdapterId(Id) \
173  { \
174  } \
175  static constexpr bool IsEnabled = false; \
176  }; \
177  template <> \
178  struct DeviceAdapterTraits<viskores::cont::DeviceAdapterTag##Name> \
179  { \
180  static DeviceAdapterNameType GetName() \
181  { \
182  return DeviceAdapterNameType(#Name); \
183  } \
184  }; \
185  } \
186  }
187 
193 
195 
196 
202 
208 #define VISKORES_IS_DEVICE_ADAPTER_TAG(tag) \
209  static_assert(std::is_base_of<viskores::cont::DeviceAdapterId, tag>::value && \
210  !std::is_same<viskores::cont::DeviceAdapterId, tag>::value, \
211  "Provided type is not a valid Viskores device adapter tag.")
212 
213 #endif //viskores_cont_DeviceAdapterTag_h
Types.h
viskores::Int8
int8_t Int8
Base type to use for 8-bit signed integer numbers.
Definition: Types.h:173
viskores::cont::DeviceAdapterId::operator==
constexpr bool operator==(DeviceAdapterId other) const
Definition: DeviceAdapterTag.h:68
viskores::cont::DeviceAdapterId::operator!=
constexpr bool operator!=(DeviceAdapterId other) const
Definition: DeviceAdapterTag.h:69
VISKORES_DEVICE_ADAPTER_ANY
#define VISKORES_DEVICE_ADAPTER_ANY
Definition: DeviceAdapterTag.h:51
ExportMacros.h
viskores
Groups connected points that have the same field value.
Definition: Atomic.h:27
VISKORES_MAX_DEVICE_ADAPTER_ID
#define VISKORES_MAX_DEVICE_ADAPTER_ID
Definition: DeviceAdapterTag.h:50
VISKORES_DEVICE_ADAPTER_UNDEFINED
#define VISKORES_DEVICE_ADAPTER_UNDEFINED
Definition: DeviceAdapterTag.h:43
Configure.h
viskores::cont::DeviceAdapterId::IsValueValid
constexpr bool IsValueValid() const
Return whether this object represents a valid type of device.
Definition: DeviceAdapterTag.h:81
VISKORES_VALID_DEVICE_ADAPTER
#define VISKORES_VALID_DEVICE_ADAPTER(Name, Id)
Creates a tag named viskores::cont::DeviceAdapterTagName and associated MPL structures to use this ta...
Definition: DeviceAdapterTag.h:137
VISKORES_INVALID_DEVICE_ADAPTER
#define VISKORES_INVALID_DEVICE_ADAPTER(Name, Id)
Marks the tag named viskores::cont::DeviceAdapterTagName and associated structures as invalid to use.
Definition: DeviceAdapterTag.h:164
viskores::cont::DeviceAdapterId
An object used to specify a device.
Definition: DeviceAdapterTag.h:66
viskores::cont::DeviceAdapterId::Value
viskores::Int8 Value
Definition: DeviceAdapterTag.h:107
StaticAssert.h
viskores::cont::make_DeviceAdapterId
DeviceAdapterId make_DeviceAdapterId(const DeviceAdapterNameType &name)
Construct a device adapter id from a runtime string The string is case-insensitive.
viskores::cont::DeviceAdapterId::operator<
constexpr bool operator<(DeviceAdapterId other) const
Definition: DeviceAdapterTag.h:70
viskores::cont::DeviceAdapterId::GetName
DeviceAdapterNameType GetName() const
Return a name representing the device.
viskores::cont::DeviceAdapterNameType
std::string DeviceAdapterNameType
Definition: DeviceAdapterTag.h:58
viskores::cont::DeviceAdapterId::make_DeviceAdapterId
friend DeviceAdapterId make_DeviceAdapterId(viskores::Int8 id)
Construct a device adapter id a viskores::Int8.
Definition: DeviceAdapterTag.h:124
viskores::cont::DeviceAdapterId::DeviceAdapterId
constexpr DeviceAdapterId(viskores::Int8 id)
Definition: DeviceAdapterTag.h:101
viskores::cont::DeviceAdapterTraits
Definition: DeviceAdapterTag.h:130
viskores_cont_export.h
viskores::cont::DeviceAdapterId::GetValue
constexpr viskores::Int8 GetValue() const
Returns the numeric value of the index.
Definition: DeviceAdapterTag.h:87