Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid device symbol when copying to CUDA constant memory

Tags:

cuda

nvidia

I have several files for an app in image processing. As the number of rows and colums for an image does not change while doing some image processing algorithm I was trying to put those values in constant memory. My app looks like:

Imageproc.cuh

...
...
__constant__ int c_rows;
__constant__ int c_cols;

#ifdef __cplusplus
   extern "C"
   {
#endif
   ...
   ...
#ifdef __cplusplus
   }
#endif

Imageproc.cu

...
...

int algorithm(float *a, const int rows, const int cols){
   ...
   ...
   checkCudaError(cudaMemcpyToSymbol(&c_rows, &rows, sizeof(int)));
   checkCudaError(cudaMemcpyToSymbol(&c_cols, &cols, sizeof(int)));

   dim3 block(T, T);
   dim3 grid(cols/T+1, rows/T+1);

   kernel<<<grid, block>>>( ... );
   ...
   ...

}

It compiles well but when trying to run the program I get invalid device symbol cudaMemcpyToSymbol(&c_rows, &rows, sizeof(int))

Can't I put those variables in constant memory or what am I missing?

like image 766
BRabbit27 Avatar asked May 11 '13 15:05

BRabbit27


1 Answers

If your symbol is declared like this:

__constant__ int c_rows;

then the correct call to cudaMemcpyToSymbol is just

int rows = 5;
cudaMemcpyToSymbol(c_rows, &rows, sizeof(int)));
like image 146
talonmies Avatar answered Sep 17 '22 01:09

talonmies