Skip to content

Latest commit

 

History

94 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cuda Mandelbrot 🔀

how to use cuda acceleration to compute mandelbrot set

The code is written for my rtx 4070s so there is no guarantee it will work on others gpus but it probably will work on every rtx 4000, i will take a closer look at portability in the future

you can select your architecture passing the -DCMAKE_CUDA_ARCHITECTURES=XX flag where XX is your cuda architecture.

GPU Series Compute Capability
RTX 40xx (Ada) 89
RTX 30xx (Ampere) 86
RTX 20xx (Turing) 75
GTX 16xx (Turing) 75
GTX 10xx (Pascal) 61, 62
GTX 900 (Maxwell) 50, 52

otherwise you can use nvcc -ls-arch changed to nvcc --list-gpu-arch in newer cuda sdk release to get a detailed list.

Build

mkdir -p build && cd build

cmake                         \ 
-DCMAKE_BUILD_TYPE=Release    \
-DCMAKE_CUDA_ARCHITECTURES=89 \
..

make -j`nproc --all`
./cuda
feh test.ppm

Note

nvidia has also recently dropped the support for various older gpu like gtx 950 etc. If you type cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_CUDA_ARCHITECTURES=52 You will get some random errors using latest versions of cuda sdk (es. on archlinux). (these errors are similar to this and this)

And if you type something like this:

cmake .. -DCMAKE_BUILD_TYPE=Release               \ 
         -DCMAKE_CUDA_ARCHITECTURES=52            \
         -DCMAKE_CUDA_COMPILER=/opt/cuda/bin/nvcc \
         -DCMAKE_CUDA_HOST_COMPILER=/usr/bin/g++-15

to please the compiler you will finally get an unsupported architecture error.

Learning resources

profiling, nvprof is a sort of compatibility layer to use old nvprof syntax, but most of nvprof flags are simply ignored by nsys

gpu profiling

nsys --help profile
nsys --help nvprof

# es.
nsys profile -o report.qdrep ./cuda 
nsys nvprof ./cuda 
nsys profile --stats=true ./cuda
nsys nvprof --print-gpu-trace ./cuda 

cpu profiling

perf stat -e task-clock,cycles,instructions,r1b1,r10e,stalled-cycles-frontend,stalled-cycles-backend,L1-dcache-load-misses,cache-misses ./cuda
perf stat -r 10 valgrind --tool=callgrind ./cuda
valgrind --tool=callgrind ./cuda
valgrind --tool=callgrind ./cuda | kcachegrind

dynamic analysis

valgrind --undef-value-errors=no --tool=memcheck --leak-check=yes --show-reachable=yes --num-callers=20 --track-fds=yes ./cuda

asm

objdump -S -M intel cuda | gedit - &
Copyright © 2025, Manu-sh, s3gmentationfault@gmail.com. Released under the MIT license.

About

cuda accelerated mandelbrot

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Contributors

Languages