Commit 4d9ce248 authored by Kenneth Moreland's avatar Kenneth Moreland

Synchronize CUDA timer when stopping it

Previously, when Stop was called on a Cuda timer, it would record a stop
event but it would not synchronize it at that time. Instead, the
synchronize was only called when GetElapsedTime was called. The problem
is that the time of the event is only marked when synchronize is called.
Thus, if the event completed before GetElapsedTime was called, it would
record the time from when the event acutally happened to the time when
GetElapsedTime was called as part of the elapsed time, which is
incorrect.

Fix the problem by synchronizing when Stop is called. Although this
makes the Timer more invasive, generally using the Timer can cause
synchronization to happen. This behavior is consistent with the Timer
implementation for other devices.
parent 85265a9c
......@@ -64,6 +64,7 @@ void DeviceAdapterTimerImplementation<vtkm::cont::DeviceAdapterTagCuda>::Start()
void DeviceAdapterTimerImplementation<vtkm::cont::DeviceAdapterTagCuda>::Stop()
{
VTKM_CUDA_CALL(cudaEventRecord(this->StopEvent, cudaStreamPerThread));
VTKM_CUDA_CALL(cudaEventSynchronize(this->StopEvent));
this->StopReady = true;
}
......@@ -104,9 +105,9 @@ vtkm::Float64 DeviceAdapterTimerImplementation<vtkm::cont::DeviceAdapterTagCuda>
{
// Stop was not called, so we have to insert a new event into the stream
VTKM_CUDA_CALL(cudaEventRecord(this->StopEvent, cudaStreamPerThread));
VTKM_CUDA_CALL(cudaEventSynchronize(this->StopEvent));
}
VTKM_CUDA_CALL(cudaEventSynchronize(this->StopEvent));
float elapsedTimeMilliseconds;
VTKM_CUDA_CALL(cudaEventElapsedTime(&elapsedTimeMilliseconds, this->StartEvent, this->StopEvent));
// Reset Stop flag to its original state
......
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