OpenCL Programming by Example
eBook - ePub

OpenCL Programming by Example

Ravishekhar Banger, Koushik Bhattacharyya

Share book
  1. 304 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

OpenCL Programming by Example

Ravishekhar Banger, Koushik Bhattacharyya

Book details
Book preview
Table of contents
Citations

About This Book

In Detail

Research in parallel programming has been a mainstream topic for a decade, and will continue to be so for many decades to come. Many parallel programming standards and frameworks exist, but only take into account one type of hardware architecture. Today computing platforms come with many heterogeneous devices. OpenCL provides royalty free standard to program heterogeneous hardware.

This guide offers you a compact coverage of all the major topics of OpenCL programming. It explains optimization techniques and strategies in-depth, using illustrative examples and also provides case studies from diverse fields. Beginners and advanced application developers will find this book very useful.

Beginning with the discussion of the OpenCL models, this book explores their architectural view, programming interfaces and primitives. It slowly demystifies the process of identifying the data and task parallelism in diverse algorithms.

It presents examples from different domains to show how the problems within different domains can be solved more efficiently using OpenCL. You will learn about parallel sorting, histogram generation, JPEG compression, linear and parabolic regression and k-nearest neighborhood, a clustering algorithm in pattern recognition. Following on from this, optimization strategies are explained with matrix multiplication examples. You will also learn how to do an interoperation of OpenGL and OpenCL.

"OpenCL Programming by Example" explains OpenCL in the simplest possible language, which beginners will find it easy to understand. Developers and programmers from different domains who want to achieve acceleration for their applications will find this book very useful.

Approach

This book follows an example-driven, simplified, and practical approach to using OpenCL for general purpose GPU programming.

Who this book is for

If you are a beginner in parallel programming and would like to quickly accelerate your algorithms using OpenCL, this book is perfect for you! You will find the diverse topics and case studies in this book interesting and informative. You will only require a good knowledge of C programming for this book, and an understanding of parallel implementations will be useful, but not necessary.

Frequently asked questions

How do I cancel my subscription?
Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
Can/how do I download books?
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Do you support text-to-speech?
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Is OpenCL Programming by Example an online PDF/ePUB?
Yes, you can access OpenCL Programming by Example by Ravishekhar Banger, Koushik Bhattacharyya in PDF and/or ePUB format, as well as other popular books in Informatica & Programmazione in C. We have over one million books available in our catalogue for you to explore.

Information

Year
2013
ISBN
9781849692342

OpenCL Programming by Example


Table of Contents

OpenCL Programming by Example
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers and more
Why Subscribe?
Free Access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Hello OpenCL
Advances in computer architecture
Different parallel programming techniques
OpenMP
MPI
OpenACC
CUDA
CUDA or OpenCL?
Renderscripts
Hybrid parallel computing model
Introduction to OpenCL
Hardware and software vendors
Advanced Micro Devices, Inc. (AMD)
NVIDIA®
Intel®
ARM Mali™ GPUs
OpenCL components
An example of OpenCL program
Basic software requirements
Windows
Linux
Installing and setting up an OpenCL compliant computer
Installation steps
Installing OpenCL on a Linux system with an AMD graphics card
Installing OpenCL on a Linux system with an NVIDIA graphics card
Installing OpenCL on a Windows system with an AMD graphics card
Installing OpenCL on a Windows system with an NVIDIA graphics card
Apple OSX
Multiple installations
Implement the SAXPY routine in OpenCL
OpenCL code
OpenCL program flow
Run on a different device
Summary
References
2. OpenCL Architecture
Platform model
AMD A10 5800K APUs
AMD Radeon™ HD 7870 Graphics Processor
NVIDIA® GeForce® GTC 680 GPU
Intel® IVY bridge
Platform versions
Query platforms
Query devices
Execution model
NDRange
OpenCL context
OpenCL command queue
Memory model
Global memory
Constant memory
Local memory
Private memory
OpenCL ICD
What is an OpenCL ICD?
Application scaling
Summary
3. OpenCL Buffer Objects
Memory objects
Creating subbuffer objects
Histogram calculation
Algorithm
OpenCL Kernel Code
The Host Code
Reading and writing buffers
Blocking_read and Blocking_write
Rectangular or cuboidal reads
Copying buffers
Mapping buffer objects
Querying buffer objects
Undefined behavior of the cl_mem objects
Summary
4. OpenCL Images
Creating images
Image format descriptor cl_image_format
Image details descriptor cl_image_desc
Passing image buffers to kernels
Samplers
Reading and writing buffers
Copying and filling images
Mapping image objects
Querying image objects
Image histogram computation
Summary
5. OpenCL Program and Kernel Objects
Creating program objects
Creating and building program objects
OpenCL program building options
Querying program objects
Creating binary files
Offline and online compilation
SAXPY using the binary file
SPIR – Standard Portable Intermediate Representation
Creating kernel objects
Setting kernel arguments
Executing the kernels
Querying kernel objects
Querying kernel argument
Releasing program and kernel objects
Built-in kernels
Summary
6. Events and Synchronization
OpenCL events and monitoring these events
OpenCL event synchronization models
No synchronization needed
Single device in-order usage
Synchronization needed
Single device and out-of-order queue
Multiple devices and different OpenCL contexts
Multiple devices and single OpenCL context
Coarse-grained synchronization
Event-based or fine-grained synchronization
Getting information about cl_event
User-created events
Event profiling
Memory fences
Summary
7. OpenCL C Programming
Built-in data types
Basic data types and vector types
The half data type
Other data types
Reserved data types
Alignment of data types
Vector data types
Vector components
Aliasing rules
Conversions and type casts
Implicit conversion
Explicit conversion
Reinterpreting data types
Operators
Operation on half data type
Address space qualifiers
__global/global address space
__local/local address space
__constant/constant address space
__private/private address space
Restrictions
Image access qualifiers
Function attributes
Data type attributes
Variable attribute
Storage class specifiers
Built-in functions
Work item function
Synchronization and memory fence functions
Other built-ins
Summary
8. Basic Optimization Techniques with Case Studies
Finding the performance of your program?
Explaining the code
Tools for profiling and finding performance bottlenecks
Case study – matrix multiplication
Sequential implementation
OpenCL implementation
Simple kernel
Kernel optimization techniques
Case study – Histogram calculation
Finding the scope of the use of OpenCL
General tips
Summary
9. Image Processing and OpenCL
Image representation
Implementing image filters
Mean filter
Median filter
Gaussian filter
Sobel filter
OpenCL implementation of filters
Mean and Gaussian filter
Median filter
Sobel filter
JPEG compression
Encoding JPEG
OpenCL implementation
Summary
References
10. OpenCL-OpenGL Interoperation
Introduction to OpenGL
Defining Interoperation
Implementing Interoperation
Detecting if OpenCL-OpenGL Interoperation is supported
Initializing OpenCL context for OpenGL Interoperation
Mapping of a buffer
Listing Interoperation steps
Synchronization
Creating a buffer from GL texture
Renderbuffer object
Summary
11. Case studies – Regressions, Sort, and KNN
Regression with least square curve fitting
Linear approximations
Parabolic approximations
Implementation
Bitonic sort
k-Nearest Neighborhood (k-NN) algorithm
Summary
Index

OpenCL Programming by Example

Copyright © 2013 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark informati...

Table of contents