Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Parallel Computing — CPU and GPU Optimization

Profiling and parallelizing a physics/graphics engine across CPU cores with OpenMP and the GPU with OpenCL, ending up with as much as a 34x speedup over the original.

Language OpenMP OpenCL Build

Overview

The starting point was a single-threaded engine. From there I profiled to find where the time was actually going, then applied optimizations one layer at a time — compiler vectorization first, then multicore CPU parallelism with OpenMP, and finally a GPU port with OpenCL. Measuring after each step made it clear which changes actually paid off.

Optimization stages

  1. Baseline: the single-threaded reference implementation
  2. Compiler and SIMD: -O3 -ftree-vectorize -ffast-math, with AVX2
  3. CPU multicore: OpenMP (-fopenmp) on the parallelizable loops
  4. GPU: an OpenCL kernel (parallel.cl) offloading the hot path

Results

Version Frametime (80x80 workload) Speedup
Optimized CPU 537 ms baseline
OpenCL GPU 69 ms about 7.8x over the optimized CPU version
End to end up to 34x over the original

Build

mkdir -p build && cd build
cmake ..
make
./parallel

Dependencies: OpenGL, GLUT, an OpenCL SDK, and an OpenMP-capable compiler.

Repository layout

├── parallel.c        host program (OpenMP plus OpenCL host code)
├── parallel.cl       OpenCL GPU kernel
├── CMakeLists.txt
└── build/

Skills demonstrated

OpenMP, OpenCL, GPU computing, SIMD and AVX2, performance profiling, CMake, C, and parallel algorithm design.

About

Physics-engine optimization with OpenMP and OpenCL — up to 34x speedup

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages