concept init_cl in category opencl

appears as: init_cl, The init_cl
OpenCL in Action: How to Accelerate Graphics and Computation

This is an excerpt from Manning's book OpenCL in Action: How to Accelerate Graphics and Computation.

Chapter 2 presented the six fundamental data structures used in OpenCL applications: cl_platform_id, cl_device_id, cl_context, cl_command_queue, cl_program, and cl_kernel. In basic_interop.c, the init_cl function creates and configures all six of these structures.

Most of the code in init_cl is similar to that used in host applications throughout this book. The main difference is the manner in which the cl_context structure is created. The following listing presents the code.

Listing 15.1. Creating the OpenGL-OpenCL context: basic_interop.c (abridged)

After the context is created, the init_cl function reads the text in basic_interop.cl and compiles it. Then it creates a cl_command_queue and a cl_kernel for the basic_interop function. Once these structures are created, the OpenCL initialization is complete and the application can start creating data objects.

The texture_filter application reads the image in the input.png file, filters the image with a sharpening filter, and displays the result as a texture. The goal of this section is to explain how this process works. Throughout this discussion, you’ll rely on the same five functions discussed in the last chapter: init_gl, init_cl, configure_shared_data, execute_kernel, and display.

16.2.2. The init_cl function

The init_cl function creates the primary OpenCL data structures used by the application: platform, device, context, program, command queue, and kernel. In texture_filter.c, this function also reads in pixels from the input image (input.png) and creates a two-dimensional image object to hold them. This is shown in the following code: