Skip to content

Repository files navigation

OpenCL-Sobel-Video-Optimization

Sobel Edge Detection

This repository contains a high-performance implementation of the Sobel Filter for real-time video processing, optimized for GPU architectures using OpenCL. The project documents the transition from a sequential CPU baseline to a highly optimized GPU kernel achieving over 138x speedup on the NVIDIA K20 (Alma Cluster).

The core objective was to maximize throughput for high-resolution video frames (~120 million operations/sec) by optimizing memory access patterns and hardware occupancy.

Performance Evolution

The project followed a 4-stage optimization roadmap. Benchmarks were conducted on the NVIDIA K20 (Alma Cluster) processing 200 frames of high-resolution video.

Implementation Strategy Avg. Kernel Time Speedup vs. CPU
CPU Baseline Sequential C++ 76.65 ms 1x
GPU Baseline Global Memory Access 0.867 ms 88.4x
Math Optimization native_sqrt & Relaxation 0.828 ms 92.6x
Local Tiling Local Memory (SRAM) 0.552 ms 138.8x

Key Optimization: Universal Tiling

The final iteration (kernel_3.cl) utilizes a Local Memory Tiling strategy.

  1. SRAM Utilization: By loading pixel "tiles" into shared local memory, the kernel eliminates redundant global memory reads for the 3x3 convolution window.
  2. Strided Loading: Replaced boundary branching with strided loops to ensure all threads in a warp participate in data loading, effectively eliminating warp divergence.
  3. Bandwidth Efficiency: This approach bypassed L1 cache throughput limits, achieving the peak theoretical performance of the hardware.

Repository Structure

  • filter_sobel.cpp: Original sequential CPU implementation for performance baselining.
  • host_3.cpp: Advanced OpenCL host code featuring command queue management, profiling via OpenCL events, and dynamic work-group scaling.
  • kernel_3.cl: Final optimized kernel using Local Memory (SRAM) tiling and strided memory access.
  • speed.txt: Comprehensive performance analysis across various Work-Group sizes (8x1 to 32x32).

Technical Concepts Demonstrated

  • Heterogeneous Programming: Managing Host (CPU) and Device (GPU) memory buffers.
  • Memory Hierarchy Tuning: Minimizing Global Memory latency through Local Memory (SRAM) caching.
  • Warp Divergence Mitigation: Using strided loads to ensure high SIMD efficiency.
  • Precision Trade-offs: Utilizing native_ math functions for hardware-level acceleration.

Build and Execution

Prerequisites

  • OpenCL Headers and ICD Loader
  • GCC with C++17 support

Compilation

g++ -O2 host_3.cpp -lOpenCL -o sobel_gpu

Execution

The host application is configured to process sequential PPM frames:

./sobel_gpu

Note: The host code dynamically loads the .cl source file. Ensure the kernel file is present in the same directory. Developed as part of the MSc Computer Science curriculum at the University of Vienna.

About

GPU-accelerated Sobel edge detection using OpenCL. Features a high-performance "Universal Tiling" implementation with local memory (SRAM) caching and strided loading, achieving a 138x speedup on NVIDIA K20 hardware.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages