CodeRosetta: Pushing the Boundaries of Unsupervised Code Translation for Parallel Programming

Ali TehraniJamsaz, Arijit Bhattacharjee, Le Chen, Nesreen K. Ahmed, Amir Yazdanbakhsh, Ali Jannesari

Introduction

In the domain of High-Performance Computing (HPC), the ability to port legacy or sequential code to parallel architectures is a critical bottleneck. As hardware evolves, developers are frequently tasked with translating standard C++ or Fortran code into specialized extensions like CUDA to leverage GPU acceleration. However, this process is notoriously difficult to automate. Standard machine learning approaches for code translation typically rely on massive parallel datasets—paired examples of the same logic written in two different languages—which simply do not exist for complex HPC applications. Furthermore, parallel programming introduces unique semantic complexities, such as thread indexing and memory management, where even a minor syntax error can lead to catastrophic system failures or race conditions.

CodeRosetta emerges as a specialized solution to these challenges. A 0.8B parameter encoder-decoder transformer, CodeRosetta is designed to perform unsupervised code translation, effectively learning to bridge the gap between sequential and parallel programming languages without the need for a "Rosetta Stone" of paired data.

The Challenges of HPC Translation

Automated code translation in the HPC space faces two primary hurdles:

  1. Data Scarcity: Unlike natural language translation, where millions of translated sentences are available, HPC codebases are often proprietary or highly specialized. There is no vast repository of C++ code paired with its exact CUDA equivalent.
  2. Semantic Nuance: Parallel programming is unforgiving. Translating a loop from C++ to a CUDA kernel requires precise calculations for threadIdx and blockIdx. General-purpose Large Language Models (LLMs) often struggle with these nuances, producing code that may look correct but fails to compile or results in runtime memory overflows.

Methodology: Unsupervised Structural Learning

CodeRosetta overcomes the lack of paired data through a suite of innovative unsupervised pre-training tasks that focus on the underlying structure of the code.

AST Entity Recognition (AER)

To move beyond simple token matching, the authors implemented AST Entity Recognition. By utilizing Abstract Syntax Trees (ASTs), the model learns to identify and categorize code elements—such as variables, function calls, and CUDA-specific constructs—based on their structural role. This allows the model to "reason" about the logic of the code rather than just its surface-level syntax.

Tailored Denoising Auto-Encoding (DAE)

The model is trained to reconstruct original code from corrupted versions. CodeRosetta employs two specific noise strategies:

  • Weighted Token Dropping: The model prioritizes removing critical HPC keywords, forcing the decoder to learn how to re-insert them correctly based on context.
  • Language-Specific Token Insertion: By mixing "foreign" tokens from other languages into the source code, the model learns to distinguish between language boundaries and maintain strict syntax.

Adaptive Noise and Back Translation

The training process utilizes a curriculum-based approach where the complexity of the "noise" increases as the model improves. To ensure functional equivalence, CodeRosetta employs Back Translation: the model translates a snippet from C++ to CUDA, then attempts to translate it back to C++. If the resulting code matches the original, the translation is deemed successful, providing a self-supervised signal for optimization.

Experimental Results

The researchers evaluated CodeRosetta against state-of-the-art models, including GPT-4 and BabelTower, using datasets like BabelTower (243,000 unpaired files) and The Stack V2.

Performance Benchmarks

  • C++ to CUDA: CodeRosetta outperformed the previous state-of-the-art by 2.9 BLEU and 1.72 CodeBLEU points. More impressively, it achieved a 98.85% compilation accuracy for C++ to CUDA translations.
  • Fortran to C++: CodeRosetta is the first encoder-decoder model to effectively tackle this legacy translation task, improving CodeBLEU scores by over 4.63 points compared to both open-source and closed-source competitors.
  • Functional Correctness: In runtime evaluations, 93% of the CUDA kernels generated by CodeRosetta produced the exact same numerical results as the reference implementations, demonstrating high reliability in scientific computing contexts.

Key Insights

The success of CodeRosetta highlights a significant trend in AI research: specialization often beats scale. Despite having significantly fewer parameters than frontier models like GPT-4, CodeRosetta’s domain-specific training objectives—particularly its focus on AST structures and tailored denoising—allow it to handle the rigors of parallel programming more effectively. The authors found that Masked Language Modeling (MLM) remains the most critical foundation for code understanding; without it, the model's ability to grasp syntax plummeted.

Limitations and Future Directions

While CodeRosetta represents a major leap forward, it is currently limited to C++, CUDA, and Fortran. Future work aims to expand this scope to include other HPC frameworks like OpenCL and SYCL. Additionally, while the model is highly accurate, it can still miss subtle race conditions in highly complex kernels. The researchers plan to integrate direct compiler feedback into the training loop, allowing the model to automatically learn from compilation errors and further refine its semantic depth.

By pushing the boundaries of unsupervised learning, CodeRosetta provides a powerful new tool for the HPC community, simplifying the transition to modern parallel architectures.

Summary updated

BibTeX
@inproceedings{tehranijamsaz2024coderosetta,
  author = {Ali TehraniJamsaz and Arijit Bhattacharjee and Le Chen and Nesreen K. Ahmed and Amir Yazdanbakhsh and Ali Jannesari},
  title = {{CodeRosetta: Pushing the Boundaries of Unsupervised Code Translation for Parallel Programming}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=V6hrg4O9gg},
}
Figure