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

beyond071 beyond071 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
函数源码如下:
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。

求各位高手指点一下问题所在,非常感谢!
...全文

相关推荐

评论 5
收藏 已收藏
分享
返回顶部
beyond071
CUDA 591 成员 2,925 内容