gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:13:14 24 4
gpt4 key购买 nike

我是 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 ...

可以使用以下两个文件重现该项目。

测试.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 生成这些命令?

最佳答案

提前致歉,我没有足够的积分来添加评论,但我可以确认我的装备上的行为。这在我的机器上使用 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.

关于c++ - CMakeLists 问题:在 thrust::device_vector 上调用 resize() 时出现 bad_alloc 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37482446/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com