Skip to main content
QUICK REVIEW

[Paper Review] Comparing Llama-2 and GPT-3 LLMs for HPC kernels generation

Pedro Valero‐Lara, Alexis Huante|arXiv (Cornell University)|Sep 12, 2023
Parallel Computing and Optimization TechniquesComputer Science16 references5 citations
TL;DR

This paper evaluates Meta's Llama-2 LLM against OpenAI's Codex (via GitHub Copilot) for generating high-performance computing (HPC) kernels in C++, Fortran, Python, and Julia across multiple parallel programming models. Llama-2 produces more optimized code but with lower reliability than Copilot, achieving correct outputs in 33–66% of test cases compared to Copilot’s 66–83%, with notable optimization gains in matrix operations despite errors in GPU syntax.

ABSTRACT

We evaluate the use of the open-source Llama-2 model for generating well-known, high-performance computing kernels (e.g., AXPY, GEMV, GEMM) on different parallel programming models and languages (e.g., C++: OpenMP, OpenMP Offload, OpenACC, CUDA, HIP; Fortran: OpenMP, OpenMP Offload, OpenACC; Python: numpy, Numba, pyCUDA, cuPy; and Julia: Threads, CUDA.jl, AMDGPU.jl). We built upon our previous work that is based on the OpenAI Codex, which is a descendant of GPT-3, to generate similar kernels with simple prompts via GitHub Copilot. Our goal is to compare the accuracy of Llama-2 and our original GPT-3 baseline by using a similar metric. Llama-2 has a simplified model that shows competitive or even superior accuracy. We also report on the differences between these foundational large language models as generative AI continues to redefine human-computer interactions. Overall, Copilot generates codes that are more reliable but less optimized, whereas codes generated by Llama-2 are less reliable but more optimized when correct.

Motivation & Objective

  • To evaluate the effectiveness of Llama-2 as a code generator for HPC kernels across multiple programming languages and parallel models.
  • To compare Llama-2’s code generation accuracy and optimization quality against the GPT-3-based GitHub Copilot (Codex) baseline.
  • To assess how model choice affects reliability and performance in generating optimized HPC kernels for CPUs and GPUs.
  • To identify patterns in LLM behavior across different HPC stacks, including OpenMP, CUDA, HIP, OpenACC, and language-specific libraries like Numba and cuPy.
  • To understand the trade-offs between code reliability and optimization when using open-source vs. proprietary LLMs for HPC development.

Proposed method

  • Generated HPC kernels (AXPY, GEMV, GEMM) using Llama-2 via Hugging Chat, a Hugging Face-based interface, with simple natural language prompts.
  • Evaluated generated code across four languages: C++, Fortran, Python, and Julia, using 144 unique combinations of kernels, languages, and programming models.
  • Tested correctness and performance using standard compilers and runtime environments for each target model (e.g., OpenMP, CUDA, OpenACC, Numba, cuPy, CUDA.jl).
  • Applied consistent prompts across both Llama-2 and Copilot to ensure fair comparison, with keyword augmentation for Fortran and Python where beneficial.
  • Measured success as the presence of at least one correct, compilable, and functionally correct kernel per test case.
  • Analyzed error patterns, especially in GPU-specific syntax (e.g., incorrect use of __shared__ vs. __device__ in cuPy).
Figure 1: Hugging Chat website interface.
Figure 1: Hugging Chat website interface.

Experimental results

Research questions

  • RQ1How does Llama-2’s accuracy in generating correct HPC kernels compare to GitHub Copilot’s GPT-3-based Codex across multiple programming languages and models?
  • RQ2In what ways do Llama-2 and Copilot differ in code optimization strategies, particularly for matrix multiplication kernels?
  • RQ3Why do certain GPU programming models (e.g., HIP, AMDGPU.jl) show consistently lower success rates across both models?
  • RQ4To what extent do language-specific features (e.g., Julia’s Base.Threads.jl, Python’s Numba) influence LLM code generation reliability and correctness?
  • RQ5What are the most common error patterns in LLM-generated HPC code, and how do they differ between Llama-2 and Copilot?

Key findings

  • Llama-2 generated at least one correct kernel in 40% of C++ cases, 66% of Fortran cases, 22% of Julia cases, and 33% of Python cases.
  • GitHub Copilot achieved at least one correct code in 80% of C++ cases, 100% of Fortran cases, 66% of Julia cases, and 83% of Python cases, demonstrating higher reliability.
  • Llama-2 produced more optimized code than Copilot when correct, particularly in matrix kernels using Numba and numpy, with techniques like tiling and strided access.
  • A recurring error in Llama-2’s cuPy-generated code was the misuse of the __shared__ decorator instead of __device__, which breaks GPU compilation despite otherwise correct logic.
  • For AXPY kernels, Llama-2 failed to generate correct code in all cases across C++, Fortran, and Python, while Copilot succeeded in most.
  • Llama-2 outperformed Copilot in generating correct OpenMP codes for all kernels in C++ and Fortran, indicating stronger support for CPU parallelism.
Figure 2: Results for C++ kernels (left) and programming models (right).
Figure 2: Results for C++ kernels (left) and programming models (right).

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.