__shared__ and __constant__ variable and empty constructor

yes, the problem is that your class X is NOT allowed to have any element which contains a constructor through all layers.

So if Y has no constructor but an object of Z, Z is not allowed to have a constructor as well. Much work to get rid of all constructors.

Anyway, what I learned by working with CUDA, is to keep the class structure very very flat to avoid problems like this.

Also it speeds up your program if you are using a flat structure.

If you are completly stuck now, is it not possible to replace your copy constructors in the same way like i told you before? For example

struct Y

{

	int value;

	__host__ __device__ init() {};

	__host__ __device__ copyConstructor(Y& y)

	 {value = y.value}

};

struct X

{

	Y a, b;

	 __host__ __device__ init()

	{

		a.init();

		b.init();

		b.copyConstructor(a);

	 }

};

Hi there. I’m currently using the CUDA 4.0 compiler.

The current status is that it supports structs/classes with empty constructors, but no members with empty constructors:

struct X 

{ 

    X() {}

};

struct Y

{

    Y() {}

    X x;

};

__shared__ X x; // ok, compiler detects empty c'tor

__shared__ Y y; // error, even though c'tor is empty

As far as I know, there really is no work-around if you need to overload the c’tor of Y.

However, if Y is POD (plain old data), you can change the class to a union and put the members in an anonyomous struct:

union Y

{

    struct { X x; }

};

__shared__ X x; // ok, compiler detects empty c'tor

__shared__ Y y; // ok, compiler detects empty c'tor

Hope that helps.

You can work around this restriction on shared variables with a small helper class [1].

[1] personal/demo.cu at master · jaredhoberock/personal · GitHub

bug reported 9 Dec 2013 (sid=402399)

10 Dec 2013 kkang confirms also in CUDA 5.5 (bug 402399)

Bill