This repo contains a collection of CUDA examples that were first used for a talk at the Melbourne C++ Meetup.
- 00-hello-world.cu - Vector addition on a CPU; the hello world of the parallel computing
- 01-cuda-hello-world.cu - Vector addition using CUDA
- 02-cuda-hello-world-faster.cu - Vector addition using CUDA, with a CPU bottleneck removed
- 03-templates-device-ptr.cu - Using C++ templates to make device pointers safer
- 04-templates-device-mem.cu - More templates, allowing for scoped device memory
- 05-thrust-rand-vectors.cu - Using Thrust to add up random numbers
All examples can be compiled with nvcc
. Only 02-cuda-hello-world-faster.cu
requires an additional compiler option --expt-relaxed-constexpr
(at least, when compiled on Linux).
A Makefile has been included, so all examples can built using make
.
These are all based on examples found in the wild. 03 and 04, in particular, are based on code from Michael Gopshtein's CppCon talk, CUDA Kernels in C++. And examples 01 and 02 are based on the Vector Addition sample code included in the CUDA Toolkit.
This source code has been released into the public domain.