Thrust ::排序很长的编译时间

时间:2011-05-19 16:02:27

标签: cuda thrust

我正在尝试使用Thrust编译一个示例代码块,以帮助学习一些CUDA。

我正在使用Visual Studio 2010,我还有其他编译示例。但是,当我编译这个例子时,编译需要花费10分钟。我有选择地注释掉了行,并发现它的Thrust :: sort行需要永远(有一行注释掉它需要大约5秒钟来编译)。

我在某个地方发现了一篇帖子,谈到了在Thrust中编译的速度很慢,这是Thrust开发团队做出的决定(它在运行时速度提高了3倍,但编译时间更长)。但那篇文章是在2008年末。

知道为什么这么长时间?

另外,我正在使用以下规格在机器上进行编译,因此它不是一台慢机器

i7-2600k @ 4.5 ghz
16 GB DDR3 @ 1833 mhz
配备6 GB / s 1TB驱动器0

根据要求,这是Visual Studio正在调用的构建字符串

C:\ Program Files \ NVIDIA GPU Computing Toolkit \ CUDA \ v3.2 \ bin \ nvcc.exe“-ccbin”C:\ Program Files(x86)\ Microsoft Visual Studio 9.0 \ VC \ bin“-I” C:\ Program Files \ NVIDIA GPU Computing Toolkit \ CUDA \ v3.2 \ include“-G0 --keep-dir”Debug \“ - maxrregcount = 32 --machine 64 --compile -D_NEXUS_DEBUG -g -Xcompiler”/ EHsc / nologo / Od / Zi / MTd“-o”Debug \ kernel.obj“”C:\ Users \ Rob \ Desktop \ VS2010Test \ VS2010Test \ VS2010Test \ kernel.cpp“-clean

实施例

#include <thrust/host_vector.h>
#include <thrust/device_vector.h>
#include <thrust/sort.h>
int main(void)
{
    // generate 16M random numbers on the host
    thrust::host_vector<int> h_vec(1 << 24);
    thrust::generate(h_vec.begin(), h_vec.end(), rand);
    // transfer data to the device
    thrust::device_vector<int> d_vec = h_vec;
    // sort data on the device
    thrust::sort(d_vec.begin(), d_vec.end());
    // transfer data back to host
    thrust::copy(d_vec.begin(), d_vec.end(), h_vec.begin());
    return 0;
}

1 个答案:

答案 0 :(得分:1)

CUDA 3.2中的编译器未针对使用调试模式(即sort)编译nvcc -G0等长而复杂的程序进行优化。在这种情况下,你会发现CUDA 4.0要快得多。删除-G0选项也会减少编译时间。