2013-04-30 59 views
1

的时候,我有一个函数是这样的:措施运行C++和CUDA代码

int doSomething() { 
    <C++ host code> 
    <CUDA device code> 
    <C++ host code> 
    <...> 
} 

我想测量精度高(至少毫秒)这个函数的运行时间在Linux和Windows太。

我知道我可以衡量事件CUDA程序的运行时间,我发现非常准确库,用于测量我的过程中所使用的CPU时间,但我想衡量整体运行时间。我不能测量两个不同的时间,并将它们加在一起,因为设备代码和主机代码可以并行运行。

我想用尽可能少的外部库作为可能的,但我感兴趣的任何好的解决方案。

+1

的可能重复[如何衡量GPU VS CPU性能,与时间测量功能?(HTTP:// stackoverflow.com/questions/16258141/how-to-measure-gpu-vs-cpu-performance-with-which-time-measuring-functions) – talonmies 2013-04-30 17:16:20

+0

这已被问过多少次,最近在*前两天*。在提问前请搜索或查看CUDA标签的最新问题和常见问题。 – talonmies 2013-04-30 17:17:19

+0

您是否尝试过使用CUDA分析器?我插入了预期的cudaDeviceSych命令,以便使用分析器来测量CPU时序。 – TripleS 2013-04-30 17:42:55

回答

0

对于Windows:

LARGE_INTEGER perfCntStart, perfCntStop, proc_freq; 
::memset(&proc_freq, 0x00, sizeof(proc_freq)); 
::memset(&perfCntStart, 0x00, sizeof(perfCntStart)); 
::memset(&perfCntStop, 0x00, sizeof(perfCntStop)); 
::QueryPerformanceCounter(&perfCntStart); 
::QueryPerformanceFrequency(&proc_freq); 

..做一些事情

::QueryPerformanceCounter(&perfCntStop); 
printf(": %f\n", float(perfCntStop.QuadPart - perfCntStart.QuadPart)/float(proc_freq.QuadPart)); }