Thrust是同步还是异步?

use*_*067 5 cuda thrust

我是新手使用Thrust,有一件事我不明白.Thrust是异步还是同步?

如果我写下面的代码,所用的时间不是0.但在其他标签中,其他用户报告的结果0.真相是什么?

clock_t start,end;

start=clock(); 
thrust::sort_by_key(vettore.begin(), vettore.end(), counter.begin()); 

end=clock();

double time=((double)(end-start))/CLOCKS_PER_SEC; 

cout<<"execution time"<<time<<endl;// the result is 0.327
Run Code Online (Sandbox Code Playgroud)

Arc*_*are 3

内核启动始终是异步的 - 即使在 CUDA 1.0 中 - 因此任何仅导致内核启动的 Thrust 调用都将是异步的。

正如 marina.k 所提到的,由于缺乏流支持,任何隐式触发 memcpy 的 Thrust 代码都将是同步的。

  • 例如,thrust::reduce() 绝对是同步的,因为它读回结果并通过返回值将其返回给调用线程。我在最近关于 Thrust 的博客文章中对这些限制发表了一些评论:http://developer.nvidia.com/content/expressive-algorithmic-programming-thrust (4认同)