CUDA中记录GPU耗时与C编程中记录CPU耗时的方法
// capture the start time
cudaEvent_t start,
stop;
cudaEventCreate( &start );
cudaEventCreate( &stop );
cudaEventRecord( start, 0 );
和
// get stop time, and display the timing results
cudaEventRecord( stop, 0 );
cudaEventSynchronize( stop );
float elapsedTime;
cudaEventElapsedTime( &elapsedTime,
start, stop );
printf( "Time to generate: %3.1f ms\n",
elapsedTime );
cudaEventDestroy( start );
cudaEventDestroy( stop );
//Compile_Environment:Microsoft Visual C++2010
#include stdio.h
#include Windows.h
//该头文件不能少,且需在Winbase.h前
#include
#include
#include Winbase.h //该头文件不能少
void main()
{
LARGE_INTEGER
litmp;
LONGLONG
QPart1,QPart2;
double
dfMinus,
dfFreq,
dfTim;
QueryPerformanceFrequency(&litmp);
//获得计数器的时钟频率
dfFreq
=
(double)litmp.QuadPart;
QueryPerformanceCounter(&litmp);
//获得初始值
QPart1
=
litmp.QuadPart;
QueryPerformanceCounter(&litmp);
//获得终止值
QPart2
=
litmp.QuadPart;
dfMinus
=
(double)(QPart2-QPart1);
dfTim
=
dfMinus
/
dfFreq;
printf( "Time
to run this program is %f CPU_Clock\n",dfMinus);
printf( "Time
to run this program is %f seconds\n",dfTim);
}
{
}