CUDA + OpenCL Mandelbrot
Build:
# Build both
make
# Not both
make cuda
make openclRun:
# CUDA
./build/mandelbrot_cuda 1024 768
# OpenCL
./build/mandelbrot_opencl 1024 768Result: out/mandelbrot_cuda.ppm and out/mandelbrot_opencl.ppm. Open them using smth idk(ppm viewer)
!
Interactive viewer and recording
- Build the interactive OpenCL viewer:
make viewer_opencl- Viewer CLI (args):
widthheight— window size (default 800x600)zoom_per_frame— multiplicative zoom each frame (default0.98, <1 zooms in)pan_xpan_y— pan per frame in pixels (can be fractional; negativepan_xpans left)record_file— optional output filename (if provided, frames are piped toffmpeg)fps— optional recording framerate (default30)
Examples:
# Run interactive viewer (no recording)
./build/mandelbrot_viewer_opencl 1024 768 0.98
# Run and record to MP4 (zoom 0.98, pan left 0.5 pixels/frame, 30 fps)
./build/mandelbrot_viewer_opencl 1024 768 0.99 -0.5 -0.4 out/zoom.mp4 30Notes and tips
pan_x/pan_yare interpreted as pixels per frame and converted to complex-plane units by multiplying with the currentscale(initially3.0/width). So a value like-150is very large (moves the center by ~-150*scale on the first frame).- If the image becomes a flat color quickly, try:
- smaller zoom (e.g.
0.995), - smaller pan (e.g.
-0.5), - larger
maxIterin the host code to reveal deeper detail.
- smaller zoom (e.g.
- Recording requires
ffmpeginstalled and available in PATH.
Build/runtime notes:
- For CUDA you need the CUDA Toolkit and
nvccin PATH. - For OpenCL you need headers and a provider library (we include CUDA OpenCL headers and link to CUDA's
libOpenCLby default).