CUDA gputimer.h头文件

#ifndef __GPU_TIMER_H__
#define __GPU_TIMER_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__ */
View Code

     尝试添加gputimer.h头文件,一直失败。后来发现是头文件不对,换了头文件之后就成功了。gputimer.h头文件添加路径:.../cuda/cudatoolkit/include/

posted @ 2017-07-09 23:03  Jason&Hymer  阅读(1132)  评论(0编辑  收藏  举报