where can we find Read_imagef() function definition

I am trying to convert a OpenCL application for CPU. Any idea about the way to go about it?

My very first idea is to convert the kernel to a loop, remove the device memory variables and other opencl builtin functions.

My OpenCL application use basic builtin function read_imagef().
Can anybody tell me that where does the definition of read_imagef() function lie? Can I view the source code of this library function?

Also I would like to know how exactly the runtime compilation happens for a opencl program.

Many thanks in advance!

read_imagef() is used to map integer image coordinates into real range from 0 to 1 (normalized coordinates). Consider a 1-dimensional texture of 10 pixels. To read the first pixel, you need to call read_imagef(0.0), or read_imagef(1.0) for the last one. A formula for accessing n-th pixel is (1.0 / (length - 1)) * (n-1): 0.0, 0.1111, 0.2222 etc. What will happen if you call read_image(0.15111)? It depends on the filtering mode: https://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/sampler_t.html . If mode is CLK_FILTER_LINEAR, it will return a weighted sum of pixels 2 and 3.

P.S. All you really need to do to convert your application to use CPU is to change device type during the initialization and install a CPU based OpenCL driver.

The OpenCL specification has a section that describes exactly what read_imagef does for every sampler type, including interpolation. It would not be hard to write a replacement (in fact, the CPU driver implements that since there isn’t hardware to do it). All pixel formats get mapped to float data (so unorm 8-bit, for example, maps 0 to 0.0 and 255 to 1.0). But like Salabar said, you could just use Intel’s (or AMD’s) CPU driver (on Windows), or Apple’s (on Mac).

Thank you very much Salabar and Dithermaster for the useful information.
Unfortunately, the target CPU for which I would be porting my code to, do not have an existing OpenCL driver. Hence I think the only options that remains for me is to write a replacement for read_imagef() and the rest of opencl code for my CPU.

Can you help me where can I find an open source implementation of read_imagef() and other builtin functions. As you said that the OpenCL driver includes the definition for the built-in functions, are there any open source driver available for OpenCL for either Intel/AMD/Apple?

There is a LGPL driver, but I don’t know if it is complete. https://code.google.com/p/freeocl/ (And I assume it already moved somewhere, It’s a link from Wikipedia).

Also, this: https://github.com/jrprice/Oclgrind (It’s a handy debugging tool, but it has an SPIR interpreter that could help).

Thanks Salabar… Your information was helpful and got me going ahead.