无法创建推力设备矢量 [英] Unable to create a thrust device vector

查看:63
本文介绍了无法创建推力设备矢量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我尝试着手进行GPU编程,并使用Thrust库简化事情.我已经创建了一个可以使用它的测试程序,并查看它如何工作,但是,每当我尝试创建非零大小的推力:: device_vector时,该程序就会因运行时检查失败#3-变量'result"而崩溃正在使用而未初始化."(这来自allocator_traits.inl文件)而且...我不知道如何解决此问题.以下是导致此错误的所有必要条件.

So I'm trying to start on GPU programming and using the Thrust library to simplify things. I have created a test program to work with it and see how it works, however whenever I try to create a thrust::device_vector with non-zero size the program crashes with "Run-time Check Failure #3 - The variable 'result' is being used without being initialized.' (this comes from the allocator_traits.inl file) And... I have no idea how to fix this. The following is all that is needed to cause this error.

#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的情况下创建.

I suspect it may be a problem with how the environment is set up so the details on that are... Created using visual studio 2019, in a CUDA 11.0 Runtime project (the example program given when opening this project works fine, however), Thrust version 1.9, and the given GPU is a GTX 970.

推荐答案

在罗伯特·克罗维拉(Robert Crovella)回答之后,我使用GitHub中的代码更改了推力库中的相应代码行,从而解决了此问题.更准确地说,在文件 ... \ CUDA \ v11.1 \ include \ thrust \ detail \ allocator \ allocator_traits.inl 中,我替换了以下函数

Following the Answer of Robert Crovella, I fixed this issue by changing the corresponding lines of code in the thrust library with the code from GitHub. More precisely, in the file ...\CUDA\v11.1\include\thrust\detail\allocator\allocator_traits.inl I replaced the following function

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();
}

这篇关于无法创建推力设备矢量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆