Chapter 2. Host programming: fundamental data structures

 

This chapter covers

  • Understanding the six basic OpenCL data structures
  • Creating and examining the data structures in code
  • Combining the data structures to send kernels to a device

The first step in programming any OpenCL application is coding the host application. The good news is that you only need regular C and C++. The bad news is that you have to become familiar with six strange data structures: platforms, devices, contexts, programs, kernels, and command queues.

The preceding chapter presented these structures as part of an analogy, but the goal of this chapter is to explain how they’re used in code. For each one, we’ll look at two types of functions: those that create the structure and those that provide information about the structure after it has been created. We’ll also look at examples that demonstrate how these functions are used in applications. These won’t be full applications like the matvec example in chapter 1. Instead, these will be short, simple examples that shed light on how these data structures work and work together.

Most of this chapter deals with complex data structures and their functions, but let’s start with something easy. OpenCL provides a unique set of primitive data types for host applications, and we’ll examine these first.

2.1. Primitive data types

2.2. Accessing platforms

2.3. Accessing installed devices

2.4. Managing devices with contexts

2.5. Storing device code in programs

2.6. Packaging functions in kernels

2.7. Collecting kernels in a command queue

2.8. Summary