Skip to main content
QUICK REVIEW

[Paper Review] Learning to Parallelize with OpenMP by Augmented Heterogeneous AST Representation

Le Chen, Quazi Ishtiaque Mahmud|arXiv (Cornell University)|May 9, 2023
Software Engineering ResearchComputer Science5 citations
TL;DR

This paper proposes Graph2Par, a graph-based machine learning approach that uses a heterogeneous augmented abstract syntax tree (aug-AST) to detect loop-level parallelism in C code for OpenMP. By leveraging a novel code representation and a heterogeneous graph neural network (HGT), the method achieves 85% accuracy in identifying parallelizable loops—outperforming token-based models and detecting 48 previously missed parallelism opportunities in complex or nested loops.

ABSTRACT

Detecting parallelizable code regions is a challenging task, even for experienced developers. Numerous recent studies have explored the use of machine learning for code analysis and program synthesis, including parallelization, in light of the success of machine learning in natural language processing. However, applying machine learning techniques to parallelism detection presents several challenges, such as the lack of an adequate dataset for training, an effective code representation with rich information, and a suitable machine learning model to learn the latent features of code for diverse analyses. To address these challenges, we propose a novel graph-based learning approach called Graph2Par that utilizes a heterogeneous augmented abstract syntax tree (Augmented-AST) representation for code. The proposed approach primarily focused on loop-level parallelization with OpenMP. Moreover, we create an OMP\_Serial dataset with 18598 parallelizable and 13972 non-parallelizable loops to train the machine learning models. Our results show that our proposed approach achieves the accuracy of parallelizable code region detection with 85\% accuracy and outperforms the state-of-the-art token-based machine learning approach. These results indicate that our approach is competitive with state-of-the-art tools and capable of handling loops with complex structures that other tools may overlook.

Motivation & Objective

  • Address the lack of high-quality, labeled datasets for training machine learning models in loop-level parallelism detection.
  • Overcome limitations of token-based code representations that ignore structural dependencies critical for parallelism analysis.
  • Develop a more expressive code representation that captures both syntactic and structural features of loops for improved model generalization.
  • Design a machine learning pipeline that can detect complex parallelism patterns, including those missed by traditional static analysis tools.
  • Create a reusable dataset and model framework for broader application in program analysis and auto-parallelization research.

Proposed method

  • Construct the OMP_Serial dataset with 18,598 parallelizable and 13,972 non-parallelizable loops from GitHub, benchmarks, and synthetic generation.
  • Extract loops from C code using pre-processing steps such as comment and whitespace removal, and label each loop based on the presence of OpenMP pragmas.
  • Transform each loop’s AST into a heterogeneous augmented AST (aug-AST) that encodes node types, control/data dependencies, and loop-specific attributes like reduction operations.
  • Represent the aug-AST as a heterogeneous graph with multiple node and edge types to capture diverse semantic and structural relationships.
  • Train a heterogeneous graph neural network (HGT) on the aug-ASTs to classify whether a loop is parallelizable and which OpenMP pragma is applicable.
  • Use the HGT model for four downstream tasks: parallelism detection, pragma recommendation, and dependency analysis, leveraging message passing across heterogeneous graph structures.
Figure 1: Proposed methodology. Data collection and generation: our dataset contains data from GitHub crawling, benchmark collection, and synthetic data generation. Data pre-processing: we extracted loops from codes with pre-processing steps, e.g., removing comments and blank lines. We also label th
Figure 1: Proposed methodology. Data collection and generation: our dataset contains data from GitHub crawling, benchmark collection, and synthetic data generation. Data pre-processing: we extracted loops from codes with pre-processing steps, e.g., removing comments and blank lines. We also label th

Experimental results

Research questions

  • RQ1Can a graph-based code representation that combines structural and textual features improve the accuracy of loop-level parallelism detection compared to token-based models?
  • RQ2To what extent can a heterogeneous augmented AST capture complex loop patterns—such as reductions and nested loops with no loop-carried dependencies—that traditional tools miss?
  • RQ3How effective is the proposed HGT-based model in detecting parallelism opportunities in loops with complex control or data dependencies?
  • RQ4Can the OMP_Serial dataset serve as a reliable benchmark for training and evaluating future auto-parallelization tools and models?
  • RQ5What is the practical overhead of generating the aug-AST representation, and is it feasible for real-world static analysis pipelines?

Key findings

  • The Graph2Par model achieves 85% accuracy in detecting parallelizable loops, outperforming state-of-the-art token-based machine learning approaches.
  • The model successfully identifies 48 loops with parallelism opportunities that were missed by three established tools: DiscoPoP, PLUTO, and autoPar.
  • The aug-AST representation enables the model to detect parallelism in complex cases, including nested loops with no loop-carried dependencies and loops with reduction operations.
  • The model correctly identifies that loops with 2D array accesses and reductions on a single index (e.g., j) can be safely parallelized, even when traditional tools fail.
  • The overhead of generating the aug-AST is minimal—on the order of milliseconds—for typical loops (average 6.9 lines), making it practical for static analysis.
  • The OMP_Serial dataset provides a valuable, large-scale benchmark for future research in auto-parallelization and code analysis using machine learning.
Figure 2: Category-wise loops missed by renowned parallelization assistant tools. The results are generated using the OMP_Serial dataset introduced in section 4 .
Figure 2: Category-wise loops missed by renowned parallelization assistant tools. The results are generated using the OMP_Serial dataset introduced in section 4 .

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.