10 GPU programming model
This chapter covers
- Developing a general GPU programming model
- Understanding how it maps to different vendor’s hardware
- Learning what details of the programming model influence performance
- Mapping the programming model to different GPU programming languages
In this chapter, we will develop an abstract mental model of how work is performed on GPUs. This programming model fits a variety of GPU devices from different vendors and also across the models from each vendor. It is also a simpler model than what occurs on the real hardware, capturing just the essential aspects required to develop an application. Fortunately, various GPUs have a lot of similarities in structure. This is a natural result of the demands of high-performance graphics applications.
The choice of data structures and algorithms have long-ranging impact on the performance and ease of programming for the GPU. With a good mental model of the GPU, you can plan how data structures and algorithms map to the parallelism of the GPU. Especially for GPUs, our primary job as application developers is to expose as much parallelism as we can. With thousands of threads to harness, we need to fundamentally change the work so there are a lot of small tasks to distribute across the threads.