Papers
Topics
Authors
Recent
Search
2000 character limit reached

Optimized Parallel GPU Merge Kernel

Updated 16 March 2026
  • Parallel GPU merge kernel is a specialized algorithm that efficiently merges k sorted sequences on GPUs by partitioning work into tiles and using warp-level operations.
  • It exploits GPU features such as coalesced memory accesses, binary search partitioning, and register-based minBlockHeap merging for optimal throughput.
  • The design overcomes traditional performance bottlenecks by eliminating shared memory bank conflicts and ensuring balanced load distribution across warps.

A parallel GPU merge kernel is a specialized algorithmic component designed to perform k-way merging of sorted sequences on Graphics Processing Units (GPUs), exploiting their massive parallelism and unique compute and memory hierarchy characteristics. At its core, this kernel facilitates the merging of KK input runs into a single sorted sequence, mapping the problem efficiently onto the GPU architecture to maximize memory bandwidth and parallel throughput while minimizing synchronization and avoiding shared memory bank conflicts. The GPU Multiway Mergesort (MMS) algorithm exemplifies the state of the art in this area, offering an asymptotically optimal implementation in terms of global memory accesses and achieving practical performance advantages over previous comparison-based GPU sorting algorithms (Casanova et al., 2017).

1. Problem Formulation: Parallel k-way Merge on GPU

Given KK sorted runs A1,…,AKA^1, \dots, A^K of total length NN, the objective is to produce a single output run by merging all input runs. In the GPU setting, PP warps are launched, each responsible for a contiguous segment (termed a "tile") of the output, of size roughly N/PN/P. Each warp operates in lockstep, issuing coalesced global-memory accesses of width BB (corresponding to the warp width). This design partitions the k-way merge into PP independent sub-merges, each of size N/PN/P, promoting perfect load balance and maximizing the efficiency of memory coalescing.

2. Partitioning: Discovering Merge Tile Boundaries

Partitioning is accomplished by mapping each output tile to precise indices in each input run. For warp tt (KK0) and per-run starting indices KK1, the requirement is:

KK2

where KK3 denotes the global rank. This boundary discovery utilizes a generalization of the merge-path technique with binary search: for each run KK4, a binary search on KK5 finds KK6, relying on K–1 binary searches or SIMD comparisons in other runs to determine global rank. Each warp’s total partitioning cost is KK7 global memory transfers, which is asymptotically negligible provided KK8.

3. The minBlockHeap Merge Kernel Architecture

Upon determining per-run boundaries, each warp merges its assigned tile using the minBlockHeap, a binary heap structure where each node contains KK9 sorted elements and has A1,…,AKA^1, \dots, A^K0 leaves (each representing a block from an input run). The construction proceeds as follows:

  • Build Phase: Every leaf node reads a block of A1,…,AKA^1, \dots, A^K1 elements from its run using coalesced accesses. The heap is built bottom-up: at every internal node A1,…,AKA^1, \dots, A^K2 (with children A1,…,AKA^1, \dots, A^K3, A1,…,AKA^1, \dots, A^K4), the fillEmptyNode procedure merges the A1,…,AKA^1, \dots, A^K5 child elements, propagating the A1,…,AKA^1, \dots, A^K6 smallest into A1,…,AKA^1, \dots, A^K7 and recursing to refill the emptied child until a leaf is reached.
  • Steady-State Output: The root’s A1,…,AKA^1, \dots, A^K8 elements—always the smallest available—are written back to global memory as a coalesced store. The root is then marked empty, and fillEmptyNode is invoked recursively to refill from the appropriate input, continuing until all A1,…,AKA^1, \dots, A^K9 elements are emitted.

Critical to performance, all merge steps within fillEmptyNode are realized using a parallel bitonic network across registers, leveraging warp-shuffle instructions to avoid any dependence on shared memory. This design totally eliminates shared memory bank conflicts and synchronization primitives such as __syncthreads() within warps.

4. I/O and Work Complexity Analysis

For each merge round, every warp reads and writes NN0 elements, and the total global I/O cost per merge round is therefore NN1. The algorithm conducts NN2 rounds, with NN3 representing device memory size. The total global I/O complexity is thus:

NN4

Choosing NN5 yields:

NN6

This matches the Parallel External Memory (PEM) model’s lower bound for sorting (Casanova et al., 2017). Per output block, the only additional computation is the NN7 bitonic warp-shuffle steps in fillEmptyNode, giving total parallel work of

NN8

with NN9 (warp width).

5. Hardware Constraints and GPU-Specific Optimizations

The choice of PP0 is governed by shared memory availability. For NVIDIA Kepler (48 KiB per SM), PP1 is optimal; for Maxwell (96 KiB per SM), PP2. The active warps PP3 are selected to saturate all SMs, typically 512–1024 warps. By employing warp-shuffle instructions for all intra-tile communication, all shared-memory bank conflicts are averted. The base-case merge employs a warp-level shearsort for PP4 elements, using a bank-conflict-free transpose. The base-case size is tuned so that PP5 avoids problematic powers of PP6, circumventing wasteful final merges.

6. Empirical Performance and Comparative Evaluation

MMS is benchmarked against Thrust and modernGPU comparison-based mergesorts, as well as CUB’s radix sort, on three platforms: GTX 770 Kepler, K40m Kepler, and M4000 Maxwell. Throughputs of 400–600 M keys/s (Kepler) and ~700 M keys/s (Maxwell) are attained. For small PP7, performance matches that of MGPU/Thrust; for large PP8, MMS achieves 5–15% higher performance due to lower I/O costs. While MMS, being comparison-based, is within 30–40% of CUB’s radix sort (1.2 G keys/s), it excels on workloads that induce worst-case bank conflicts in competitors: in such scenarios, MMS delivers a 30–45% speedup and is unaffected by the performance collapses that degrade MGPU/Thrust by 2–3x in shared-memory merges.

7. Theoretical and Practical Significance

The MMS parallel GPU merge kernel establishes an asymptotically optimal solution both in global memory accesses and in practical throughput for comparison-based sorting on GPUs. By eliminating shared memory bank conflicts and achieving near-perfect coalescing via partitioned tiles and register-only merges, it overcomes performance bottlenecks in existing algorithms. This positions the MMS merge kernel as a foundational primitive in high-throughput, memory-efficient sorting frameworks on GPU architectures (Casanova et al., 2017).

Definition Search Book Streamline Icon: https://streamlinehq.com
References (1)

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to Parallel GPU Merge Kernel.