VTK-m  2.0
RuntimeDeviceTracker.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_RuntimeDeviceTracker_h
11 #define vtk_m_cont_RuntimeDeviceTracker_h
12 
13 #include <vtkm/cont/vtkm_cont_export.h>
14 
19 
20 #include <functional>
21 #include <memory>
22 
23 namespace vtkm
24 {
25 namespace cont
26 {
27 namespace detail
28 {
29 
30 struct RuntimeDeviceTrackerInternals;
31 }
32 struct ScopedRuntimeDeviceTracker;
33 
47 class VTKM_CONT_EXPORT RuntimeDeviceTracker
48 {
50 
51 public:
52  VTKM_CONT
54 
58  VTKM_CONT bool CanRunOn(DeviceAdapterId deviceId) const;
59 
65  {
66  this->SetDeviceState(deviceId, false);
67  }
68 
69 
73  {
74  this->SetDeviceState(deviceId, false);
75  }
76 
81  VTKM_CONT void ResetDevice(vtkm::cont::DeviceAdapterId deviceId);
82 
86  VTKM_CONT
87  void Reset();
88 
98  VTKM_CONT void DisableDevice(DeviceAdapterId deviceId);
99 
112  VTKM_CONT void ForceDevice(DeviceAdapterId deviceId);
113 
117  VTKM_CONT bool GetThreadFriendlyMemAlloc() const;
118  VTKM_CONT void SetThreadFriendlyMemAlloc(bool state);
119 
125  VTKM_CONT void CopyStateFrom(const vtkm::cont::RuntimeDeviceTracker& tracker);
126 
133  VTKM_CONT void SetAbortChecker(const std::function<bool()>& func);
134  VTKM_CONT void ClearAbortChecker();
136 
137  VTKM_CONT bool CheckForAbortRequest() const;
138 
139  VTKM_CONT void PrintSummary(std::ostream& out) const;
140 
141 private:
143 
144  detail::RuntimeDeviceTrackerInternals* Internals;
145 
146  VTKM_CONT
147  RuntimeDeviceTracker(detail::RuntimeDeviceTrackerInternals* details, bool reset);
148 
149  VTKM_CONT
151 
152  VTKM_CONT
153  RuntimeDeviceTracker& operator=(const RuntimeDeviceTracker&) = delete;
154 
155  VTKM_CONT
156  void CheckDevice(vtkm::cont::DeviceAdapterId deviceId) const;
157 
158  VTKM_CONT
159  void SetDeviceState(vtkm::cont::DeviceAdapterId deviceId, bool state);
160 
161  VTKM_CONT
162  void LogEnabledDevices() const;
163 };
164 
174 VTKM_CONT_EXPORT
175 VTKM_CONT
177 
179 {
180  Force,
181  Enable,
182  Disable
183 };
184 
191 {
204 
223 
227  const std::function<bool()>& abortChecker,
229 
232 
233 private:
234  std::unique_ptr<detail::RuntimeDeviceTrackerInternals> SavedState;
235 };
236 
237 }
238 } // namespace vtkm::cont
239 
240 #endif //vtk_m_cont_RuntimeDeviceTracker_h
ErrorBadAllocation.h
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
ErrorBadDevice.h
vtkm::cont::RuntimeDeviceTracker::ReportBadDeviceFailure
VTKM_CONT void ReportBadDeviceFailure(vtkm::cont::DeviceAdapterId deviceId, const vtkm::cont::ErrorBadDevice &)
Report a ErrorBadDevice failure and flag the device as unusable.
Definition: RuntimeDeviceTracker.h:71
vtkm::cont::RuntimeDeviceTracker::Internals
detail::RuntimeDeviceTrackerInternals * Internals
Definition: RuntimeDeviceTracker.h:144
DeviceAdapterTag.h
vtkm::cont::RuntimeDeviceTrackerMode::Force
@ Force
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::cont::ScopedRuntimeDeviceTracker
Definition: RuntimeDeviceTracker.h:190
vtkm::cont::RuntimeDeviceTracker
RuntimeDeviceTracker is the central location for determining which device adapter will be active for ...
Definition: RuntimeDeviceTracker.h:47
vtkm::cont::RuntimeDeviceTrackerMode::Disable
@ Disable
vtkm::cont::ScopedRuntimeDeviceTracker::SavedState
std::unique_ptr< detail::RuntimeDeviceTrackerInternals > SavedState
Construct a ScopedRuntimeDeviceTracker associated with the thread, associated with the provided track...
Definition: RuntimeDeviceTracker.h:234
vtkm::cont::DeviceAdapterId
Definition: DeviceAdapterTag.h:52
vtkm::cont::ErrorBadAllocation
This class is thrown when VTK-m attempts to manipulate memory that it should not.
Definition: ErrorBadAllocation.h:25
vtkm::cont::RuntimeDeviceTracker::ReportAllocationFailure
VTKM_CONT void ReportAllocationFailure(vtkm::cont::DeviceAdapterId deviceId, const vtkm::cont::ErrorBadAllocation &)
Report a failure to allocate memory on a device, this will flag the device as being unusable for all ...
Definition: RuntimeDeviceTracker.h:63
vtkm::cont::GetRuntimeDeviceTracker
VTKM_CONT_EXPORT VTKM_CONT vtkm::cont::RuntimeDeviceTracker & GetRuntimeDeviceTracker()
Get the RuntimeDeviceTracker for the current thread.
RuntimeDeviceInformation.h
vtkm::cont::ErrorBadDevice
This class is thrown when VTK-m performs an operation that is not supported on the current device.
Definition: ErrorBadDevice.h:29
vtkm::cont::RuntimeDeviceTrackerMode
RuntimeDeviceTrackerMode
Definition: RuntimeDeviceTracker.h:178
vtkm::cont::RuntimeDeviceTrackerMode::Enable
@ Enable