imate
C++/CUDA Reference
|
Records elasped time between two CUDA events. More...
#include <cuda_timer.h>
Public Member Functions | |
CudaTimer () | |
constructor for CudaTimer More... | |
~CudaTimer () | |
Destructor for CudaTimer . More... | |
void | start () |
Starts the timer. More... | |
void | stop () |
Stops the timer. More... | |
float | elapsed () const |
Returns the elapsed time in seconds. More... | |
Protected Attributes | |
cudaEvent_t | start_time |
cudaEvent_t | stop_time |
Records elasped time between two CUDA events.
The measured time is the wall time, not the process time of the GPU. In fact, the measured time the same as the wall clock time of CPU.
Example:
It is better to synchronize all GPU threads before reading the time. For instance:
CudaTimer cuda_timer; cuda_timer.start(); // Some GPU threads here. // ... // Note, this CudaTime measures wall time, so the sleep() // time counts toward the measured time. sleep(1); // Sync threads so the CPU do not jump to the next before // gpu threads are done. cudaDeviceSynchronize(); cuda_timer.stop(); float elapsed_time = cuda_timer.elapsed();
Definition at line 61 of file cuda_timer.h.
CudaTimer::CudaTimer | ( | ) |
constructor for CudaTimer
Definition at line 26 of file cuda_timer.cu.
References cudaEventCreate(), start_time, and stop_time.
CudaTimer::~CudaTimer | ( | ) |
Destructor for CudaTimer
.
Definition at line 40 of file cuda_timer.cu.
References cudaEventDestroy(), start_time, and stop_time.
float CudaTimer::elapsed | ( | ) | const |
Returns the elapsed time in seconds.
Definition at line 80 of file cuda_timer.cu.
References cudaEventElapsedTime(), cudaEventSynchronize(), start_time, and stop_time.
Referenced by cuTraceEstimator< DataType >::cu_trace_estimator().
void CudaTimer::start | ( | ) |
Starts the timer.
Definition at line 54 of file cuda_timer.cu.
References cudaEventRecord(), and start_time.
Referenced by cuTraceEstimator< DataType >::cu_trace_estimator().
void CudaTimer::stop | ( | ) |
Stops the timer.
Definition at line 67 of file cuda_timer.cu.
References cudaEventRecord(), and stop_time.
Referenced by cuTraceEstimator< DataType >::cu_trace_estimator().
|
protected |
Definition at line 72 of file cuda_timer.h.
Referenced by CudaTimer(), elapsed(), start(), and ~CudaTimer().
|
protected |
Definition at line 73 of file cuda_timer.h.
Referenced by CudaTimer(), elapsed(), stop(), and ~CudaTimer().