【问题标题】:Is Thrust synchronous or asynchronous?推力是同步的还是异步的?
【发布时间】:2012-06-20 09:39:06
【问题描述】:

我刚开始使用 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

【问题讨论】:

  • 注意:NVIDIA论坛here的相关问题。

标签: cuda thrust


【解决方案1】:

内核启动一直是异步的 - 即使在 CUDA 1.0 中也是如此 - 因此任何仅导致内核启动的 Thrust 调用都是异步的。

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

【讨论】:

  • 例如,thrust::reduce() 肯定是同步的,因为它读回结果并通过返回值将其返回给调用线程。我在最近关于 Thrust 的博客文章中对这些限制做了一些 cmets:developer.nvidia.com/content/…
【解决方案2】:

clock() 函数的粒度并不像您在 Windows 中想象的那么好。而在 Windows XP 中,它的粒度高达 16 毫秒。

使用高分辨率计时器或 Cutil 库的计时函数(通常是首选)代替使用 clock()。

关于Windows中高分辨率计时器的讨论: C++ high precision time measurement in Windows

关于 CUtil 库用于计时的讨论: CUDA: CUtil timer - confusion on elapsed time

【讨论】:

    【解决方案3】:

    您可以手动将 time.h 添加到索引器中,转到 Preferences -> C/C++ -> Indexer 并将其放在现有的“要预先索引的文件”前面,如下所示:

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

    它会工作

    【讨论】:

      猜你喜欢
      • 2020-05-15
      • 2020-02-21
      • 2013-02-25
      • 2012-12-30
      • 2014-04-25
      • 1970-01-01
      • 1970-01-01
      • 2019-01-17
      • 2017-06-22
      相关资源
      最近更新 更多