checkCudaErrors( cudaMemcpy2DToArray(d_imageArray, 0, 0, _data, pitch,imageWidth*sizeof(float),imageHeight, cudaMemcpyHostToDevice) );其中_data是vector<vector> *_data,当imageWidth和imageHeight比较小的时候运行成功,比较大的时候会崩溃,难道是CUDA数组有大小限制?
楼主您好,您的帖子已经阅读,但是我不是C++用户。不懂vector和模板的。
我建议您咨询下ZeHuanWang和PengWang,以及yyfn风辰,以及田园2008等版主/NV原厂支持。
版主,你好,请问一下怎么咨询他们?我刚刚注册~
他们长期驻版,您可以有如下方式:
(1)等待他们上线。
(2)主动联系他们,通过这个页面最上方的“消息”机制。
谢谢版主的推荐~
他们都没有回啊,不知道cuda数组有没有尺寸限制,我分别用二维vector和二维数组测试了,都是当尺寸比较大的时候就崩溃了,尺寸小的时候是可以运行成功的~
CUDA ARRAY是有大小限制的!Programming guide的F.1中有详细大小的限制,楼主可自行查看!
绑定到线性存储器或CUDA数组的二维纹
理参考的最大宽和高 为65535*32768 ,我的远没有超过这个限制啊,都不到10000
楼主把前面分配CUDA Array和GPU MEM的部分以及错误提示也发上来让大家看看吧,这样或许能更准确找到问题出在哪里!
extern “C”
void initTexture(/const/ int imageWidth, /const/ int imageHeight, vector<vector> *_data)
{
imageWidth =155;
imageHeight =400;
// imageWidth =1559;
// imageHeight =6001;
cudaChannelFormatDesc channelDesc = cudaCreateChannelDesc<float>();
checkCudaErrors( cudaMallocArray(&d_imageArray, &channelDesc, imageWidth, imageHeight) );
unsigned int size = imageWidth * imageHeight * sizeof(float);
float* devPtr;
size_t pitch;
cudaMallocPitch((void**)&devPtr, &pitch, imageWidth * sizeof(float), imageHeight);
checkCudaErrors( cudaMemcpy2DToArray(d_imageArray, 0, 0, _data, pitch,imageWidth*sizeof(float),imageHeight, cudaMemcpyHostToDevice) );
versclTex.addressMode[0] = cudaAddressModeClamp;
versclTex.addressMode[1] = cudaAddressModeClamp;
versclTex.filterMode = cudaFilterModeLinear;
// rgbaTex.normalized = false; // access with integer texture coordinates
versclTex.normalized = false;
getLastCudaError(“initTexture”);
// Bind the array to the texture
checkCudaErrors( cudaBindTextureToArray(versclTex, d_imageArray) );
}
请大家看看,原本数据大小是1559*6001,当把宽和高设小时,是可以运行的,大了就会崩溃。
不知道能不能直接拷贝二维vector
这里有个问题!
cudaMallocPitch里的参数pitch是指向设备分配出来对齐内存每行有多少个字节,而cudaMemcpy2DToArray里的pitch是指向数据源每行有多少个字节,你把这两个地方搞混了!
其实你可以直接cudaMemcpyToArray来代替cudaMemcpy2DToArray!
请问一下是二维的vector也可以用cudaMemcpyToArray吗?
如果你要用cudaMemcpy2DToArray的话,那就把pitch改成你_data一行有多少个字节然后试试看!
二维数组的话,如果是固定分配大小的数组,那样二维数组是连续存放在内存中的,可以直接cudaMemcpyToArray
如果是动态分配出来的。。。我没试过,不太清楚动态分配出的二维数组是否是在内存空间连续!
问题貌似找到了,二维vector不能直接当二维数组用,如果只是二维裸数组的话,貌似不管是不是动态分配都可以用cudaMemcpyToArray和cudaMemcpy2DToArray(pitch改成你_data一行有多少个字节),反正二维裸数组运行都没蹦~