用于计算带宽的时间

时间:2011-02-22 07:24:14

标签: cuda

我试图找到我的代码使用的有效带宽对CUDA GEforce 8800 gtx最大值为86GB / s。我不知道现在是什么时候使用。目前我正在使用调用内核和我的指令之间的区别反对调用没有指令的内核。这是正确的方法吗?(我使用的公式是 - >有效bw =(字节读取+写入)/时间)

此外,我的内核调用开销非常糟糕(接近1秒)。有没有办法摆脱它?

2 个答案:

答案 0 :(得分:1)

您可以使用cuda事件对内核进行相当精确的计时。

//declare the events
cudaEvent_t start;
cudaEvent_t stop;
float kernel_time;

//create events before you use them
cudaEventCreate(&start);
cudaEventCreate(&stop);

//put events and kernel launches in the stream/queue
cudaEventRecord(start,0);
myKernel <<< config >>>( );
cudaEventRecord(stop,0);

//wait until the stop event is recorded
cudaEventSynchronize(stop);

//and get the elapsed time
cudaEventElapsedTime(&kernel_time,start,stop);

//cleanup
cudaEventDestroy(start);
cudaEVentDestroy(stop);

答案 1 :(得分:0)

有效带宽(GBps = ((Br + Bw)/ 10 ^ 9)/时间

Br =内核从DRAM读取的字节数

Bw =内核在DRAM中写入的字节数

时间 =内核占用的时间。

例如,您测试在GPU的DRAM中将2048x2048浮点矩阵(每个4个字节)从一个位置复制到另一个位置的有效带宽。公式为:

带宽,以GB / s = ((2048x2048 x 4 x 2)/ 10 ^ 9)/内核占用时间

这里:

2048x2048 (矩阵元素)

4 (每个元素有4个字节)

2 (一个用于读取,一个用于写入)

/ 10 ^ 9 将B转换为GB。