GPU Programming

Introduction to GPU programming with Nvidia CUDA

Featured image

(The illustrations used are from Pierre-François Bonnefoi’s course, source: https://p-fb.net/master1/gpgpu/cours/cuda.pdf)

About GPU Programming

GPU programming (or GPGPU—General-Purpose computing on Graphics Processing Units) aims to harness the computational power of graphics cards for tasks that are massively parallelizable.

While a CPU is primarily dedicated to handling rapid, sequential tasks, graphics cards offer a programming architecture that is highly conducive to parallelism. Nvidia pioneered this field; since 2007, the company has been developing a hardware interface and a C-based programming language known as CUDA (Compute Unified Device Architecture).

CUDA? How does it work? 🤔

With CUDA, the CPU architecture (referred to as the Host) is separated from the GPU architecture (referred to as the Device). The host has its own RAM containing its programs and variables, whereas the GPU is responsible only for executing the specific portion of the code assigned to it, known as the kernel. The two architectures exchange data via a PCI bus.

CPU / GPU Exchange - PFB

The CPU therefore retains control over both architectures:

So, what does a GPU look like?

That’s not an easy question to answer, my friend!

GPU Architecture

In GPU programming:

In CUDA, memory is structured similarly, but hierarchically:

There is also the concept of a warp within a block (a warp being a group of 32 synchronized threads); if you’d like to learn more, I encourage you to check out Pierre-François Bonnefoi’s course 😉: https://p-fb.net/master1/gpgpu/cours/cuda.pdf

Uses of GPU Programming

Naturally, the most well-known application of GPU programming is in the fields of video games and special effects.

However, it is also used in the scientific community: by providing greater computing power than a CPU, it enables simulations, analysis, and data processing to be performed in much more reasonable timeframes!

During my CRYPTIS Master’s program (and thus in the context of RSA cryptography), I developed CUDA programs capable of cracking the prime factorization of massive numbers. 😉