This is the final project for the 2024 course of "High Performance Computing" of the Master degree "Quantum Engineering" at Politecnico di Torino.
Written in CUDA, the end result should be a CLI tool. Given a complex function (among a relative wide range of possibilities) and, optionally, the values of some options (width, height,fps, center, function parameters, etc.), such tool produces a video of the stream plot of the chosen function.
The general program flow is the following
- Initial particle positions are generated using Lloyd's algorithm
- The evolution of the particles is written on multiple canvases in order to parallelize writing on different OpenMP threads or CUDA thread blocks
- For each frame, the same pixel of each canvas are combined into a single pixel which is drawn into the frame buffer
- Frames are encoded into a mp4 file using ffmpeg
- Set the env variable
FFMPEG_PATH
to the path to the root library of ffmpeg (without trailing slash) - Be sure to have
CUDA
andCMake
available on your machine (e.g. by runningmodule load cmake nvidia/cudasdk
) - On Windows, you must use the MSVC compiler
- Create the build folder
- Run the following
cmake -DCMAKE_BUILD_TYPE=Release -S <source-directory> -B <build-directory> cmake --build <build-directory> --target HPC_project_2024 -j
- In case
nvcc
does not recognize the option-arch=native
or does not detect a CUDA capable device, please specify the environment variableGPU_ARCHITECTURE
with the name of the GPU architecture you want to compile for (e.g.export GPU_ARCHITECTURE=sm_75
for compute capability 7.5)
Full synopsis of the command, as well as all the available flags, can be seen by running the command without arguments.
HPC_project_2024 -R <resolution> -D <video-duration-seconds> -p <parallelization> -d <particle-distance> -L <lloyd-iterations> <function-name>
You can avoid recomputing the particle position through Lloyd algorithm by saving and then loading the particles to and from a file.
# save particles into particles.txt after 5 iterations of Lloyd algorithm
HPC_project_2024 -L 5:particles.txt <other-flags> <function-name>
# save particles into other_particles.txt after 8 iterations of Lloyd algorithm, and produce no video
HPC_project_2024 -D 0 -L 8:other_particles.txt <other-flags>
# load particles later
HPC_project_2024 -L particle.txt <other-flags> <function-name>
To get good results you should make sure that the screen resolution (-R
), space scale (-s
), and center point (-c
) of the command runs saving and loading particles match. However, this is not enforced.
This tool makes use of two libraries:
getopt
— Preinstalled on Linux. When compiling for Windows, a port ofgetopt
(taken from Chunde's repository) is injected.ffmpeg
— Once installed, the environment variableFFMPEG_PATH
must be specified with the path to the installation directory offfmpeg
. When building for Windows, be sure to add the${FFMPEG_PATH}/bin
directory in the PATH, so that dll can be used by the executable.
ncu -o <out_file> <command>
compute-sanitizer --tool memcheck --log-file <out_file> <command>