Table Lookup, how to How does one implement an table Lookup like in the prog. guide p. 138

Hi,

I asked a similar question in an other topic, but I did not get answer I understood, so i tried rephrasing my problem a bit.
the question:
how can i implement an table lookup like in E3 page 138 in the 2.3 cuda programming guide(it is the very end) ?
you would help me best with some code lines

what i want to do is changing the resolution of an image, store in a cudaArray(2D), each pixel is a float4 value. a texture is bound to the array. I think it cant be that hard to use a gpu to change resolution.
just to make some things clear:

  1. i know how to use textures(a bit at least), i read the examples like simple texture and use them alot in my work, i just cant do THAT
  2. i know how to change the resolution the hard way, i am looking for an easy way using textures, as the programming guide suggests it is possible

i am looking forward to your answers.

Do you want to do upsampling or downsampling?

both, coming from a smaler to a larger resolution is easy, my question is basicly refering how one gets from a larger to a smaler resolution, thats probably downsampling(?)

It isn’t obvious what part of the process you don’t understand. The basic idea is to set up a filtering texture using normalized coordinates (which you say you know how to do) , then have the kernel read the texture using normalized coordinates which give you the image size you want. So if you were downsampling to 50x50, you would read all coordinates in a 50x50 unit grid - so {x,y} in {0, 1/49, 2/49, 3/49, …, 48/49, 1}, and write the values you get from the texture into a global memory array.

thanks for your answer. still not entirly sure, i think you put me on the right path. by “set up a filtering texture” do you mean linear filtering? if that is so basicly using normalized coordinates could do the trick?

Yes, use linear filtering (so cudaFilterModeLinear). You don’t have to use normalized coordinates, I used normalized coordinates only because I thought it might be more intuitive to understand. You can use the interpolation formula shown in Section E3 of the programming guide, which is what you were originally asking about. That is also why I am somewhat confused about the question in the first place: if you already understand how textures work, and you have already found the required interpolation formula to give you what you want from the programming guide, you have everything at your disposal to solve the problem.

Topic solved

I wasnt completly aware about the functionality of normalized textures. all it takes is a normalized texture and linear filter mode. an easy way to down sample could look like this:

texture<float4, 2, cudaReadModeElementType> orgtex;

orgtex.filterMode = cudaFilterModeLinear;
orgtex.normalized = true;

ScaleDown_tex_norm<<<scaledGridsize,blocksize>>>(smaller_image);

global void ScaleDown_tex_norm(Simagef4 out){
int x = (blockIdx.x * blockDim.x)+ threadIdx.x;
int y = (blockIdx.y * blockDim.y)+ threadIdx.y;

if(x < out.length && y < out.height){
	float xf = x/(float) out.length;
	float yf = y/(float) out.height;
	out.data[y*out.length+x] = tex2D(orgtex,xf,yf);	
}

}

thanks alot avviday!!!