gpt4 book ai didi

cuda - 使用推力 device_vector 作为全局变量

转载 作者:行者123 更新时间:2023-12-02 02:19:40 33 4
gpt4 key购买 nike

为什么下面的代码在主程序结束时会崩溃?

#include <thrust/device_vector.h>

thrust::device_vector<float4> v;

int main(){
v.resize(1000);
return 0;
}

错误是:

terminate called after throwing an instance of 'thrust::system::system_error'
what(): unspecified driver error

如果我使用 host_vector 而不是 device_vector 代码运行正常。

您认为这是 Thrust 错误,还是我在这里做错了什么?

我在带有 cuda 4.0 的 ubuntu 10.10 和带有 cuda 6.5 的 Windows 7 上尝试过。两种情况下的 Thrust 版本均为 1.7。

谢谢

最佳答案

问题既不是 Thrust 中的错误,也不是您做错了什么。相反,这是 CUDA 运行时 API 设计的限制。

崩溃的根本原因是当变量超出范围时调用 thrust::vector 的析构函数,这种情况发生在 CUDA 运行时 API 上下文被拆除之后。这将产生运行时错误(可能是 cudaErrorCudartUnloading),因为进程在与 CUDA 驱动程序断开连接后尝试调用 cudaFree

除了不使用在 main() 翻译单元范围内声明的 Thrust 设备容器之外,我不知道还有其他解决方法。

关于cuda - 使用推力 device_vector 作为全局变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25547005/

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