M2_SETI/A4/TP_OMP_GPU/Seuillage/GpuTimer.h
2023-02-22 11:23:45 +01:00

39 lines
508 B
C++

#pragma once
#include <cuda_runtime_api.h>
class GpuTimer
{
cudaEvent_t start, stop;
public:
GpuTimer()
{
cudaEventCreate(&start);
cudaEventCreate(&stop);
}
~GpuTimer()
{
cudaEventDestroy(stop);
cudaEventDestroy(start);
}
void Start()
{
cudaEventRecord(start);
}
void Stop()
{
cudaEventRecord(stop);
cudaEventSynchronize(stop);
}
float Elapsed()
{
float elapsed;
cudaEventElapsedTime(&elapsed, start, stop);
return elapsed;
}
};