Invalid device symbol when copying to CUDA constan

2020-04-08 13:46发布

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?

标签: cuda nvidia
1条回答
别忘想泡老子
2楼-- · 2020-04-08 14:37

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)));
查看更多
登录 后发表回答