cuda的julia集运行错误解决办法- 《cuda by examples》第四章例子



julia_gpu.cu(42): error: calling a host function("cuComplex::cuComplex") from a __device__/__global__ function("julia") is not allowed
julia_gpu.cu(43): error: calling a host function("cuComplex::cuComplex") from a __device__/__global__ function("julia") is not allowed
julia_gpu.cu(47): error: calling a host function("cuComplex::cuComplex") from a __device__/__global__ function("julia") is not allowed

julia_gpu.cu(47): error: calling a host function("cuComplex::cuComplex") from a __device__/__global__ function("julia") is not allowed

解决办法:

在构造函数前面加上__device__,即

struct cuComplex {
    float   r;
    float   i;
    __device__ cuComplex( float a, float b ) : r(a), i(b)  {}
    __device__ float magnitude2( void ) {
        return r * r + i * i;
    }
    __device__ cuComplex operator*(const cuComplex& a) {
        return cuComplex(r*a.r - i*a.i, i*a.r + r*a.i);
    }
    __device__ cuComplex operator+(const cuComplex& a) {
        return cuComplex(r+a.r, i+a.i);
    }
};

加完__device__ 后可能还会有如下错误:

无法打开文件“glut32.lib”

把glut32.lib 以及glut64.lib拷贝到C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\lib

把glut32.dll以及glut64.dll拷贝到C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin

成功运行图片如下:(跟网上其他人运行的结果不太一样- 有人知道为啥吗)cuda的julia集运行错误解决办法- 《cuda by examples》第四章例子_第1张图片


你可能感兴趣的:(cuda)