各位大大好
最近在寫程序時
使用了Event來測時
大致上的code是這樣
cudaEvent_t start, stop;
float runtime;
cudaEventCreate(&start);
cudaEventCreate(&stop);
cudaEventRecord(start, 0);
run_agent<<<109, 96>>>(d_a, d_b, d_c);
cudaEventRecord(stop, 0);
cudaEventSynchronize(stop);
cudaEventElapsedTime(&runtime, start, stop);
cudaEventDestroy(stop);
cudaEventDestroy(start);
printf("time:%fms\n", runtime);
測出來的時間約為5ms
但是後來改成for迴圈去跑
cudaEvent_t start, stop;
float runtime;
cudaEventCreate(&start);
cudaEventCreate(&stop);
cudaEventRecord(start, 0);
for(unsigned int k = 0; k < 10; k++) {
run_agent<<<109, 96>>>(d_a, d_b, d_c);
cudaThreadSynchronize();
}
cudaEventRecord(stop, 0);
cudaEventSynchronize(stop);
cudaEventElapsedTime(&runtime, start, stop);
cudaEventDestroy(stop);
cudaEventDestroy(start);
printf("time:%fms\n", runtime);
我也加上了cudaThreadSynchronize()去同步線程
但是測出來的時間居然是6.xms
我覺得很奇怪
正常來說不是應該要是剛剛的5ms * 10嗎?
因為線程同步的問題
至少啟動kernel的時間都已經超過6ms了
怎麼會只有6ms?
附註一下我的設備是
CPU:I5-2400
GPU:GTX560
請各位大大解答~感謝