
Chapter 3. OpenCL Buffer Objects
In the previous chapter we discussed about the OpenCL Architectural models, and also understood the device context and command queue creation. This forms the first step towards the OpenCL language programming. In Chapter 1, Hello OpenCL, we implemented a simple saxpy
OpenCL example, which created memory objects (buffers in this case) and the kernel performed the saxpy
operation on these buffers. These memory objects were created and transferred to and from the device's memory. Computations were performed on these memory objects by every instance of the kernel execution created in the NDRange. OpenCL memory objects form the most fundamental architectural unit in the OpenCL programming.
In this chapter we will study the OpenCL buffer memory object and the functions and characteristics related to these buffer objects. This is referred to as the cl_mem
object for contiguous memory locations. We will discuss the following in this chapter:
- Create buffer objects
- Create subbuffer objects
- Use these buffer objects to compute the image histogram
- Transferring the buffer data to and from the device
- Mapping and querying the buffer objects
Besides this there is another form of OpenCL cl_mem
object called the image buffer. The image buffer represents the various raw formats of an image. We will discuss the image objects in the next chapter.