Last updated: December 21, 2018
OpenCL Framework: Right for You?
OpenCL, or Open Computing Language, is a software framework designed exclusively for building applications that can be run across diverse computer systems. It is an open standard for developing cross-platform, parallel programming applications, which has a number of open-source implementations.
Essentially, OpenCL was developed to allow coders to create applications that can be run on any device, regardless of manufacturer, processor specifications, graphics unit, or other hardware components. That means a developer can build an application on their Windows PC and it will work just as well on an Android phone, Mac OS X computer, or any other parallel processing device. Provided, of course, that all of these devices support OpenCL and have the appropriate compiler and runtime library implemented.
The programming language used to develop OpenCL applications is OpenCL C, which is based on C99 (the previous official definition of the C programming language). OpenCL C can program a range of hardware and devices, including CPUs, GPUs, and hardware accelerators.
OpenCL was first developed by Apple Inc, and then refined with input from several major hardware developers and proposed to the non-profit organization, the Khronos Group. The Khronos Group created an open standards committee with active participation from several major technology vendors to finalize the OpenCL standards.
Technical standards were finalized in late 2008, and in 2009 Apple released OpenCL 1.0 with their Mac OS X Snow Leopard. During 2008 and 2009, OpenCL was officially embraced by AMD, NVIDIA, and IBM.
Several new features and refinements were introduced in 2010 and 2011, and in 2013 OpenCL 2.0 was released, which included, amongst other things, support for shared virtual memory, nested parallelism, and a client driver extension for Android. A subsequent release in 2015, Open CL 2.1, replaced the OpenCL C kernel language with OpenCL C++.
As a new framework designed for one of the biggest trends in computer programming today, and being open source, it is no surprise that OpenCL has a large, activity community of users and mentors.
- Khronos Resource Page: the Khronos Group, responsible for maintaining OpenCL, have compiled a large list of resources for developers, including information about different implementations, language bindings, and the many libraries and frameworks available to OpenCL programmers. This same site also includes an extensive list of online training and guides.
- Reference Cards: these handy reference sheets contain everything you need to program in OpenCL, including an API guide, class diagram, shared virtual memory commands, and lists of available program objects, data types, built in functions, and more.
- Intel OpenCL Forums: this forum site is mostly visited by established OpenCL developers looking for programming advice, discussing best practices, and sharing ideas.
There are several online tutorials available for OpenCL, some created by the open source community, others developed by the many hardware manufacturers who contributed to the OpenCL standard. Since OpenCL is an advanced programming tool, most of them assume previous experience with application development and, typically, knowledge of C/C++.
- CodeProject’s OpenCL Tutorial: this online tutorial series provides extensive background into the OpenCL project, guides to installing the appropriate software to enable OpenCL development, and individual lessons for all the major areas of OpenCL programming. It includes several examples and additional links for background information.
- CMSoft OpenCL Tutorial: CMSoft offers both a general OpenCL tutorial and a series of case studies designed to cover a number of specialized projects, including the implementation of a general photo filtering algorithm which will work on any OpenCL-compatible GPU, tracking color in video, and how to use the GPU to multiply matrices.
- Intro OpenCL Tutorial: created by a hardware architect at AMD, this tutorial is written for brand new OpenCL programmers and walks them through the fundamentals of OpenCL, while providing plenty of coding examples.
Being a relatively new framework, there are only a handful of books on OpenCL, and many of them were written prior to the current version, meaning they won’t cover some of the latest features available to developers. However, even the older texts provide a good overview of the framework and its uses. An introduction of the latest developments can easily be obtained through many of the online resources listed above.
- Heterogeneous Computing with OpenCL 2.0 by David Kaeli, et al: this text aims to cover both the OpenCL standard and the general concept of parallel programming. It explores topics such as shared virtual memory, optimization techniques, debugging, and how to distribute work across a diverse system of computers. It includes several case studies as well as example code.
- OpenCL Programming Guide by Munshi, et al: this book is specifically written for working developers. Being one of the earliest OpenCL textbooks, written for version 1.1, it doesn’t cover some of the latest improvements. However, it still provides an effective overview of the OpenCL architecture and terminologies, basic programming features, and language tutorials for OpenCL C. This text also includes several case studies, examples, and online source code.
- OpenCL Parallel Programming Development Cookbook by Raymond Tay: this text takes the approach that to effectively learn a language, you need to understand both the theory behind it and practical applications. It breaks the learning down into two parts. The first half of the book covers the fundamentals of OpenCL and parallel programming. The second half is an exploration of key algorithms that demonstrate different parallel programming techniques.
- OpenCL Programming by Example by Banger and Bhattacharyya: This book aims to be the “easy” guide to OpenCL programming, using very simple examples to demonstrate key concepts of parallel programming and OpenCL.
Twenty years ago, when the vast majority of computer users all ran the same operating systems and the CPU/GPU scene was dominated by only a small handful of companies, having the ability to program across multiple platforms was a luxury most of us simply didn’t need. But with the launch of mobile technologies and the rise of Apple and Android, it is unlikely we will see any single producer holding that level of market share again soon. Instead, software developers need to adapt to today’s heterogeneous environment.
OpenCL is a major step in that transition. Rather than programming for each technology variable, developers can create code that reaches across platforms. One language, one framework, one environment, to program for several hardware and software specifications.
Further Reading and Resources
We have more programming guides, tutorials, and infographics related to coding and developer resources:
- C Developer Resources: get started and move into advanced areas of C programming.
- Cocoa and Cocoa Touch Introduction: learn the API for creating applications for Mac OS X and iOS.
- Java Introduction, How to Learn, and Resources: available on most devices, Java is a great language if you want to code for a large number of platforms.