Array interpolation

Hi,

I know CUDA but I’m new in OpenCL and I have a small question for you.
I have an array

unsigned char * my_array

representing in fact a 2D array of size W*H.
I want to interpolate this array.
Let me use the following notation:

my_array[r][c] = my_array[r*W+c]

What I want to do is to access in my kernel to my_array[r][c] where r and c are not integer.
So far, my kernel gets the value of the 4 neighbors and scale the values (linear interpolation).
But I think this is absolutely not optimal (bank conflict, non coalesced reads).

In CUDA, you just need to put your array in a CUDA texture.
If you ask then in your kernel to access the value on not integer indexes, CUDA will automatically linearly interpolate the array.
I want to do the same in OpenCL. Is there a way of doing it? Are the “image2d_t” the correct object to do?
Can you please help me on this?

Thanks!

Vincent

Yes.

Thanks for your answer but could you be more specific please :)
OpenCL image are for me relatively different from CUDA texture.
For instance, what are the normalized coordinates?
Which function to use to have the linear interpolation?
What sampler shoul I use?

Thanks :)

Vincent

I don’t know much about images as I don’t use them. Try checking OpenCL specifications document (at khronos web-site) and/or NVidia’s OpenCL programming guide. I guess you will find there all the information you need.

If I use the read_imagef function, the output is a normalized float, but it seems that I can have linear interpolation.
If I use the read_imageui function, the output is an interger and I cannot have linear interpolation (just nearest neighbor interpolation).

What sampler and what function should I use to have linear interpolation?

Many thanks,

Vincent

See the sampler_t documentation. Use the CLK_FILTER_LINEAR filter mode. read_imagef is the correct function to use even for integer images, as the interpolated result will be a float value. On the host side, create your image with an cl_image_format set to CL_LUMINANCE / CL_UNORM_INT8. That should do it.