Last active
August 29, 2015 14:03
-
-
Save jepio/508a4155e1d8c0394bf0 to your computer and use it in GitHub Desktop.
Timing CUDA GPU code. Source: https://github.com/udacity/cs344/blob/master/Unit2%20Code%20Snippets/gputimer.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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