我正在开发一款简单的cuda程序,其中我发现90%的时间都花在了一个语句上,即从设备到主机的cudamemcpy。该程序在600-700微秒内从主机传输了约2MB的数据,并在10毫秒内从设备复制回了4MB的数据。我的程序总共需要13毫秒的时间。我的问题是,为什么两个复制从设备到主机和从主机到设备之间存在不对称性?这是因为CUDA开发者认为复制回来的数据通常比较小吗?我的第二个问题是,是否有任何方法可以规避这个问题。
我使用的是Fermi GTX560图形卡,具有343个核心和1GB内存。
我使用的是Fermi GTX560图形卡,具有343个核心和1GB内存。
int main (int argc, char **argv) {
cudaFree(0);
....//cuda is initialized..
}
unsigned int timer;
cutCreateTimer(&timer);
cutStartTimer(timer);
//your code, to assess elapsed time..
cutStopTimer(timer);
printf("Elapsed: %.3f\n", cutGetTimerValue(timer));
cutDeleteTimer(timer);
kernel<<<numBlocks, threadPerBlock>>>(...);
cudaError_t err = cudaThreadSynchronize();
if (cudaSuccess != err) {
fprintf(stderr, "cudaCheckError() failed at %s:%i : %s.\n", __FILE__, __LINE__, cudaGetErrorString( err ) );
exit(1);
}
//now the kernel is complete..
cutStopTimer(timer);