OMPGPT: A Generative Pre-trained Transformer Model for OpenMP

Le Chen, Arijit Bhattacharjee, Nesreen K. Ahmed, Niranjan Hasabnis, Gal Oren, Vy A. Vo, Ali Jannesari · DOI

TL;DR

OMPGPT is a compact, 0.76-billion parameter language model specifically engineered to automate OpenMP pragma generation for High-Performance Computing (HPC). By combining domain-specific training on C/C++ code with a novel iterative prompting strategy called Chain-of-OMP, the model outperforms much larger general-purpose LLMs while remaining small enough to run on standard HPC hardware.

What Problem Does This Paper Address?

Parallelizing code using OpenMP is a cornerstone of high-performance computing, but it is notoriously difficult to get right. Developers must manually insert "pragmas"—compiler directives that tell the system how to distribute work across multiple cores. While general-purpose Large Language Models (LLMs) like GPT-3.5 or StarCoder are great at general programming, they struggle with the niche requirements of HPC for three main reasons:

  1. Hardware Constraints: Massive LLMs often require specialized hardware that isn't always available or efficient to use within standard HPC clusters.
  2. Prompt Variability: General LLMs rely on natural language (NL) prompts. Slight changes in how a user asks a question can lead to wildly different (and often incorrect) code outputs.
  3. Domain Specificity: General models are "jacks-of-all-trades." They lack the deep, specialized understanding of OpenMP syntax and the specific code structures common in HPC environments.

Methods

The authors developed OMPGPT, a domain-specific model based on the GPT-Neo architecture. To make it "HPC-ready," they made several key design choices:

  • Model Downsizing: They tailored the architecture to just 0.76 billion parameters (8 layers, 32 attention heads). This makes it significantly more compact than baselines like StarCoder (15B) or GPT-NeoX (20B).
  • Strategic Positioning: In a clever departure from standard practice, the authors trained the model to place OpenMP pragmas after the code blocks they describe. This aligns with the "instinct" of autoregressive models to predict the next token based on preceding context; by seeing the loop first, the model has the necessary information to predict the correct parallelization strategy.
  • Chain-of-OMP: This is a novel, automated prompt engineering technique inspired by "Chain-of-Thought" reasoning. Instead of asking for a full pragma at once, the system generates it piece-by-piece: first the prefix (#pragma omp), then the directive/clause (e.g., for private), and finally the control variables.
Fig. 4. Chain-of-OMP. Start phase: using the standard OpenMP pragma generation prompts for OMPGPT. Directive/clause generation phase: the first generated Direc- tive/clause is augmented to the previous input as the input for the next chain. This phase is updated till it number of chains reaches parameter Nchain. The final Control variable generation phase generates the last component to complete the chain-of-OMP and generate the OpenMP pragma.

Datasets

The model was trained and evaluated using HPCorpus, a massive database of C, C++, and Fortran repositories from GitHub.

  • Scale: The authors utilized a subset of C and C++ code totaling 72.39 GB, encompassing over 77 million functions.
  • Distribution: As shown in the paper, the dataset covers a wide variety of OpenMP pragmas, with parallel, for, and parallel for being the most frequent.
Fig. 2. Distribution of OpenMP Prag- mas in the HPCorpus OpenMP subset with the top 15 most frequently occur- ring pragmas.

Key Insights and Ideas

  • Small Models, Big Impact: The paper demonstrates that a highly specialized 0.76B model can achieve competitive or superior performance compared to models 20x its size. This is a win for efficiency and accessibility in the HPC community.
  • Aligning with Model Instincts: The decision to move pragmas to the end of code blocks during training is a simple but powerful "aha moment." It transforms pragma generation from a "guess what I'm about to write" task into a "summarize the code I just saw" task.
  • Automated Iteration: Unlike traditional Chain-of-Thought, which often requires users to manually craft multi-step prompts, Chain-of-OMP is fully automated. The model's own output is fed back into the next stage of the chain until the pragma is complete.

Key Results

OMPGPT showed impressive results across several benchmarks:

  • Perplexity: In terms of understanding OpenMP code structure, OMPGPT achieved a perplexity score of 3.54 for C, outperforming the larger GPT-Neo (2.7B) and rivaling MonoCoder (0.89B).
  • Accuracy Boost: The Chain-of-OMP method provided massive gains. For the target clause, accuracy jumped from 2.9% with a basic prompt to 16.9% with the chain. The for schedule clause saw a 600% increase in accuracy.
  • Fine-tuning Superiority: When fine-tuned for specific tasks like reduction or private clauses, OMPGPT consistently outperformed both MonoCoder and GPT-3.5 in strict matching tests.
Comparison of perplexity scores across different LLMs

Limitations and Future Work

While OMPGPT is a significant step forward, the authors acknowledge some hurdles:

  • Data Scarcity: Performance was lower for pragmas with limited representation in the training set (e.g., the teams clause).
  • Context Windows: The current evaluation focused on loop snippets. Future work aims to extend the model's context window to handle more complex, multi-function code structures.
  • Broadening Scope: The researchers plan to evaluate Chain-of-OMP on a wider array of OpenMP clauses and explore its application to other HPC-specific tasks beyond parallelization.

Summary updated

BibTeX
@inproceedings{chen2024ompgpt,
  author = {Le Chen and Arijit Bhattacharjee and Nesreen K. Ahmed and Niranjan Hasabnis and Gal Oren and Vy A. Vo and Ali Jannesari},
  title = {{OMPGPT: A Generative Pre-trained Transformer Model for OpenMP}},
  booktitle = {Euro-Par},
  year = {2024},
  doi = {10.1007/978-3-031-69577-3\_9},
}
Figure