5

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?

talonmies
  • 70,661
  • 34
  • 192
  • 269
BRabbit27
  • 6,333
  • 17
  • 90
  • 161
  • Maybe I'm out of touch with CUDA these days but I thought hat `cudaMemcpyToSymbol` needed a string for the destination symbol name ? – Paul R May 11 '13 at 15:34
  • 1
    @PaulR: That was deprecated in CUDA 4 and removed in CUDA 5. Now a symbol is passed directly (which works because CUDA uses proper ELF headers and linker internally). – talonmies May 11 '13 at 15:39
  • @talonmies: thanks for confirming that I am out of touch. ;-) – Paul R May 11 '13 at 17:46

1 Answers1

11

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)));
talonmies
  • 70,661
  • 34
  • 192
  • 269