Exploring Integer Sum Reduction using Atomics on Intel CPU
Zheming Jin, Hal Finkel · 2019
Atomic functions are useful in updating a shared variable by multiple threads, barrier synchronizations, constructing complex data structures, and building high-level frameworks. In this paper, we focus on the evaluation and analysis of integer sum reduction, a common data parallel primitive. We convert the sequential reduction into parallel OpenCL implementations on a CPU. To understand the relationships between the kernel performance and the operations involved in reduction, we develop three microkernels that show the costs of one atomic addition to global memory from one work-item per work-group, a work-group barrier, and reducing within a work-group to local memory using one atomic addition per work-item. The sum reduction kernel with vectorized memory accesses can improve the performance of the baseline kernel for a wide range of work-group sizes. However, the vectorization efficiency shrinks with the growing work-group size. We also find that the vendor's default OpenCL kernel optimization does not improve the kernel performance. When the vectorization width is 16, the performance speedup of our manual vectorization over the vendor's auto-vectorization ranges from 1.03 to 16.7. We attribute the performance drop to the fact that the default kernel optimizations instantiate a large number of atomics operations.