I'm trying to copy to constant memory. But I can not because of my misunderstanding of usage of cudaMemcpyToSymbol function. I'm trying to follow this
Here is some code
__device__ __constant__ double var1;
__device__ __constant__ int var2;
int main(){
//... some code here...
double var1ToCopy = 10.1;
int var2ToCopy = 1;
void * p1 = &var1ToCopy;
void * p2 = &var2ToCopy;
cudaStatus = cudaMemcpyToSymbol((void*)&var1,p1,sizeof(double),0,cudaMemcpyHostToDevice);
if (cudaStatus != cudaSuccess){
return -1;
}
cudaStatus = cudaMemcpyToSymbol((void*)&var2,p2,sizeof(int),0,cudaMemcpyHostToDevice);
if (cudaStatus != cudaSuccess){
return -1;
}
//... and some code here...
}
I know it is a very dumb question, but I have spent several hours googling an answer and did not had any success.
You don't need the ampersand on the symbol name. A symbol is not the same as a pointer or a variable.
Instead of this:
Do this:
I've also simplified the above call based on the fact that some of the parameters have defaults as indicated in the documentation.
Here's a fully worked example around a modfied version of your code (requires cc2.0+ GPU):