推力异常:“thrust :: system :: system_error在存储器位置0x00000000” [英] Thrust exception: "thrust::system::system_error at memory location 0x00000000"

查看:2789
本文介绍了推力异常:“thrust :: system :: system_error在存储器位置0x00000000”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用类 device_vector 编写了一个CUDA内核 assign()的代码来初始化向量。这个内核由类成员函数作为问题的解决方案启动:

I wrote this code of a CUDA Kernel assign() using the class device_vector for initializing a vector. This kernel is launched by a class member function as a solution to the question:

CUDA内核作为类的成员函数

并根据

https:// devtalk.nvidia.com/default/topic/573289/mixing-c-and-cuda/

我使用的是GTX650Ti GPU,Windows 8.1 ,Visual Studio 2013 Community和CUDA Toolkit 7.5。

I'm using a GTX650Ti GPU, Windows 8.1, Visual Studio 2013 Community and CUDA Toolkit 7.5.

代码 initTest.cu

The code initTest.cu does compile but an exception is thrown making reference to the file trivial_copy.inl.

0x775B5B68的第一次机会异常 initTest.exe:Microsoft C ++异常:thrust :: system :: system_error在内存位置0x0116F3C8。
如果有这个异常的处理程序,程序可以安全地继续。

"First-chance exception at 0x775B5B68 in initTest.exe: Microsoft C++ exception: thrust::system::system_error at memory location 0x0116F3C8. If there is a handler for this exception, the program may be safely continued."

有人知道为什么会出现此问题吗?

Does anyone know why this problem occurs?

头文件 foo.cuh 是:

The header file foo.cuh is:

#ifndef FOO_CUH
#define FOO_CUH
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <thrust/device_vector.h>
#include <vector>
using namespace thrust;
using namespace std;

__global__ void assign(float *x, const float &constant, const unsigned int &n)
{
    int i = blockDim.x * blockIdx.x + threadIdx.x;
    if (i < n)
        x[i] = constant;
}
class foo
{
    public:
    foo(const unsigned int &);
    void init(const float &);
    vector<float> domain;
private:
    unsigned int samples;
};
foo::foo(const unsigned int &n)
{
    vector<float> result(n);
    domain = result;
    samples = n;
}
void foo::init(const float &value)
{
    device_vector<float> result(samples);
    assign <<< 1, domain.size() >>>(raw_pointer_cast(result.data()), value, samples);
    thrust::copy(result.begin(), result.end(), domain.begin());
}
#endif

em> initTest.cu 是:

and the main function defined in initTest.cu is:

#include "foo.cuh"
#include <iostream>

int main()
{
    foo a(10);
    a.init(0.5);
    for (unsigned int i = 0; i < a.domain.size(); i++)
    {
        if (i == 0)
            cout << "{ ";
        else if (i == a.domain.size() - 1)
            cout << a.domain[i] << " }";
        else
            cout << a.domain[i] << ", ";
    }
    cin.get();
    return 0;
}


推荐答案

p>

This is illegal:

__global__ void assign(float *x, const float &constant, const unsigned int &n)
                                             ^                             ^

内核参数不能通过引用传递。

Kernel parameters cannot be pass-by-reference.

当我删除&符号:

__global__ void assign(float *x, const float constant, const unsigned int n)

您的代码为我正确运行。

Your code runs correctly for me.

我建议您使用正确的cuda错误检查。这样做会把你的注意力集中在内核上。相反,错误未被捕获,直到推力检测到它,并抛出一个 system_error ,这无助于识别错误的来源。

I would suggest you use proper cuda error checking. Doing so would have focused your attention on the kernel. Instead, the error was uncaught until thrust detected it and threw a system_error, which doesn't help to identify the source of the error.

这篇关于推力异常:“thrust :: system :: system_error在存储器位置0x00000000”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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