You are previewing OpenCL Parallel Programming Development Cookbook.
O'Reilly logo
OpenCL Parallel Programming Development Cookbook

Book Description

Accelerate your applications and understand high-performance computing with over 50 OpenCL recipes

  • Learn about parallel programming development in OpenCL and also the various techniques involved in writing high-performing code

  • Find out more about data-parallel or task-parallel development and also about the combination of both

  • Understand and exploit the underlying hardware features like processor registers and caches that run potentially tens of thousands of threads across the processors

In Detail

OpenCL (Open Computing Language) is the first royalty-free standard for cross platform, parallel programming of modern processors found in personal computers, servers, mobiles, and embedded devices. OpenCL greatly improves speed and responsiveness for a wide spectrum of applications in numerous market categories, from gaming and entertainment to scientific and medical software. OpenCL has proved itself to be versatile in that it now runs on not only operating systems like Windows and Linux powered by Intel and AMD processors, but also on low power chips like ARM, and it has also been adopted by processor manufacturers like ARM Corp, Vivante, and Altera, among others.

OpenCL Parallel Programming Development Cookbook was designed to be practical so that we achieve a good balance between theory and application. Learning to program in a parallel way is relatively easy, but to be able to take advantage of all of the resources available to you efficiently is quite different. You need to be shown not only application, but also the theory behind it.

This book is roughly in two parts, where the first part is the fundamentals of OpenCL parallel development and the second part is the various algorithms we will explore with you. Each part is packed with many code samples and illustrations to demonstrate various concepts. The first part is essential for a beginner to not only program in parallel, but also to think in parallel and become equipped with the mental model with which to tackle parallel programming. The second part consists of seven different algorithms that the author has identified; you will learn various parallel programming techniques that experts have used in the past 60 years that are applicable to OpenCL.

This book will demonstrate how you think in parallel by illustrating and demonstrating programming techniques like data partitioning, thread coarsening, register tiling, data pre-fetching, and algorithm transformation. These techniques are demonstrated in the seven algorithms you’ll be shown, from image processing and solving sparse linear systems to in-memory sorting.

OpenCL Parallel Programming Development Cookbook combines recipes, illustrations, code, and explanations to allow you to learn the essentials of parallel programming in OpenCL, and the author has added in enough math so that the readers understand the motivation and can also lay the foundation upon which they will begin their own exploration.

Table of Contents

  1. OpenCL Parallel Programming Development Cookbook
    1. Table of Contents
    2. OpenCL Parallel Programming Development Cookbook
    3. Credits
    4. About the Author
    5. About the Reviewers
    6. www.PacktPub.com
      1. Support files, eBooks, discount offers and more
        1. Why Subscribe?
        2. Free Access for Packt account holders
    7. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Errata
        3. Piracy
        4. Questions
    8. 1. Using OpenCL
      1. Introduction
      2. Querying OpenCL platforms
        1. Getting ready
        2. How to do it…
        3. How it works…
      3. Querying OpenCL devices on your platform
        1. Getting ready
        2. How to do it…
        3. How it works…
      4. Querying for OpenCL device extensions
        1. Getting ready
        2. How to do it…
        3. How it works…
      5. Querying OpenCL contexts
        1. Getting ready
        2. How to do it…
        3. How it works…
      6. Querying an OpenCL program
        1. Getting ready
        2. How to do it…
        3. How it works…
      7. Creating OpenCL kernels
        1. Getting ready
        2. How to do it …
        3. How it works…
      8. Creating command queues and enqueuing OpenCL kernels
        1. Getting ready
        2. How to do it…
        3. How it works…
    9. 2. Understanding OpenCL Data Transfer and Partitioning
      1. Introduction
      2. Creating OpenCL buffer objects
        1. Getting ready
        2. How to do it…
        3. How it works…
      3. Retrieving information about OpenCL buffer objects
        1. Getting ready
        2. How to do it…
        3. How it works…
      4. Creating OpenCL sub-buffer objects
        1. Getting ready
        2. How to do it…
        3. How it works…
      5. Retrieving information about OpenCL sub-buffer objects
        1. Getting ready
        2. How to do it…
        3. How it works…
      6. Understanding events and event-synchronization
        1. Getting ready
        2. How to do it…
        3. There's more…
      7. Copying data between memory objects
        1. Getting ready
        2. How to do it…
        3. How it works…
      8. Using work items to partition data
        1. Getting ready
        2. How to do it…
        3. How it works…
    10. 3. Understanding OpenCL Data Types
      1. Introduction
      2. Initializing the OpenCL scalar data types
        1. Getting ready
        2. How to do it…
      3. Initializing the OpenCL vector data types
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
      4. Using OpenCL scalar types
        1. Getting ready
        2. How to do it…
        3. How it works…
      5. Understanding OpenCL vector types
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
      6. Vector and scalar address spaces
        1. Getting ready
        2. How to do it…
        3. How it works…
      7. Configuring your OpenCL projects to enable the double data type
        1. Getting ready
        2. How to do it…
        3. How it works...
    11. 4. Using OpenCL Functions
      1. Introduction
      2. Storing vectors to an array
        1. Getting ready
        2. How to do it…
        3. How it works…
      3. Loading vectors from an array
        1. Getting ready
        2. How to do it…
        3. How it works…
      4. Using geometric functions
        1. Getting ready
        2. How to do it…
        3. How it works…
      5. Using integer functions
        1. Getting ready
        2. How to do it…
        3. How it works…
      6. Using floating-point functions
        1. Getting ready
        2. How to do it…
        3. How it works…
      7. Using trigonometric functions
        1. Getting ready
        2. How to do it…
        3. How it works…
      8. Arithmetic and rounding in OpenCL
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
      9. Using the shuffle function in OpenCL
        1. Getting ready
        2. How to do it…
        3. How it works…
      10. Using the select function in OpenCL
        1. Getting ready
        2. How to do it…
        3. How it works…
    12. 5. Developing a Histogram OpenCL program
      1. Introduction
      2. Implementing a Histogram in C/C++
        1. Getting ready
        2. How to do it…
        3. How it works…
      3. OpenCL implementation of the Histogram
        1. Getting ready
        2. How to do it…
        3. How it works…
      4. Work item synchronization
        1. Getting ready
        2. How to do it…
        3. How it works…
    13. 6. Developing a Sobel Edge Detection Filter
      1. Introduction
      2. Understanding the convolution theory
        1. Getting ready
        2. How to do it…
      3. Understanding convolution in 1D
        1. How to do it...
        2. How it works…
      4. Understanding convolution in 2D
        1. Getting ready
        2. How to do it…
        3. How it works…
      5. OpenCL implementation of the Sobel edge filter
        1. Getting ready
        2. How to do it…
        3. How it works…
      6. Understanding profiling in OpenCL
        1. Getting ready
        2. How to do it…
        3. How it works…
    14. 7. Developing the Matrix Multiplication with OpenCL
      1. Introduction
      2. Understanding matrix multiplication
        1. Getting ready
        2. How to do it...
        3. How it works…
      3. OpenCL implementation of the matrix multiplication
        1. Getting ready
        2. How to do it…
        3. How it works…
      4. Faster OpenCL implementation of the matrix multiplication by thread coarsening
        1. Getting ready
        2. How to do it...
        3. How it works…
      5. Faster OpenCL implementation of the matrix multiplication through register tiling
        1. Getting ready
        2. How to do it
        3. How it works…
      6. Reducing global memory via shared memory data prefetching in matrix multiplication
        1. Getting ready
        2. How to do it...
        3. How it works…
    15. 8. Developing the Sparse Matrix Vector Multiplication in OpenCL
      1. Introduction
      2. Solving SpMV (Sparse Matrix Vector Multiplication) using the Conjugate Gradient Method
        1. Getting ready
        2. How to do it...
      3. Understanding the various SpMV data storage formats including ELLPACK, ELLPACK-R, COO, and CSR
        1. How to do it...
      4. Understanding how to solve SpMV using the ELLPACK-R format
        1. How to do it
        2. How it works
      5. Understanding how to solve SpMV using the CSR format
        1. Getting ready
        2. How to do it
        3. How it works
      6. Understanding how to solve SpMV using VexCL
        1. Getting ready
        2. How to do it
        3. How it works
    16. 9. Developing the Bitonic Sort with OpenCL
      1. Introduction
      2. Understanding sorting networks
        1. How to do it...
        2. How it works...
      3. Understanding bitonic sorting
        1. How to do it...
        2. How it works...
      4. Developing bitonic sorting in OpenCL
        1. Getting ready
        2. How to do it...
        3. How it works...
    17. 10. Developing the Radix Sort with OpenCL
      1. Introduction
      2. Understanding the Radix sort
        1. How to do it…
      3. Understanding the MSD and LSD Radix sorts
        1. How to do it…
        2. How it works…
      4. Understanding reduction
        1. How to do it…
        2. How it works…
        3. There's more…
      5. Developing the Radix sort in OpenCL
        1. Getting ready
        2. How to do it …
        3. How it works…
    18. Index