Julia set on GPU CUDA by example

Hello.

Today, I try to understand device , host from “CUDA by example”

In chapter 4. Have you ever compile “Julia_gpu.cu” and be able to run ?

I got :

C:\cuda_by_example\chapter04>nvcc julia_gpu.cu

julia_gpu.cu

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

4 errors detected in the compilation of "C:/Users/7-64/AppData/Local/Temp/tmpxft

_000010bc_00000000-6_julia_gpu.cpp1.ii".

C:\cuda_by_example\chapter04>

What is wrong with my compiler ?

Looks like the operator overload function is not declared as device.
You can check the source file in which cuComplex is defined and add in the device keyword to the operator overload functions.

Thank you.

I will post my progress again.

I got the same problem and fixed it. Please check the Appendix D.1.1 of the “NVIDIA CUDA C Programming Guide” Version 4.0

There should be a device before the constructor, I changed the struct cuComplex to the following code and everything works OK now:

class cuComplex {

private:

    float   r, i;

public:

    __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);

    }

};

Arrh. I just know that cuComplex is a constructor.

It works.

Thank you hyqneuron and platinor.

I have to replace the 25th line from

cuComplex( float a, float b ) : r(a), i(b)  {}

to this

__device__ cuComplex( float a, float b ) : r(a), i(b)  {}

External Image