invalid device symbol when copying to constant memory

Hi there,

I am trying to copy the contents of a host array to constant memory on the device. This is pretty simple, and there are lots of examples of how to do this in the Programmer’s Guide and various websites. A sample of my code is below:

[codebox]#define NUMBER_OF_PARTICLES 10

extern constant float particleMass_d[NUMBER_OF_PARTICLES];

cudaError_t e2 = cudaMemcpyToSymbol(particleMass_d, particleMass_h, sizeof(particleMass_h));

if (e2 != cudaSuccess)

{

printf(cudaGetErrorString(e2));

}[/codebox]

However, this code always returns an “invalid device symbol” cudaError_t. Any ideas why this might happen? I am using Cuda 2.1 on Ubuntu 64 bit with a Tesla C1060 card.

I have also tried a number of variants on this. I have prefaced particleMass_d with “device” as well as “constant”. I have tried “cudaMemcpyToSymbol(particleMass_d, particleMass_h, NUMBER_OF_PARTICLES*sizeof(float), 0, cudaMemcpyHostToDevice);”. I have also tried putting “particleMass_d” in quotes in the cudaMemcpyToSymbol function.

Thanks,

KPF

I see some problem in “sizeof(particleMass_h)”.

Can you try it.

[codebox]

cudaError_t e2 = cudaMemcpyToSymbol(particleMass_d, particleMass_h, sizeof(float) * NUMBER_OF_PARTICLES, 0, cudaMemcpyHostToDevice);

[/codebox]

:)

Yes, I have tried that as well, but I get the same results.

I think that the problem may occurs in your defined constant memory.

because your return error is “invalid device symbol”. It is means that constant memory is invalid.

Let define like this.

device constant float particleMass_d[NUMBER_OF_PARTICLES];

Great! That worked. Strange because I am sure I had tried that previously, but maybe something didn’t recompile as it should have.

Thanks,

KPF