[求助]使用3D纹理时遇到问题,想了2天没想通...

beyond071 2010-08-11 04:35:15
函数源码如下:
texture <unsigned short, 3, cudaReadModeElementType> tex;
cudaArray *d_volumeArray = NULL;

//随便写个空的kernel
__global__ void kernel()
{
unsigned int tid = threadIdx.x;
}

void initTex(unsigned short *pPrj, cudaExtent extent)
{
cudaChannelFormatDesc channelDesc = cudaCreateChannelDesc<unsigned short>();
cutilSafeCall( cudaMalloc3DArray(&d_volumeArray, &channelDesc, extent) );

// copy data to 3D array
cudaMemcpy3DParms copyParams = {0};
copyParams.srcPtr = make_cudaPitchedPtr((void*)pPrj, extent.width*sizeof(unsigned short), extent.width, extent.height);
copyParams.dstArray = d_volumeArray;
copyParams.extent = extent;
copyParams.kind = cudaMemcpyHostToDevice;
cutilSafeCall( cudaMemcpy3D(©Params) );

// set texture parameters
tex.normalized = false; // access with normalized texture coordinates
tex.filterMode = cudaFilterModeLinear; // linear interpolation
tex.addressMode[0] = cudaAddressModeClamp; // wrap texture coordinates
tex.addressMode[1] = cudaAddressModeClamp;
tex.addressMode[2] = cudaAddressModeClamp;

// bind array to 3D texture
cutilSafeCall(cudaBindTextureToArray(tex, d_volumeArray, channelDesc));

//随便执行一个空的kernel就在输出中看到cudaError内存错误
kernel<<<100, 256>>>();
}

//main中调用部分
int main()
{
//....
//载入数据
cudaExtent extent;
extent.width = 512;
extent.height = 512;
extent.depth = 4;

int volumeSize = extent.width * extent.height * extent.depth;
unsigned short *pPrj = (unsigned short*)malloc( sizeof(unsigned short) * volumeSize);

//从文件中读入数据岛pPrj中....

initTex(pPrj, extent);//使用cudaGetLastError或者是cudaThreadSynchronize都没能捕捉到错误
}


应用场景:我从文件中读入一个512*512*4的3D数据,是unsigned short格式的,要将其绑定到3D纹理上。然后在kernel中用tex3D访问。代码完全参考的是SDK中的simpleTexture3D和volumeRender的,只是数据的三维不再相等。

遇到问题:绑定过程中没有错误提示,到了kernel执行中(即使如上面的一个什么都不做的kernel),也会在输出中出现如下的错误提示:Texture3D.exe 中的 0x7c812afb 处最可能的异常: Microsoft C++ 异常: 内存位置 0x0012fa08 处的 cudaError。

求各位高手指点一下问题所在,非常感谢!
...全文
206 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
beyond071 2010-11-17
  • 打赏
  • 举报
回复
texture <unsigned short, 3, cudaReadModeElementType> tex;

tex.filterMode = cudaFilterModeLinear; // linear interpolation

纹理拾取的返回值类型是浮点型才能进行滤波
leo_3small 2010-11-17
  • 打赏
  • 举报
回复
自己仔细研究了一下,
具体的原因是out of memory
这是因为d_volumeArray 没有被释放。
在程序结束时加上
cutilSafeCall(cudaFreeArray(d_volumeArray));
就好了。
唉,看来良好的编程习惯很重要。
leo_3small 2010-11-16
  • 打赏
  • 举报
回复
同样的问题,求楼主详解!
tengwl 2010-08-13
  • 打赏
  • 举报
回复
lz的,是什么小错误啊?俺也学习学习。
beyond071 2010-08-12
  • 打赏
  • 举报
回复
可能是问题没水平... 没人愿意说, 是小错误 自己改掉了

589

社区成员

发帖
与我相关
我的任务
社区描述
CUDA™是一种由NVIDIA推出的通用并行计算架构,该架构使GPU能够解决复杂的计算问题。 它包含了CUDA指令集架构(ISA)以及GPU内部的并行计算引擎。
社区管理员
  • CUDA编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧