VTK-m  2.1
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 
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 class ScopedRuntimeDeviceTracker;
33 
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;
119  VTKM_CONT void SetThreadFriendlyMemAlloc(bool state);
120 
126  VTKM_CONT void CopyStateFrom(const vtkm::cont::RuntimeDeviceTracker& tracker);
127 
133  VTKM_CONT void SetAbortChecker(const std::function<bool()>& func);
135  VTKM_CONT void ClearAbortChecker();
136 
137  VTKM_CONT bool CheckForAbortRequest() const;
138 
140  VTKM_CONT void PrintSummary(std::ostream& out) const;
141 
142 private:
144 
145  detail::RuntimeDeviceTrackerInternals* Internals;
146 
147  VTKM_CONT
148  RuntimeDeviceTracker(detail::RuntimeDeviceTrackerInternals* details, bool reset);
149 
150  VTKM_CONT
152 
153  VTKM_CONT
154  RuntimeDeviceTracker& operator=(const RuntimeDeviceTracker&) = delete;
155 
156  VTKM_CONT
157  void CheckDevice(vtkm::cont::DeviceAdapterId deviceId) const;
158 
159  VTKM_CONT
160  void SetDeviceState(vtkm::cont::DeviceAdapterId deviceId, bool state);
161 
162  VTKM_CONT
163  void LogEnabledDevices() const;
164 };
165 
176 VTKM_CONT
178 
181 {
182  // Documentation is below (for better layout in generated documents).
183  Force,
184  Enable,
185  Disable
186 };
187 
193 
196 
199 
200 //----------------------------------------------------------------------------
206 {
207 public:
220 
239 
243  const std::function<bool()>& abortChecker,
245 
248 
249 private:
250  std::unique_ptr<detail::RuntimeDeviceTrackerInternals> SavedState;
251 };
252 
253 }
254 } // namespace vtkm::cont
255 
256 #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::Internals
detail::RuntimeDeviceTrackerInternals * Internals
Definition: RuntimeDeviceTracker.h:145
DeviceAdapterTag.h
vtkm::cont::RuntimeDeviceTrackerMode::Force
@ Force
Replaces the current list of devices to try with the device specified.
vtkm::cont::RuntimeDeviceTracker::ReportBadDeviceFailure
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::ScopedRuntimeDeviceTracker
A class to create a scoped runtime device tracker object.
Definition: RuntimeDeviceTracker.h:205
vtkm::cont::GetRuntimeDeviceTracker
vtkm::cont::RuntimeDeviceTracker & GetRuntimeDeviceTracker()
Get the RuntimeDeviceTracker for the current thread.
VTKM_CONT_EXPORT
#define VTKM_CONT_EXPORT
Definition: vtkm_cont_export.h:44
vtkm_cont_export.h
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
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
Removes the provided device adapter from the list of devices to try.
vtkm::cont::DeviceAdapterId
An object used to specify a device.
Definition: DeviceAdapterTag.h:58
vtkm::cont::ErrorBadAllocation
This class is thrown when VTK-m attempts to manipulate memory that it should not.
Definition: ErrorBadAllocation.h:25
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:250
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
Identifier used to specify whether to enable or disable a particular device.
Definition: RuntimeDeviceTracker.h:180
vtkm::cont::RuntimeDeviceTrackerMode::Enable
@ Enable
Adds the provided device adapter to the list of devices to try.
vtkm::cont::RuntimeDeviceTracker::ReportAllocationFailure
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