Viskores  1.0
RuntimeDeviceTracker.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_RuntimeDeviceTracker_h
19 #define viskores_cont_RuntimeDeviceTracker_h
20 
22 
27 
28 #include <functional>
29 #include <memory>
30 
31 namespace viskores
32 {
33 namespace cont
34 {
35 namespace detail
36 {
37 
38 struct RuntimeDeviceTrackerInternals;
39 }
40 class ScopedRuntimeDeviceTracker;
41 
55 class VISKORES_CONT_EXPORT RuntimeDeviceTracker
56 {
58 
59 public:
62 
66  VISKORES_CONT bool CanRunOn(DeviceAdapterId deviceId) const;
67 
73  {
74  this->SetDeviceState(deviceId, false);
75  }
76 
77 
81  {
82  this->SetDeviceState(deviceId, false);
83  }
84 
89  VISKORES_CONT void ResetDevice(viskores::cont::DeviceAdapterId deviceId);
90 
95  void Reset();
96 
106  VISKORES_CONT void DisableDevice(DeviceAdapterId deviceId);
107 
120  VISKORES_CONT void ForceDevice(DeviceAdapterId deviceId);
121 
125  VISKORES_CONT bool GetThreadFriendlyMemAlloc() const;
127  VISKORES_CONT void SetThreadFriendlyMemAlloc(bool state);
128 
134  VISKORES_CONT void CopyStateFrom(const viskores::cont::RuntimeDeviceTracker& tracker);
135 
141  VISKORES_CONT void SetAbortChecker(const std::function<bool()>& func);
143  VISKORES_CONT void ClearAbortChecker();
144 
145  VISKORES_CONT bool CheckForAbortRequest() const;
146 
148  VISKORES_CONT void PrintSummary(std::ostream& out) const;
149 
150 private:
152 
153  detail::RuntimeDeviceTrackerInternals* Internals;
154 
156  RuntimeDeviceTracker(detail::RuntimeDeviceTrackerInternals* details, bool reset);
157 
160 
162  RuntimeDeviceTracker& operator=(const RuntimeDeviceTracker&) = delete;
163 
165  void CheckDevice(viskores::cont::DeviceAdapterId deviceId) const;
166 
168  void SetDeviceState(viskores::cont::DeviceAdapterId deviceId, bool state);
169 
171  void LogEnabledDevices() const;
172 };
173 
183 VISKORES_CONT_EXPORT
186 
189 {
190  // Documentation is below (for better layout in generated documents).
191  Force,
192  Enable,
193  Disable
194 };
195 
201 
204 
207 
208 //----------------------------------------------------------------------------
214 {
215 public:
228 
247 
251  const std::function<bool()>& abortChecker,
253 
256 
257 private:
258  std::unique_ptr<detail::RuntimeDeviceTrackerInternals> SavedState;
259 };
260 
261 }
262 } // namespace viskores::cont
263 
264 #endif //viskores_cont_RuntimeDeviceTracker_h
viskores::cont::RuntimeDeviceTrackerMode
RuntimeDeviceTrackerMode
Identifier used to specify whether to enable or disable a particular device.
Definition: RuntimeDeviceTracker.h:188
ErrorBadAllocation.h
viskores::cont::ErrorBadAllocation
This class is thrown when Viskores attempts to manipulate memory that it should not.
Definition: ErrorBadAllocation.h:33
ErrorBadDevice.h
viskores::cont::GetRuntimeDeviceTracker
viskores::cont::RuntimeDeviceTracker & GetRuntimeDeviceTracker()
Get the RuntimeDeviceTracker for the current thread.
DeviceAdapterTag.h
viskores::cont::RuntimeDeviceTracker::ReportAllocationFailure
void ReportAllocationFailure(viskores::cont::DeviceAdapterId deviceId, const viskores::cont::ErrorBadAllocation &)
Report a failure to allocate memory on a device, this will flag the device as being unusable for all ...
Definition: RuntimeDeviceTracker.h:71
viskores::cont::ScopedRuntimeDeviceTracker
A class to create a scoped runtime device tracker object.
Definition: RuntimeDeviceTracker.h:213
viskores::cont::ScopedRuntimeDeviceTracker::SavedState
std::unique_ptr< detail::RuntimeDeviceTrackerInternals > SavedState
Construct a ScopedRuntimeDeviceTracker associated with the thread, associated with the provided track...
Definition: RuntimeDeviceTracker.h:258
VISKORES_CONT
#define VISKORES_CONT
Definition: ExportMacros.h:65
viskores
Groups connected points that have the same field value.
Definition: Atomic.h:27
viskores::cont::RuntimeDeviceTrackerMode::Enable
@ Enable
Adds the provided device adapter to the list of devices to try.
viskores::cont::ErrorBadDevice
This class is thrown when Viskores performs an operation that is not supported on the current device.
Definition: ErrorBadDevice.h:37
viskores::cont::DeviceAdapterId
An object used to specify a device.
Definition: DeviceAdapterTag.h:66
viskores::cont::RuntimeDeviceTracker
RuntimeDeviceTracker is the central location for determining which device adapter will be active for ...
Definition: RuntimeDeviceTracker.h:55
viskores::cont::RuntimeDeviceTracker::ReportBadDeviceFailure
void ReportBadDeviceFailure(viskores::cont::DeviceAdapterId deviceId, const viskores::cont::ErrorBadDevice &)
Report a ErrorBadDevice failure and flag the device as unusable.
Definition: RuntimeDeviceTracker.h:79
RuntimeDeviceInformation.h
viskores::cont::RuntimeDeviceTrackerMode::Disable
@ Disable
Removes the provided device adapter from the list of devices to try.
viskores::cont::RuntimeDeviceTrackerMode::Force
@ Force
Replaces the current list of devices to try with the device specified.
viskores::cont::RuntimeDeviceTracker::Internals
detail::RuntimeDeviceTrackerInternals * Internals
Definition: RuntimeDeviceTracker.h:153
viskores_cont_export.h