gputimer.h

发布时间 2024-01-04 13:46:07作者: hfgyui

ifndef GPU_TIMER_H

define GPU_TIMER_H

include <math.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()
{
    float elapsed;
    cudaEventSynchronize(stop);
    cudaEventElapsedTime(&elapsed, start, stop);
    return elapsed;
}

};

endif /* GPU_TIMER_H */