复制到CUDA常量内存时,设备符号无效 [英] Invalid device symbol when copying to CUDA constant memory

查看:265
本文介绍了复制到CUDA常量内存时,设备符号无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序的几个文件在图像处理。因为图像的行和列数在做一些图像处理算法时不会改变,我试图将这些值放在常量内存中。我的应用程式如下:

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

}

它编译得很好,但是当试图运行程序时,我得到无效的设备符号cudaMemcpyToSymbol(& c_rows,& rows,sizeof(int))

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?

推荐答案

如果你的符号声明如下:

If your symbol is declared like this:

__constant__ int c_rows;

那么正确调用 cudaMemcpyToSymbol

int rows = 5;
cudaMemcpyToSymbol(c_rows, &rows, sizeof(int)));

这篇关于复制到CUDA常量内存时,设备符号无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆