您的位置:首页 > 编程语言

关于CUDA编程中,常用运行速度对比函数总结

2019-02-28 14:08 246 查看

CPU程序计时程序(头文件#include<time.h>):

[code]LARGE_INTEGER litmp;	//####//用来计算cpu消耗时间
LONGLONG qt1,qt2;		//####
double dft,dff,dfm;		//####

QueryPerformanceFrequency(&litmp);	//####获得时钟频率
dff=(double)litmp.QuadPart;			//####
QueryPerformanceCounter(&litmp);	//####//获得初始值
qt1=litmp.QuadPart;					//####

需要计时的代码段

QueryPerformanceCounter(&litmp);	//####//获得终止值
qt2=litmp.QuadPart;					//####
dfm=(double)(qt2-qt1);				//####
dft=dfm/dff;						//####//获得对应的时间值

GPU程序计时程序(头文件#include<helper_timer.h>):

[code]StopWatchInterface * timer_cublas;  //****用来计算GPU核函数耗时
sdkCreateTimer(&timer_cublas);		//****
sdkStartTimer(&timer_cublas);		//****

需要计时的核函数

cudaThreadSynchronize();			//****
sdkStopTimer(&timer_cublas);		//****
double dSeconds = sdkGetTimerValue(&timer_cublas)/(1000.0f); //****

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: