【发布时间】:2020-12-09 06:29:45
【问题描述】:
尝试使用thrust::copy 将数据从std::vector 复制到thrust::device_vector 时遇到以下错误:
tryThrustCopy.exe 中 0x00007FFD7FF43E49 处未处理的异常:Microsoft C++ 异常:内存位置 0x0000002CB3B9C8B0 处的thrust::system::system_error。发生了
我正在使用带有 Visual Studio 16、Visual C++ 2019(版本 14)、CUDA 11.0 的 Windows 10,我的 GPU 驱动程序版本是 455.41。
在Visual Studio的调试模式下报错。发布配置中的程序从命令行运行,但会在复制步骤终止。
这是我生成错误的代码。
main.cpp:
#include <vector>
#include <thrust/device_vector.h>
#include <thrust/copy.h>
#include <iostream>
#include "particle.h"
int main(int argc, char** argv)
{
std::vector<particle> particles(5);
particles.at(0).x += 1; // Do something to the host vector.
thrust::device_vector<particle> dParticles;
dParticles.resize(particles.size());
//Here comes the error.
thrust::copy(particles.begin(), particles.end(), dParticles.begin());
std::cout << "test 2 ends" << std::endl;
return 0;
}
粒子.h:
#ifndef __particle_h__
#define __particle_h__
class particle
{
private:
public:
particle() : x(0), y(0) {}
int x;
int y;
};
#endif
一般来说,我试图将粒子对象的宿主向量复制到设备向量。我还发现使用上述代码将整数向量 (vector<int>) 从主机复制到设备效果很好。
如果有人能指出我在哪里犯了错误,我真的很感激。我是 CUDA 的新手,因此也欢迎任何有关如何检查错误的建议。
【问题讨论】:
标签: c++ visual-studio cuda thrust