CMakeLists问题:在thrust :: device_vector上调用resize()时出现bad_alloc错误

时间:2016-05-27 11:33:58

标签: c++ cuda cmake thrust

我是新手推动库并尝试在我的项目中使用它。这是一个非常简单的代码示例。它可以编译没有任何问题。但是,当我尝试运行它时,它会给我一个错误:

terminate called after throwing an instance of 'thrust::system::detail::bad_alloc'
what():  std::bad_alloc: unknown error

以及警告:

nvlink warning : SM Arch ('sm_20') not found in ...

可以使用以下两个文件复制项目。

TEST.CPP

#include <thrust/device_vector.h>
int main(){
    thrust::device_vector<int> x;
    x.resize(10);
}

的CMakeLists.txt

cmake_minimum_required(VERSION 2.8.9)
project(test_project)
find_package(CUDA QUIET REQUIRED)                                                                                                     
list(APPEND CUDA_NVCC_FLAGS "-std=c++11;-arch=compute_52")
set(CUDA_SEPARABLE_COMPILATION ON)
cuda_add_executable("cuda_test" "test.cu")

经过一些测试,显然如果删除“set(CUDA_SEPARABLE_COMPILATION ON)”行,程序运行没有问题。但我真的需要为我的项目激活可分离的编译。

任何帮助或提示都将不胜感激。

更新

@RobertCrovella要求,这里有更多的信息。

CUDA版本是7.5,它是使用GTX980在UBUNTU 14.04上新安装的。之后我没有更新Thrust库。

以下是cmake使用“make VERBOSE = 1”生成的实际命令。

CMake script with separable compilation

CMake script without separable compilation

更新2:

@merelyMark确认了同样的错误。由于代码和CMakeLists文件都非常简单,这是否可能是Thrust / CUDA中的错误? [编辑]没有。

更新3:

@RobertCrovella指出,推力库正常工作cmake comands。现在问题是:如何使用CMakeLists生成这些命令?

1 个答案:

答案 0 :(得分:1)

提前道歉,我没有足够的积分来添加评论,但我可以确认我的装备上的行为。这可以在我的机器上使用E5-1650 v3和配备CUDA 7.5和Ubuntu 14.04.3的Quadro M4000进行正确编译。我收到一个警告错误:

nvlink warning : SM Arch ('sm_20') not found in ...

我可以在运行时确认行为:

./cuda_test 
terminate called after throwing an instance of 'thrust::system::detail::bad_alloc'
  what():  std::bad_alloc: unknown error
Aborted (core dumped)

我同意@RobertCrovella,我不确定你在这里想要完成什么。

Here's my VERBOSE output for separable compilation.

Here's my VERBOSE output without separable compilation.

相关问题