Reputation: 25
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.
Upvotes: 0
Views: 1958
Reputation: 152164
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.
Upvotes: 1