Viskores  1.0
DeviceAdapterListHelpers.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_internal_DeviceAdapterListHelpers_h
19 #define viskores_cont_internal_DeviceAdapterListHelpers_h
20 
21 #include <viskores/List.h>
24 
25 namespace viskores
26 {
27 namespace cont
28 {
29 namespace internal
30 {
31 
32 //============================================================================
33 struct ExecuteIfValidDeviceTag
34 {
35 
36  template <typename DeviceAdapter>
37  using EnableIfValid = std::enable_if<DeviceAdapter::IsEnabled>;
38 
39  template <typename DeviceAdapter>
40  using EnableIfInvalid = std::enable_if<!DeviceAdapter::IsEnabled>;
41 
42  template <typename DeviceAdapter, typename Functor, typename... Args>
43  typename EnableIfValid<DeviceAdapter>::type operator()(
44  DeviceAdapter device,
45  Functor&& f,
47  Args&&... args) const
48  {
49  if (tracker.CanRunOn(device))
50  {
51  f(device, std::forward<Args>(args)...);
52  }
53  }
54 
55  // do not generate code for invalid devices
56  template <typename DeviceAdapter, typename... Args>
57  typename EnableIfInvalid<DeviceAdapter>::type operator()(DeviceAdapter, Args&&...) const
58  {
59  }
60 };
61 
64 template <typename DeviceList, typename Functor, typename... Args>
65 VISKORES_CONT void ForEachValidDevice(DeviceList devices, Functor&& functor, Args&&... args)
66 {
69  ExecuteIfValidDeviceTag{}, devices, functor, tracker, std::forward<Args>(args)...);
70 }
71 }
72 }
73 } // viskores::cont::internal
74 
75 #endif // viskores_cont_internal_DeviceAdapterListHelpers_h
ErrorBadDevice.h
RuntimeDeviceTracker.h
viskores::cont::GetRuntimeDeviceTracker
viskores::cont::RuntimeDeviceTracker & GetRuntimeDeviceTracker()
Get the RuntimeDeviceTracker for the current thread.
VISKORES_CONT
#define VISKORES_CONT
Definition: ExportMacros.h:65
viskores
Groups connected points that have the same field value.
Definition: Atomic.h:27
viskores::ListForEach
void ListForEach(Functor &&f, viskores::List< Ts... >, Args &&... args)
For each typename represented by the list, call the functor with a default instance of that type.
Definition: List.h:745
viskores::cont::RuntimeDeviceTracker
RuntimeDeviceTracker is the central location for determining which device adapter will be active for ...
Definition: RuntimeDeviceTracker.h:55
viskores::cont::RuntimeDeviceTracker::CanRunOn
bool CanRunOn(DeviceAdapterId deviceId) const
Returns true if the given device adapter is supported on the current machine.
List.h