Abstract
While data parallelism aspects of OpenCL have been of primary interest due to the massively data parallel GPUs being on focus, OpenCL also provides powerful capabilities to describe task parallelism. In this article we study the task parallel concepts available in OpenCL and find out how well the different vendor-specific implementations can exploit task parallelism when the parallelism is described in various ways utilizing the command queues. We show that the vendor implementations are not yet capable of extracting kernel-level task parallelism from in-order queues automatically. To assess the potential performance benefits of in-order queue parallelization, we implemented such capabilities to an open source implementation of OpenCL. The evaluation was conducted by means of a case study of an advanced noise reduction algorithm described as a multi-kernel OpenCL application.
Introduction
OpenCL has long been the industry standard for heterogeneous computing, yet it suffers from a persistent "identity problem." Most developers utilize it primarily for offloading massive data-parallel workloads to GPUs, following a "single kernel at a time" execution model. However, modern computing platforms are increasingly complex, featuring multi-core CPUs, DSPs, and FPGAs that could theoretically execute different kernels concurrently. This potential for "task parallelism" remains largely untapped due to the complexity of describing task relationships and the limitations of current vendor implementations.
The primary mechanism for managing tasks in OpenCL is the command queue. While "out-of-order" queues allow for concurrent execution, they require programmers to manually define every dependency using complex event objects. Consequently, most developers opt for "in-order" queues for their simplicity. Unfortunately, commercial OpenCL implementations from major vendors typically execute these in-order queues strictly sequentially, even when tasks are mathematically independent, leaving significant performance on the table.
Automatic Task Parallelism via DAG Construction
To address this efficiency gap, this study proposes a runtime system that treats a sequence of OpenCL commands as a Directed Acyclic Graph (DAG). Instead of requiring manual dependency definitions, the runtime automatically analyzes the buffer arguments of each kernel.
As shown in Figure 1, a typical multi-kernel application involves complex data flows between buffers and kernels. If Kernel A writes to a buffer that Kernel B subsequently reads, the runtime identifies a dependency. Conversely, if kernels utilize entirely different buffers, they are flagged as parallelizable. This logic was implemented as an extension to the pocl (Portable Computing Language) runtime, allowing it to intercept commands and identify "embarrassingly parallel" opportunities that vendor SDKs typically overlook.
The Programming Burden of Manual Parallelism
The reluctance of developers to use out-of-order queues is rooted in the significant increase in code complexity. Manual parallelization requires the use of event dependencies to synchronize tasks across multiple queues or within a single out-of-order queue.
Figure 5 illustrates the intricate web of event dependencies needed to coordinate kernels across different command queues. This manual micro-management by the host CPU is error-prone and burdensome. By automating this process through DAG construction from standard in-order queues, the proposed system provides the performance benefits of out-of-order execution without the associated programming overhead.
Experimental Evaluation
The proposed system was evaluated using the BM3D (Block-Matching and 3D filtering) noise reduction algorithm, a sophisticated multi-kernel pipeline involving block matching, thresholding, and aggregation. To provide sufficient task-level depth, the algorithm was executed on 30 input frames.
Testing was conducted across three distinct architectures:
- Dual-socket Intel Xeon: 24 cores, representing high-end server performance.
- AMD A10-7850K: A quad-core APU.
- Intel Core i7: A standard quad-core consumer CPU.
Key Results and Insights
The evaluation revealed that commercial SDKs are surprisingly conservative. Even when tasks are independent, they often wait for sequential completion unless out-of-order queues are explicitly used. On the 24-core Intel Xeon, the automatic parallelization achieved a 1.96x speedup over standard sequential execution, matching the performance of manually-optimized code.
Furthermore, the study highlighted a "Locality Tax" in some implementations. AMD’s SDK showed a 25% performance penalty when using multiple command queues, likely due to a round-robin scheduler that scatters tasks across cores, thereby destroying cache locality. To mitigate this, the authors introduced "compute groups" in pocl, which group processor cores sharing a cache to ensure that kernels sharing data are executed in close proximity.
Conclusion and Future Work
This research demonstrates that OpenCL runtimes can—and should—perform the heavy lifting of dependency analysis. By extracting task parallelism automatically from in-order queues, developers can achieve significant speedups without increasing code complexity. Future work will focus on locality-aware scheduling, using the task graph to predict data requirements and optimize kernel placement, as well as extending automatic DAG extraction to multi-device systems featuring both CPUs and multiple GPUs.
Summary updated