大概程序框架如下:
unsigned int CurCounter=0;
unsigned int SumCounter=0;
cudaEvent_t start,stop;//用于计算当前kernel的执行进度
cudaEvent_t start1,stop1;//用于计算所有kernel时间
cudaEventCreate(&start);
cudaEventCreate(&stop);
cudaEventCreate(&start1);
cudaEventCreate(&stop1);
cudaEventRecord(start1,0);
for(…)
{
CurCounter=0;
cudaEventRecord(start,0);
kernel<<<…>>>(…);
cudaEventRecord(stop,0);
while( cudaEventQuery(stop) == cudaErrorNotReady ) { CurCounter++; }
SumCounter=CurCounter;
}
cudaEventRecord(stop1,0);
cudaEventSynchronize(stop1);
float elapseTime1;
cudaEventElapsedTime(&elapseTime1,start1,stop1);
cout<<“time to gennerate:”<<elapseTime1<<“ms”<<endl;
cudaEventDestroy(start);
cudaEventDestroy(stop);
cudaEventDestroy(start1);
cudaEventDestroy(stop1);
执行这段程序后(程序已退出)GPU的使用率会一直很高,请问一下这是什么原因?
还有一个问题:为了计算每个kernel的运行状态(即完成了百分之多少),我的想法是用CurCounter/SumCounter(上一次kernel的SumCounter基本可以等于本次的SumCounter),所得的比例就是当前kernel的完成的比例(在另一个CPU线程中计算),不知道这样合不合理?是否还有其他方法?