Commit 46550899 authored by Kenneth Moreland's avatar Kenneth Moreland

Allow resetting Timer with a new device

Previously, in order to specify a device with the timer, it had to be
specified in the timer's construction or had to be specified every time
GetElapsedTime was called. The first method was inconvienient in the
case where there are multiple code paths to define the device and the
latter method was inconvienient because you would have to pass around a
device id.

Both these techniques still exist, but we have also added a new form of
Reset that allows you to change the device the timer is used on.
parent dd4a9395
......@@ -201,6 +201,21 @@ void Timer::Reset()
vtkm::ListForEach(functor, detail::EnabledDeviceListTag(), this, TimerDispatchTag::Reset);
void Timer::Reset(vtkm::cont::DeviceAdapterId device)
vtkm::cont::RuntimeDeviceTracker tracker;
if (device != DeviceAdapterTagAny() && !tracker.CanRunOn(device))
"Device '" << device.GetName() << "' can not run on current Device."
"Thus timer is not usable");
this->Device = device;
this->DeviceForQuery = vtkm::cont::DeviceAdapterTagAny();
void Timer::Start()
......@@ -45,6 +45,8 @@ class EnabledDeviceTimerImpls;
/// have the longest execution time if enabled.
/// Per device adapter time query is also supported. It's useful when users want to reuse
/// the same timer to measure the cuda kernal call as well as the cuda device execution.
/// It is also possible to change the device adapter after construction by calling the form
/// of the Reset method with a new DeviceAdapterId.
/// The there is no guaranteed resolution of the time but should generally be
/// good to about a millisecond.
......@@ -64,6 +66,9 @@ public:
/// Resets the timer.
VTKM_CONT void Reset();
/// Resets the timer and changes the device to time on.
VTKM_CONT void Reset(vtkm::cont::DeviceAdapterId device);
/// Start would call Reset function before starting the timer for convenience
VTKM_CONT void Start();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment