O'Reilly logo

OpenCL Programming Guide by Dan Ginsburg, James Fung, Timothy G. Mattson, Benedict R. Gaster, Aaftab Munshi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 2. HelloWorld: An OpenCL Example

In order to introduce you to OpenCL, we begin with a simple example program. This chapter demonstrates the code required to set up and execute a kernel on an OpenCL device. The example executes a simple kernel that adds the values stored in two arrays and saves the result in another. This chapter introduces the following concepts:

• Choosing an OpenCL platform and creating a context

• Enumerating devices and creating a command-queue

• Creating and building a program object

• Creating a kernel object and memory objects for kernel arguments

• Executing a kernel and reading its result

• Checking for errors in OpenCL

This chapter will go over the basics of each of these steps. Later in the book, we will fill ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required