问题描述
因此,我尝试着手进行GPU编程,并使用Thrust库简化事情。 我已经创建了一个可以使用它的测试程序,并查看它如何工作,但是,每当我尝试创建非零大小的推力:: device_vector时,该程序就会因“运行时检查失败#3-变量'结果”而崩溃正在使用而未初始化。” (这来自allocator_traits.inl文件)而且...我不知道如何解决此问题。 以下是导致此错误的所有必要条件。
#include <thrust/device_vector.h>
int main()
{
int N = 100;
thrust::device_vector<int> d_a(N);
return 0;
}
我怀疑环境的设置可能有问题,因此有关细节... 使用Visual Studio 2019在CUDA 11.0 Runtime项目(打开此项目时给出的示例程序可以正常工作),Thrust 1.9版本和给定的GPU为GTX 970的情况下创建。
解决方法
此问题似乎仅在与CUDA 11.0相关的推力版本(1.9.x)时才体现出来,并且仅在Windows / Visual Studio上的调试项目中出现。
一些解决方法是切换到构建发行项目,或在运行时出现的对话框上单击“忽略”。根据我的测试,这允许在那时进行常规运行或调试。
我还没有确认,但是我相信这个问题已经在最新发布的thrust(1.10.x)中得到了解决(尽管目前还不是任何正式CUDA版本的一部分,但我希望它会将来的CUDA版本的一部分)。
,在罗伯特·克罗维拉(Robert Crovella)回答之后,我通过使用GitHub中的代码更改了推力库中的相应代码行来解决了此问题。更准确地说,在文件 ... \ CUDA \ v11.1 \ include \ thrust \ detail \ allocator \ allocator_traits.inl 中,我替换了以下函数
template<typename Alloc>
__host__ __device__
typename disable_if<
has_member_system<Alloc>::value,typename allocator_system<Alloc>::type
>::type
system(Alloc &)
{
// return a copy of a default-constructed system
typename allocator_system<Alloc>::type result;
return result;
}
作者
template<typename Alloc>
__host__ __device__
typename disable_if<
has_member_system<Alloc>::value,typename allocator_system<Alloc>::type
>::type
system(Alloc &)
{
// return a copy of a default-constructed system
return typename allocator_system<Alloc>::type();
}