核函数中参数超过256byte 怎么办

定义了一个核函数,
global void kernel_orthCorrection( unsigned char* dev_inBuf, unsigned char* dev_outBuf, int nWid ,int nHei,int wid,int hei, DEM_Data dem, Boundary m_Boundary ,rMatrix bac,double M,double Xs,double Ys ,double Zs,
double x0,double y0,double f)

编译时提示【错误 55 error : Formal parameter space overflowed (256 bytes max) in function _Z21kernel_orthCorrectionPhS_iiii8DEM_Data8Boundary8tagX_ABCddddddd E:\OpenRs\desktop\src\plugins\orsImgRotation\cu_OrthoCorrection.cu 45

但这些参数又是必须的 ,不能去,怎么办呢

1、255B的限制好像是早起手册有提到,新手册没有提到过。不知道楼主用的是CUDA几点几的toolit?什么卡?什么编译选项(arch=compute_xx,code=sm_xx)?
2、以及不知道楼主自定义的DEM_Data和Boundary等等具体形式是什么养的,如果这些结构比较大,可以换做传入他们的指针,从而减少参数大小。
比如:
DEM_Data * d;
cudaMalloc((void**)&d,sizeof(DEM_Data));
global void kernel_orthCorrection(……,DEM_Date * d,……)
并在你内核中做相应的简单修开。

编译选项用的 compute_10,sm_10
cuda 用的5.0,还是有256byte 的限制

您先尝试下第二种办法吧~应该是有效的。第一个我们回头会测试一下。

以及,楼主可以更改下编译选项,改成compute_2x,sm_2x(或者3x)——如果你的卡不是1x的卡,请查看你卡的具体型号和计算能力进行恰当更改。
计算能力2x和3x的,都支持通过constant传递最大4KB参数。

LZ您好:

您这个问题,网友yixi回答基本上是正确的。

在CUDA C Programming Guide里面 Appendix.D C/C++ Language Support章节中有如下描述:

D.2.4 Functions
D.2.4.1 Function Parameters
global function parameters are passed to the device:
‣ via shared memory and are limited to 256 bytes on devices of compute capability 1.x,
‣ via constant memory and are limited to 4 KB on devices of compute capability 2.x and higher.

因此,如果您按照1.x计算能力编译代码,将会出现您1#提到的问题。

此时,如果您的GPU是目前的主流型号,那么可以根据您的实际情况按照您GPU的计算能力(2.x或者3.x)设置编译参数,将不再出现这个错误。

如果您确实需要在1.x版本的硬件上执行您的代码,请考虑yixi建议的将数据打包copy到global memory,然后传递一个指针给kernel作为参数的方法。

您的问题大致如此,供您参考。

祝您编码顺利~