Skip to content

Repository files navigation





Introduction to GPU programming with CUDA/HIP

CC BY-NC-SA 4.0

This short course will provide an introduction to GPU computing with CUDA aimed at scientific application programmers wishing to develop their own software. The course will give a background on the difference between CPU and GPU architectures as a prelude to introductory exercises in CUDA programming. The course will discuss the execution of kernels, memory management, and shared memory operations. Common performance issues are discussed and their solution addressed. Profiling will be introduced via the current NVIDIA tools.

The course will go on to consider execution of independent streams, and the execution of work composed as a collection of dependent tasks expressed as a graph. Device management and details of device to device data transfer will be covered for situations where more than one GPU device is available. CUDA-aware MPI will be covered.

The course will not discuss programming with compiler directives, but does provide a concrete basis of understanding of the underlying principles of the CUDA model which is useful for programmers ultimately wishing to make use of OpenMP or OpenACC (or indeed other models). The course will not consider graphics programming, nor will it consider machine learning packages.

Note that the course is also appropriate for those wishing to use AMD GPUs via the HIP API, although we will not specifically use HIP.

Attendees must be able to program in C or C++ (course examples and exercises will limit themselves to C). A familiarity with threaded programming models would be useful, but no previous knowledge of GPU programming is required.

Installation

For details of how to log into a Cirrus account, see https://cirrus.readthedocs.io/en/main/user-guide/connecting.html

Check out the git repository to your Cirrus account.

$ cd ${HOME/home/work}
$ https://github.com/EPCCed/archer-gpu-course.git
$ cd archer-gpu-course

For the examples and exercises in the course, we will use the NVIDIA compiler driver nvcc. To access this

$ module load gcc
$ module load nvidia/nvhpc

Check you can compile and run a very simple program and submit the associated script to the queue system.

$ cd section-2.01
$ nvcc -arch=sm_70 exercise_dscal.cu
$ sbatch submit.sh

The result should appear in a file slurm-123456.out in the working directory.

Each section of the course is associated with a different directory, each of which contains a number of example programs and exercise templates. Answers to exercises generally re-appear as templates to later exercises. Miscellaneous solutions also appear in the solutions directory.

Timetable

The timetable may shift slightly in terms of content, but we will stick to the advertised start and finish times, and the break times.

Day one

TimeContentSection
09:30Logistics, login, modules, local detailsSee above
10:00Introduction
Performance model; Graphics processorssection-1.01
10:30The CUDA/HIP programming model
Abstraction; host code and device codesection-1.02
11:00Break
11:30CUDA/HIP programming: memory managenent
cudaMalloc(), cudaMemcpy()section-2.01
12:15Executing a kernel
__global__ functions <<<...>>>section-2.02
13:00Lunch
14:00Some performance considerations
Exercise on matrix operationsection-2.03
15:00Break
15:20Managed memory
Exercise on managed memorysection-2.04
15:50Shared memory
16:10Exercise on vector productsection-2.05
16:30Constant memory
16:40All together: matrix-vector productsection-2.06
17:00Close

Day two

TimeContentSection
09:00Profiling: Nsight systems and compute
09:10Using nsys and ncusection-3.01
09:30Streams
Using cudaMempcyAsync() etcsection-4.01
10:00Graph API
Using cudaGraphLaunch() etcsection-4.02
11:00Break
11:30Device management: more then one GPU
cudaMemcpy() againsection-5.01
12:15Extra topic: GPU-aware MPI
Exercisesection-5.02
13:00Lunch
14:00Putting it all together
Conjugate gradient exercisesection-6.01
15:00Break
15:20Exercises
15:50Miscellaneous commentssection-7.01
16:00Close

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

CC BY-NC-SA 4.0

About

ARCHER Introduction to GPU Programming

Resources

Stars

46 stars

Watchers

8 watching

Forks

Releases

Packages

Used by

Contributors

Languages