11 Directive-based GPU programming
This chapter covers
- Selecting the best directive-based language to use for running on your GPU
- Using directives or pragmas to quickly port your code to GPUs or other accelerator devices
- Optimizing the performance of your GPU application
There has been a scramble to establish standards for directive-based languages for programming for GPUs. The pre-eminent directive-based language, OpenMP, released in 1997, was the natural candidate to look to as an easier way to program GPUs. At that time, OpenMP was playing catchup and mainly focused on new CPU capabilities. To address GPU accessibility, in 2011 a small group of compiler vendors, Cray, PGI, and CAPS, along with Nvidia, joined to release the OpenACC standard, providing a simpler pathway to GPU programming. Similar to what you saw in chapter 7 for OpenMP, OpenACC also uses pragmas. In this case, OpenACC pragmas direct the compiler to generate GPU code. A couple of years later, the OpenMP Architecture Review Board (ARB) added their own pragma support for GPUs to the OpenMP standard.