BRabbit27
BRabbit27

Reputation: 6623

Invalid device symbol when copying to CUDA constant memory

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?

Upvotes: 5

Views: 7343

Answers (1)

talonmies
talonmies

Reputation: 72349

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)));

Upvotes: 11

Related Questions