Strange problem with cudaMemcpyToSymbol

Hi all,

I seem to have stumbled across a strange error with cudaMemcpyToSymbol. The problem is that I cannot copy data into an array on the device. Here is a test program that demonstrates what the problem is.

[codebox]#include <stdio.h>

constant float constData[2];

int main()

{

float data[2] = {1, 2};

cudaMemcpyToSymbol(constData, data, sizeof(data)); 

printf(“%f\n”, data[0]);

printf("%f\n", constData[0]);

return 0;

}[/codebox]

When I run this program in emulation mode, it appears that the floats are not copied into constData. The output that I get is:

1.0

0.0

What am I doing wrong? Is it because I’m running this in emulation mode? Or did I make some other mistake?

Thank a lot!

Check for errors after the memcpy

Right after the memcpy, I inserted:

cudaError_t err = cudaGetLastError();

printf(“%s\n”, cudaGetErrorString(err));

The result is that “no error” is printed.

you can’t read GPU memory directly from the host, so constData[0] actually has no meaning (or should segfault or something).

Yes, I know that – but shouldn’t it work in the emulator? If no, why not?

Edit: I played around with the code and ran it on the device – apparently expressions like constData[0] are meaningless in the emulator. Problem solved.