Texture binding fails but don't know why Call to cudaBindTextureToArray fails during runtime

hello, I’m relatively new to CUDA and am having trouble using textures.

Specifically, my code compiles just fine, but during runtime, a call to cudaBindTextureToArray fails with the error: “invalid texture reference”.

The code up to that point is as follows:

texture<float, 2, cudaReadModeElementType> inputTexture; // located near beginning of file after #includes and #defines
… // code below located inside a function declared extern “C”

cudaChannelFormatDesc channelDesc;
cudaArray* cuArray;
float *zeroArray;
unsigned int timer = 0;


//Copy image data to a texture on the GPU
channelDesc = cudaCreateChannelDesc();
zeroArray = (float *) calloc ((ImgHeight + 2) * (ImgWidth + 2), sizeof (float));
CUDA_SAFE_CALL (cudaMallocArray(&cuArray, &channelDesc, (ImgWidth + 2) , (ImgHeight + 2)));
CUDA_SAFE_CALL (cudaMemcpy2DToArray(cuArray, 0, 0, zeroArray, (ImgWidth + 2) * 4, (ImgWidth + 2) * 4, ImgHeight + 2, cudaMemcpyHostToDevice));
CUDA_SAFE_CALL (cudaMemcpy2DToArray(cuArray, 4, 1, input, ImgWidth * 4, ImgWidth * 4, ImgHeight, cudaMemcpyHostToDevice));

CUDA_SAFE_CALL (cudaBindTextureToArray (inputTexture, cuArray)); // Program fails HERE!!
free (zeroArray);

Previously, I had very similar code working just fine, but for some reason, it’s not working any more.
things that have changed since I had working code:

  1. I’ve bought a larger monitor, a 23 inch LCD display with a 2048x1152 resolution. (I’m not sure if this has anything to do with my problems.)
  2. I’ve installed the CUDA Wizard for Visual Studio (available via a link somewhere in the CUDA forums.)

I would appreciate any advice, hints, thoughts…



Try to build in debug mode and run the debug version. That will activate the CUDA_SAFE macros and they may provide you with more insight.
I’m not sure about the extern C function and the effect that that declaration may have on nvcc, if any.

Thanks for the advice. Unfortunately, I already compile and run the code in debug mode and the only info I’ve managed to get is the fact that the texture binding fails. :-( If you have any other thoughts, I’d appreciate any advice.

Thanks in advance!

I met the same thing.
The code is ok with driver 177.84 and cude 2.0.
But when I update it to cuda2.1, cudaMemcpy2DToArray give me an unknow error.
It looks the new driver has bugs because cuda2.0 with 181 driver also make errors.
(WindowsXP32, GTS 512.)
Any input, please.