18

主机是否完全等待设备完成其执行?例如,程序的结构如下

// 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 
4

1 回答 1

26

CUDA运行时的同步功能可以让你达到你想要的。

cudaDeviceSynchronize()

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

cudaStreamSynchronize(cudaStream)

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

于 2012-09-28T12:15:05.513 回答