Efficient Parallel CKY Parsing on GPUs

Youngmin Yi, Chao-Yue Lai, Slav Petrov, Kurt KeutzerIWPT 2011

Introduction

Syntactic parsing is a cornerstone of natural language processing (NLP), essential for tasks ranging from machine translation to information extraction. High-accuracy parsing typically relies on Probabilistic Context-Free Grammars (PCFGs). However, the complexity of the standard parsing algorithm, Cocke-Kasami-Younger (CKY), is $O(n^3 |G|)$, where $n$ is the sentence length and $|G|$ is the number of rules in the grammar. While $n$ is usually small, $|G|$ can reach millions of rules in state-of-the-art models, making exhaustive parsing computationally expensive and often too slow for real-time applications.

The CKY Bottleneck

The CKY algorithm uses dynamic programming to fill a triangular chart of possible constituent structures. As shown in Figure 1, the algorithm processes the sentence bottom-up, combining smaller spans into larger ones.

The CKY parsing chart and execution order for the sentence "I love you."

While the number of cells in the chart is relatively small ($O(n^2)$), each cell requires iterating over all possible split points and all applicable grammar rules. In massive grammars like the Berkeley Parser, this constant factor $|G|$ becomes the primary bottleneck. Traditional parallelization efforts focused on the chart cells, but this approach fails to fully utilize the thousands of cores available on modern GPUs due to the limited number of cells per level.

GPU Parallelization Strategy

The researchers proposed a paradigm shift: parallelizing over the grammar rules rather than the chart structure. Since there are millions of rules but only a few dozen words in a typical sentence, rule-level parallelism provides much higher occupancy for the GPU's hierarchical architecture.

The implementation, built using NVIDIA’s CUDA, explored two primary mapping strategies:

  1. Thread-Based Mapping: Each rule is assigned to an individual thread. While straightforward, this requires atomic operations to update scores, which can lead to hardware serialization.
  2. Block-Based Mapping: Each grammar symbol is assigned to a thread block. Rules associated with that symbol are distributed among threads within the block, allowing for fast parallel reductions in shared memory to determine the best parse score.

Optimization Techniques: Virtual Symbols

A significant challenge in block-based mapping is load imbalance. Some grammar symbols are "heavy," possessing far more rules than a single thread block can efficiently process. To address this, the authors introduced the concept of virtual symbols.

The virtual symbol strategy for load balancing across thread blocks.

As illustrated in Figure 6, virtual symbols allow the workload for a single large symbol to be split across multiple blocks. This ensures that no single block becomes a bottleneck, maintaining high throughput across the entire GPU. Additionally, the system utilizes Texture Memory and Shared Memory to cache frequently accessed scores and rules, mitigating the latency of Global Memory access.

Results and Performance

The GPU-based parser was evaluated using the Penn Treebank (WSJ) and the Berkeley Parser Grammar, which contains over 850,000 binary rules. The results demonstrated dramatic performance improvements over a highly optimized sequential C implementation on a CPU:

  • GTX 480 (Fermi Architecture): Achieved a 26x speedup, reducing the average parsing time per sentence from 5.5 seconds to just 0.21 seconds.
  • GTX 285: Achieved a 17.4x speedup.
  • Accuracy: Because the GPU implementation performs the same exhaustive search as the CPU version, there is zero loss in parsing accuracy.

Conclusion

By re-evaluating the CKY algorithm through the lens of GPU architecture, this research demonstrates that the massive parallelism of GPUs can be effectively harnessed for complex NLP tasks. Shifting the focus to rule-level parallelism and employing techniques like virtual symbols and shared memory reductions allows for near real-time, high-accuracy syntactic parsing. Future work may involve combining these GPU optimizations with pruning techniques to achieve even greater speeds.

Summary updated

BibTeX
@inproceedings{yi2011efficient,
  author = {Youngmin Yi and Chao-Yue Lai and Slav Petrov and Kurt Keutzer},
  title = {{Efficient Parallel CKY Parsing on GPUs}},
  booktitle = {IWPT},
  year = {2011},
}
Figure