Why I got a cudaErrorInvalidSymbol

Any one can tell me what is wrong in the following code:

__constant__ float dm[9];

void func(float *DM)

{

		cudaError_t error=cudaMemcpyToSymbol((void *)dm,(void *)DM,sizeof(float)*9);

	if(error!=cudaSuccess)

	{

				cout<<error<<endl;

		cout<<"Copy dm[9] to constant memory failed"<<endl;

		exit(0);

	}

}

in the output, error=13 which means cudaErrorInvalidSymbol

Hi!

(void*)dm

is nonsense in host code, since the host doesn’t know the address of dm. Thats why there’s the the cudaGetSymbolAdress function in the runtime-lib.

The reference manual states:

So you can either call

cudaMemcpyToSymbol(dm,(void *)DM,sizeof(float)*9);

or

cudaMemcpyToSymbol("dm",(void *)DM,sizeof(float)*9);

.

Regards

Navier