Working with CUDA and PyCUDA

With this chapter, we begin our hands-on Python-based experience with GPUs via a computing approach. From this perspective, it is important to understand that a computing approach primarily focuses on computational problem-solving as a series of steps: problem outline, problem solution, programming the underlying solution to the problem, and, finally, testing its effectiveness. We will follow this approach for all our computing problems in this book that we try to solve through GPU-accelerated programming.

C programming enthusiasts will be encouraged to invoke NVIDIA GPUs within their program code with CUDA-C, while Python programming enthusiasts will be motivated to use PyCUDA to invoke NVIDIA GPUs within their program code. We first start by understanding how a CUDA-C program works. The fundamental concepts behind a CUDA program and its components will be discussed with some basic examples that will help you to transition toward a PyCUDA environment. PyCUDA will be explained with a practical approach and also will be compared to CUDA. We focus on the applicability preference of PyCUDA over CUDA pertaining to the simplicity and power of Python's syntax.

This chapter is divided into the following sections to facilitate the learning process: