2012-06-20 172 views
5

我刚刚使用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 
+0

注:NVIDIA论坛上的相关问题[这里](https://devtalk.nvidia.com/default/topic/864759/is-thrust-copy-synchrous-or-asynchronus-/)。 – BenC

回答

2

内核启动一直是异步的 - 即使是在CUDA 1.0 - 因此,任何推力通话仅造成内核启动将是异步的。

隐式触发memcpy的任何Thrust代码都是同步的,因为缺少流支持,正如marina.k所暗示的那样。

+3

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

0

你可以做到这一点的time.h中手动添加到索引,去首选项 - > C/C++ - >索引,并把它在现有的前面“的文件被编入索引的前期”是这样的:

time.h, cstdarg, stdarg.h, ..... 

它去上班

相关问题