M2_SETI/A4/TP_GPU-master/TP2_reduction/GpuTimer.h
2022-12-09 09:03:22 +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;
}
};