2013-04-30 68 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)); }