CUDA Texture2D问题

时间:2012-12-28 10:50:59

标签: cuda

我无法从2D纹理中获取

texture<float2, cudaTextureType2D, cudaReadModeElementType> tex;
// ...
assert(cudaMallocPitch(&imgcov2_device, &pitch, sizeof(ComplexFloat)*x*y*z, N*N) == cudaSuccess);
cudaChannelFormatDesc channelDesc = cudaCreateChannelDesc<float2>();
tex.addressMode[0] = cudaAddressModeClamp;
tex.addressMode[1] = cudaAddressModeClamp;
tex.filterMode = cudaFilterModePoint;
tex.normalized = false;
assert(cudaBindTexture2D(NULL, tex, imgcov2_device, channelDesc, x*y*z, N*N, x*y*z*N*N*sizeof(ComplexFloat)) == cudaSuccess);
// ...
tmp = ComplexFloatAdd(tmp, ComplexFloatMul(y[j + i*N], tex2D(tex, blockIdx.x * blockDim.x + threadIdx.x, threadIdx.y + j*N))); //fetch

我确信tex2D的最后两个参数在[0,x*y*z-1][0,N*N-1]范围内。有人建议another post使用音调记忆,但我没有运气。有任何想法吗?可疑部分是当x y z = 90000,N N = 32 ^ 2时它不会失败但是当N N = 8 ^ 2时它不会失败。 ComplexFloat的类型定义为float2。只有提取失败。

1 个答案:

答案 0 :(得分:1)

将音高线性记忆绑定到2D纹理时,请始终使用cudaMallocPitch返回的音高作为cudaBindTexture2D的最后一个参数

在你的情况下,你会这样做:

cudaBindTexture2D(NULL, tex, imgcov2_device, channelDesc, x*y*z, N*N, pitch);