Created
January 4, 2013 12:15
-
-
Save ugovaretto/4452206 to your computer and use it in GitHub Desktop.
Minimal CUDA event timer
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
class CUDAEventTimer { | |
public: | |
CUDAEventTimer() { | |
cudaEventCreate(&start_); | |
cudaEventCreate(&stop_); | |
} | |
~CUDAEventTimer() { | |
cudaEventDestroy(start_); | |
cudaEventDestroy(stop_); | |
} | |
void start(cudaStream_t stream = 0) { | |
stream_ = stream; | |
cudaEventRecord(start_, stream_); | |
} | |
void stop() { | |
cudaEventRecord(stop_, stream_); | |
cudaEventSynchronize(stop_); | |
} | |
float elapsed() { | |
float elapsed = 0; | |
cudaEventElapsedTime(&elapsed, start_, stop_); | |
return elapsed; | |
} | |
private: | |
cudaEvent_t start_, stop_; | |
cudaStream_t stream_; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment