0

I try to pass struct array to constant memory, but I have same problems. First of all, my struct is:

#define point_size 1024

struct Point {
    short x;
    short y;

    Point (short xx, short yy){
        x = xx;
        y = yy;
    }

    Point (){
        x = 0;
        y = 0;
   }
};

When i use following declaration, I get a compile error: can't generate code for non empty constructors or destructors on device

__constant__ Point points_once[point_size];

The weird side of this when I use the follwing declaration, it's gone. But, it is not valid for me.

__constant__ Point *points_once[point_size];

How can I solve this problem. Thank for your help. I use latest driver and Visual Studio 2010 with compute_30 and sm_30 configuration.

2
  • Try defining the constructor as __host__ __device__ Point (){ x = 0; y = 0; } Commented Apr 19, 2013 at 7:17
  • I try, but I get same error. Commented Apr 19, 2013 at 7:22

1 Answer 1

1

This question is essentially a duplicate of this one. Please review the answer there for an explanation of why this is happening.

As a work-around, you could either use defined constants with direct assignment (i.e. not in a constructor) as discussed in the other answer, or you could simply omit the constructor initialization, and use a separate host based routine to initialize the __constant__ region with the values you desire using cudaMemcpyToSymbol.

Since an array of pointers do not actually allocate structure storage, the constructor is not called in your second example, and there is no issue, so you do not see the error message.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.