Initialising constant memory

When I try the following:

__constant__ float smoothingLength = h_epsilon*powf(particleMass/referenceDensity,(1.0f/3.0f));

It gives me the following compilation error:

/usr/include/c++/4.1.3/cstdlib(178): internal error: can't generate code for non empty constructors or destructors on device

1 catastrophic error detected in the compilation of "/tmp/tmpxft_0000235b_00000000-4_sphuniformgrid.cpp1.ii".

Compilation aborted.

Aborted (core dumped)

Is there any particular reason I can’t do this even though particleMass and referenceDensity are also constant values (written before the smoothingLength constant).

Obviously this would work in regular C, so I wanna know if there’s a workaround. (Other than to not put it into constant memory :P)


constant variables have to be filled with cudaMemCpyToSymbol as far as I know (they are in constant memory)

if h_epsilon is not a constant value, I can imagine that this will not work btw…

h_epsilon is in fact also constant :)

I’ll check out the cudaMemCpyToSymbol, but really I was hoping the compiler would take care of somthing like this for me :) Especially for constant memory.

What happens if you do:

const float temp = h_epsilon*powf(particleMass/referenceDensity,(1.0f/3.0f));

__constant__ float smoothingLength = temp;

This should force evaluation at compile time, or tell you why it can’t be done.

That actually sounded like a great idea, but unfortunately I got the exact same generic error :)

Oh well, I guess I’ll just do it manually for now.

It sounds like the compiler ignored the construct and optimized it out. What about ‘constant const float smoothingLength’ or ‘volatile const float temp’?