Book Image

OpenCL Parallel Programming Development Cookbook

By : Raymond Tay
Book Image

OpenCL Parallel Programming Development Cookbook

By: Raymond Tay

Overview of this book

<p>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.</p> <p>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.</p> <p>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.</p> <p>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.<br />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.</p>
Table of Contents (17 chapters)
OpenCL Parallel Programming Development Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Retrieving information about OpenCL buffer objects


To retrieve information about a buffer or sub-buffer object, you'll need to use the API clGetMemObjectInfo and its signature as in the following code:

cl_int clGetMemObjectInfo(cl_mem memobj,
                          cl_mem_info param_name,
                          size_t param_value_size,
                          void* param_value,
                          size_t* param_value_size_ret)

To query the memory object, simply pass the object to memobj specifying the type of information you want in param_name, inform OpenCL the size of the returned information in param_value_size and where to deposit it in param_value; the last parameter, param_value_size_ret, is largely optional but it returns the size of the value in param_value_size.

Getting ready

Here's an excerpt from the code in Ch2/buffer_query/buffer_query.c where it shows how to extract the information about the memory object, UDObj is encapsulated into a user-defined function displayBufferDetails...