Skip to content

Instantly share code, notes, and snippets.

@ugovaretto
Created January 4, 2013 12:15
Show Gist options
  • Save ugovaretto/4452206 to your computer and use it in GitHub Desktop.
Save ugovaretto/4452206 to your computer and use it in GitHub Desktop.
Minimal CUDA event timer
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