read error using texture to cuda array

when I malloc a cuda array with width and length on the device ,then bind a texture to the array,while i read the array using tex2D( ref,a,b ), (a,b is coordinate of the cuda array ,I convert them from int to float),but what I read from the array is always 0, or some strang num,not the num in the array.
(the filter mode and normalized mode are the default,in fact it is not need)
can someone tell me why

here is my code

host code
cudaArray *d_u; :(

texture<float,2,cudaReadModeElementType> uT;
cudaChannelFormatDesc uDesc = cudaCreateChannelDesc();
cudaMallocArray(&d_u,&uDesc,2050,2050 );
cudaMemcpyToArray(d_u,0,0,u, 20502050sizeof(float),cudaMemcpyHostToDevice);

device code

int ux = blockIdx.x * blockDim.x + threadIdx.x,
    uy = blockIdx.y * blockDim.y + threadIdx.y;


but the problem is r is not the value d_u(ux,uy) nor d_u(uy,ux)

thank you

golden boy

waiting for help…


Have you looked at the simpleTexture sample in the SDK?

The first parameter to cudaMallocArray must be a pointer to a “cudaArray”.

It also looks like you are allocating d_u on the host (malloc) and then overwriting the pointer with cudaMallocArray.

sorry ,i paste the wrong code,now i modify it

i have allocated d_u as cudaArray,but the problem is not righted

the same problem exists…

one more thing ,if under the emu mode, it seems i can get the reasonable value.

thank you. :)

How do you define the texture? Is it normalized? If so then tex2D is waiting for indexes between 0 and 1.

i try to set the normolized on and off, and also the clamp or wrap mode,but the result is not changed at all, or changed to very strange data. i don’t know what is the reason.

thank you.

is there someone meeted the same question with me ,or may i is wrong using the texture function,but what i do is under the sample of nv, or because my compute ability is 1.0…

thank you all

Make sure that the host pointer u is of type void*, here:
cudaMemcpyToArray(d_u,0,0,u, 20502050sizeof(float),cudaMemcpyHostToDevice);

I would suggest working on a small 2D array that can be dumped to the disk and examined. Then you can see at what stage the problem arises. There could be a problem, say, while copying host mem to device, texture access, or while you reading the value r.

Good luck!