# Performance Optimization of Object Tracking Algorithms in OpenCV on GPUs
## 2 Background and Motivation  
### OpenCV and OpenCL  
OpenCV [5] is a representative computer vision library developed by Intel. This library is open-source and used extensively in many companies and research groups. It implements various computer vision algorithms ranging from simple image filters to object tracking and a wide range of machine learning algorithms, from statistical ones to deep neural networks.  
Processing images is more suitable for parallel computing devices such as GPUs because of its high data parallelism in computation. Hence, OpenCV has also developed to leverage GPGPU computing platforms, such as OpenCL [10] or vendor-specific platforms [11]. From OpenCV v3.0, the APIs in OpenCV are unified to transparently support available computing platforms (e.g., CPU, GPU, FPGA, etc.) on a system [12]. Hence, developers do not need to build multiple codes each specific to an accelerator, but can share a single code for various accelerators.  
OpenCL [10; 13] is a programming framework for efficiently exploiting computing accelerator platforms such as GPUs or FPGAs. OpenCL aims to produce applicationsindependent of the execution platform. An OpenCL application consists of two types: a host program and kernel programs. On a CPU, a host program mainly preprocesses data for kernel programs. The host program checks device information in the platform, selects devices to run kernels, compiles kernel codes, and allocates memory space for kernels. The host program also commands computing devices to execute kernels or handles the data after kernels finish their operation [10].  
The kernel program processes data on computing devices and operates through many threads in parallel. In OpenCL, a thread is referred to as a _work-item_, and a group of work-items is called a _work-group_. When running a kernel, the programmer allocates the number of work-items in an N-dimensional range called _NDRange_. NDRange is mapped to input or output data into one-, two-, or three-dimensional address spaces. Figure 1 shows an example of a work-item, a work-group, and NDRange. A _local work size_ determines the number of work-items per work-group, and a _global work size_ determines the total number of work-items in a workspace. Hence, the two values determine the number of work-groups in a workspace.  
The OpenCL kernel can operate on various hardware, but each hardware can have different architectures, especially memory systems. Therefore, for the compatibility of the kernel program, OpenCL defines an abstract memory model, as shown on the left side of Figure 2. All work-items running on a computing device are accessible to global memory. In addition, data transferred from the host to the device are stored in global memory. A part of the global memory is dedicated to constant memory, which holds data that do not change, such as constant variables. Local memory is local to a work-group and is shared by work-items in a group. Local memory is generally faster than global memory in terms of latency and bandwidth. Each work-item has its private memory for its private values/variables. Private memory is usually backed by registers of computing units.  
Figure 1: OpenCL NDRange workspace example (2-dimensional).  
Figure 2: Memory relationship between OpenCL and GPU.