TL;DR
This paper introduces OMPGPT, a compact, domain-specific language model for generating OpenMP pragmas, outperforming larger general-purpose models. They also propose "Chain-of-OMP," a novel prompting technique that significantly boosts OMPGPT's accuracy by breaking down pragma generation into sequential steps, making LLMs more effective for High-Performance Computing (HPC) tasks.
What Problem Does This Paper Address?
Large Language Models (LLMs) like ChatGPT have revolutionized many fields, including code generation. However, applying these general-purpose code LLMs to specialized domains like High-Performance Computing (HPC) presents challenges. HPC tasks, particularly those involving parallel programming with OpenMP, have unique requirements that general models may not fully grasp. Existing code LLMs often struggle with the nuances of HPC code, leading to inaccurate or inefficient parallelization directives. Furthermore, the hardware constraints in HPC environments often favor smaller, more efficient models. This paper aims to bridge this gap by developing a specialized LLM for OpenMP pragma generation that is both effective and efficient.
Methods
The core of this work is the OMPGPT model, a domain-specific LLM built upon the GPT-Neo architecture. Unlike general code LLMs trained on vast, diverse codebases, OMPGPT is trained on a curated HPC dataset, with a significant portion dedicated to OpenMP code. This specialized training allows it to better understand the context and structure of OpenMP pragmas.
To further enhance performance, the authors introduce Chain-of-OMP, a novel prompt engineering technique inspired by "Chain-of-Thought" prompting. Instead of a single prompt, Chain-of-OMP guides the LLM through a series of sequential steps. An OpenMP pragma is broken down into its components (directive prefix, directives/clauses, and control structure), and the model generates each component iteratively. The output of one step becomes the input for the next, allowing the model to build the pragma incrementally. This approach mimics how an expert user might refine their query and helps the LLM focus on specific aspects of the pragma.
Datasets
The primary dataset used for training and fine-tuning OMPGPT is HPCorpus. This is an extensive HPC database containing C, C++, and Fortran code, with a substantial portion (around 45%) utilizing parallel programming. The authors specifically use C and C++ code from HPCorpus, totaling over 8.7 million C functions and 68 million C++ functions (approximately 72.39 GB). A portion of this dataset is held out as a test set for evaluation.
Key Insights and Ideas
- Domain Specialization Matters: Training LLMs on domain-specific data (like HPC code for OpenMP) leads to better performance than relying on general-purpose models, even if the specialized model is smaller.
- Iterative Generation is Powerful: The Chain-of-OMP technique demonstrates that breaking down complex generation tasks (like OpenMP pragmas) into smaller, sequential steps significantly improves accuracy. This is akin to "thinking step-by-step" for LLMs.
- Smaller Models Can Compete: OMPGPT, with its 0.76B parameters, shows that efficiency doesn't have to come at the cost of performance, especially when combined with domain-specific training and advanced prompting.
- Mimicking Expert Behavior: Chain-of-OMP effectively replicates how experienced programmers might approach generating complex directives, leading to more targeted and accurate outputs.
Key Results
- Perplexity: OMPGPT achieves competitive perplexity scores on OpenMP code (3.54 for C, 3.66 for C++), outperforming models like PolyCoder and GPT-J, despite being significantly smaller. While larger models like StarCoder achieve lower perplexity, OMPGPT demonstrates remarkable efficiency.
- Pragma Generation Accuracy:
- The base OMPGPT model shows improved accuracy in generating OpenMP pragmas compared to GPT-Neo.
- The Chain-of-OMP technique significantly boosts accuracy for specific OpenMP clauses:
- "for schedule": accuracy increased from 1.3% to 7.8% (a 600% improvement).
- "collapse": accuracy increased from 0.1% to 2.4% (a 2300% improvement).
- "target": accuracy increased from 2.9% to 16.9% (a 580% improvement).
- Fine-tuning Results: For specific clauses (private, reduction, SIMD), OMPGPT consistently outperformed both MonoCoder and GPT-3.5 across various metrics (precision, recall, F1-score, accuracy), especially when using the Chain-of-OMP method. The second subtest, which requires matching both the clause and its control structure, showed a performance drop for all models, but OMPGPT with Chain-of-OMP still maintained an advantage.
Limitations and Future Work
- Limitations:
- The strict matching criterion used for evaluation highlights the difficulty of achieving perfect accuracy in pragma generation, as functionally equivalent pragmas might be considered incorrect.
- Performance gains for the "teams" pragma were limited due to insufficient training data for that specific pragma.
- MonoCoder, a strong baseline, does not support SIMD pragmas, limiting direct comparison in some fine-tuning scenarios.
- Future Work:
- Evaluate Chain-of-OMP on a wider range of OpenMP clauses.
- Extend context windows beyond loop snippets to capture broader program context.
- Train LLMs from scratch on their data using Chain-of-OMP prompting.
- Explore the application of this approach for other HPC tasks, such as MPI routine generation.
Summary updated