CPU是否等待DEVICE完成其内核执行....?

时间:2012-09-28 11:55:59

标签: cuda

主机是否等待设备完全执行? 例如该程序具有以下结构

// cpu code segment

// data transfer from host to device

QUESTION - WILL CPU WAIT FOR DEVICE TO FINISH TRANSFER? IF NO, IS IT POSSIBLE? IF YES, HOW?

// kernel launch

QUESTION - WILL CPU WAIT FOR DEVICE TO LET IT FINISH KERNEL EXECUTION (CONSIDERING KERNEL EXECUTION WILL TAKE NOTABLE TIME say-5 sec)? IF NO, IS IT POSSIBLE? IF YES, HOW?

// data transfer from device to host

// program terminates after printing some information 

1 个答案:

答案 0 :(得分:18)

CUDA运行时的同步功能可以让你实现你想要的效果。

cudaDeviceSynchronize()

当您调用此函数时,CPU将等待设备完成其所有工作,无论是内存复制还是内核执行。

cudaStreamSynchronize(cudaStream)

此函数将阻止CPU,直到指定的CUDA流完成其执行。其他CUDA流将以异步方式继续执行。