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