【发布时间】:2015-09-03 08:51:04
【问题描述】:
我正在尝试使用最新版本 (7.0) 的 CUDA 和随附的 THURST 安装在 Visual Studio 2010 中构建和运行 Thrust 示例代码。我无法构建和运行示例代码。
通过删除部分代码,我发现问题出在thrust::sort(..) 调用上。宿主向量很好用,但设备向量会产生以下编译错误:
1>c:\program files\nvidia gpu 计算工具包\cuda\v7.0\include\thrust\system\cuda\detail\sort.inl(203): error C2027: use of undefined type '推力::detail::STATIC_ASSERTION_FAILURE'
这是我使用的无法编译的示例代码,这在很大程度上超出了https://developer.nvidia.com/Thrust 的 CUDA 信任示例
#include <thrust/host_vector.h>
#include <thrust/device_vector.h>
#include <thrust/generate.h>
#include <thrust/sort.h>
#include <thrust/copy.h>
#include <algorithm>
#include <cstdlib>
#include <time.h>
int main(void)
{
// generate 32M random numbers serially
thrust::host_vector<int> h_vec(32 << 20);
std::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 (This breaks the compile)
thrust::sort(d_vec.begin(), d_vec.end());
// sort data on the host (This works just fine)
thrust::sort(h_vec.begin(), d_vec.end());
// transfer data back to host
thrust::copy(d_vec.begin(), d_vec.end(), h_vec.begin());
return 0;
}
玩弄我发现如果你注释掉使用设备向量的那一行:
// thrust::sort(d_vec.begin(), d_vec.end());
但保留使用宿主向量的行:
thrust::sort(h_vec.begin(), d_vec.end());
它编译并运行得很好,虽然排序似乎在主机上运行。
如何编译和运行示例代码,以便在设备向量而不是主机向量上进行排序?
我的系统配置包括:
- 已安装 Visual Studio 2010 / SP1
- Windows 7 专业版,64 位
- CUDA 7.0 开发套件
- 带有最新驱动程序的 NVIDA Quadro K4000
【问题讨论】:
-
将文件扩展名更改为
.cu并使用nvcc编译。 -
一旦你解决了 Jared 指出的问题,你需要更改这一行,它不会编译:
thrust::sort(h_vec.begin(), d_vec.end());,可能最简单的方法是删除它,因为它对给定的程序。如果您想保留它,请将d_vec.end()更改为h_vec.end()。 -
在考虑构建过程之后,解决方案应该很明显,只需将文件名的扩展名更改为.cu(感谢Jared)。感谢您也指出了 type-o。
标签: c++ visual-studio-2010 sorting cuda thrust