Skip to content

Instantly share code, notes, and snippets.

@jepio
Last active August 29, 2015 14:03
Show Gist options
  • Save jepio/508a4155e1d8c0394bf0 to your computer and use it in GitHub Desktop.
Save jepio/508a4155e1d8c0394bf0 to your computer and use it in GitHub Desktop.
#ifndef __GPU_TIMER_H__
#define __GPU_TIMER_H__
#include <cuda_runtime.h>
struct GpuTimer
{
cudaEvent_t start;
cudaEvent_t stop;
GpuTimer()
{
cudaEventCreate(&start);
cudaEventCreate(&stop);
}
~GpuTimer()
{
cudaEventDestroy(start);
cudaEventDestroy(stop);
}
void Start()
{
cudaEventRecord(start, 0);
}
void Stop()
{
cudaEventRecord(stop, 0);
}
float Elapsed()
{
// Returns elapsed time in msecs.
float elapsed;
cudaEventSynchronize(stop);
cudaEventElapsedTime(&elapsed, start, stop);
return elapsed;
}
};
typedef struct GpuTimer GpuTimer;
#endif /* __GPU_TIMER_H__ */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment