Chapter 4. Kernel programming: data types and device memory

 

This chapter covers

  • Introducing a simple OpenCL kernel
  • Using OpenCL’s scalar and vector data types
  • Understanding the OpenCL device model

In this chapter, we’re going to put aside the scaffolding that creates and deploys kernels, and start coding the kernels themselves. We’ll examine the data types available in OpenCL kernels, and that means we’ll finally get to discuss vectors. When you process data with vectors, you put aside boring, decades-old data types like char, float, and int, and use new, exciting data types like char16, int3, and float4. Now we’re cooking!

I didn’t learn about vector programming until after I left college, but I’ve always enjoyed it since. It doesn’t matter whether it’s Intel’s Streaming SIMD Extensions (SSE), Motorola’s AltiVec, or the odd language IBM devised to program the Synergistic Processor Units (SPUs) on a Cell processor. I just find it gratifying to crunch several numbers with a single command, and my enjoyment increases when I crunch numbers on several cores at once. What more could anyone ask?

After examining different types of data, we’ll look at how and where this data is stored. OpenCL has a model for devices that includes four different address spaces. The final sections of this chapter will discuss these spaces and how to configure data storage in code.

4.1. Introducing kernel coding

4.2. Scalar data types

4.3. Floating-point computing

4.4. Vector data types

4.5. The OpenCL device model

4.6. Local and private kernel arguments

4.7. Summary

sitemap