# Performance Optimization of Object Tracking Algorithms in OpenCV on GPUs
## 2 Background and Motivation
### Previous Studies on Optimizing GPU Kernels for Computer Vision Algorithms  
Various studies have been presented to improve the throughput of computer vision algorithms, but most of them focused primarily on the algorithm itself. [PERSON] et al. [24] utilized multidimensional scaling for optimizing object tracking algorithms. This work optimized the algorithms used for infrastructure and object positioning using multidimensional scaling at the software framework level. [PERSON] et al. [25] accelerated object tracking queries by adapting video frame rates. This work applied a hybrid machine learning model consisting of a convolutional neural network and a graph neural network to resolve the object tracking failure problem at low frame rates. The above studies modified the algorithm for object tracking optimization, so they have the advantage of being independent of the hardware. However, optimal performance may not be achieved in systems with scarce hardware resources due to no consideration of the hardware resource level. \begin{table}
\begin{tabular}{l l l} \hline \hline
**Variable** & **Value** & **Device Limit** \\ \hline Device Info & & \\ \hline Device name & & \\ Number of compute units & & 8 \\ Max number of waves per compute unit & & 40 \\ Max number of work-groups per compute unit & & 40 \\ Wavefront size & & 64 \\ \hline Kernel Info & & \\ \hline Kernel name & & runLBPClassifierStumpSimple \\ Vector GPR usage per work-item & & 256 \\ Scalar GPR usage per work-item & & 102 \\ LDS usage per work-group & & 65,536 \\ Flattened work-group size & & 256 \\ Flattened global work size & & 6144 \\ Number of waves per work-group & & 4 \\ \hline Kernel Occupancy & & \\ \hline Number of waves limited by vector GPR and work-group size & 12 & 40 \\ Number of waves limited by scalar GPR and work-group size & 32 & 40 \\ Number of waves limited by LDS and work-group size & 40 & 40 \\ Number of waves limited by work-group size & 40 & 40 \\
**Limiting factor** & **VGPR** & \\ Estimated occupancy & & 30\% \\ \hline \hline \end{tabular}
\end{table} 
Table 2: Profiling results of the OpenCL kernel provided by the GPU profiler. Even for improving performance with accelerators such as a GPU, a major research topic is splitting and parallelizing the task of algorithms. [PERSON] et al. [4] presented a throughput optimization scheme for computer vision algorithms in embedded system environments and compared several hardware environments. [PERSON] et al. [26] optimized the Viola-Jones algorithm used for face detection provided by OpenCV. This work targeted processing images on mobile platforms. Although those studies have the advantage of considering scarce hardware resource environments, they regarded only software optimization without profiling hardware utilization. Moreover, most research applied well-known optimization methods to improve the GPU's performance, such as leveraging local memory, loop unrolling, vectorization [3,27,28], etc. [PERSON] et al. [3] optimized gesture recognition in OpenCV running on embedded heterogeneous multicore systems. However, the proposed techniques focused on optimizing the algorithm by applying such well-known optimization methods mentioned above without profiling hardware utilization. The following are typical OpenCL kernel optimization techniques covered in previous studies. 1. **Leveraging local memory. ** OpenCL adopted an abstract memory model to support various types of devices. OpenCL memory is classified as global, local, constant, and private. Leveraging local memory can improve the performance of the OpenCL kernel because accessing local memory is faster than global memory [28]. Figure 4 is the gaussianBlur5 kernel function code in OpenCV. A __local indicator is required to use local memory in OpenCL, as shown in Line 6 in Figure 4. When an indicator is used in front of a variable, the variable is placed in local memory. 2. **Loop unrolling. ** Loop unrolling is a common optimization technique that copies the body statement of the loop multiple times.