Fully integrating the Flang Fortran compiler with standard MLIR

TL;DR

Fully integrating Flang with standard MLIR achieves up to three times performance improvement.

cs.DC 🔴 Advanced 2024-09-27 11 views
Nick Brown
Flang Fortran MLIR LLVM HPC

Key Findings

Methodology

The paper presents a method to fully integrate the Flang Fortran compiler with standard MLIR. By lowering Flang's MLIR dialects to standard MLIR dialects and leveraging existing MLIR transformations and optimizations to generate LLVM-IR, the study demonstrates performance advantages. A research prototype was tested on the ARCHER2 supercomputer.

Key Results

  • Achieved up to three times performance improvement across multiple benchmarks compared to existing Flang methods.
  • Significantly outperformed GNU and Cray compilers in benchmarks like Jacobi iteration and PW advection.
  • Reduced code redundancy and improved compilation efficiency by using standard MLIR flow.

Significance

This research advances the development of open-source Fortran compilers by optimizing Flang's performance. It not only enhances HPC application efficiency but also promotes the utilization of the MLIR ecosystem, avoiding technological lock-in.

Technical Contribution

The technical contribution lies in developing a novel method to map Flang's MLIR dialects to standard MLIR dialects, showcasing advantages in performance and code maintenance.

Novelty

This is the first work to fully integrate Flang with standard MLIR, significantly enhancing compiler performance and flexibility.

Limitations

  • The current implementation is validated only on specific benchmarks, which may not apply to all Fortran applications.
  • Dependency on MLIR may pose challenges in keeping up with its rapidly evolving ecosystem.

Future Work

Future research directions include extending the method to support a broader range of Fortran features and validating its performance in more HPC applications.

AI Executive Summary

Fortran is a primary programming language for high-performance computing (HPC), and the performance of its compilers is crucial for scientific computing. However, the existing Flang compiler lacks full integration with standard MLIR, leading to suboptimal performance. This paper proposes a method to fully integrate Flang with standard MLIR by lowering Flang's MLIR dialects to standard MLIR dialects and leveraging existing MLIR transformations and optimizations to generate LLVM-IR. Experimental results show that this method achieves up to three times performance improvement across multiple benchmarks, particularly excelling in compute-intensive tasks like Jacobi iteration and PW advection. This research not only enhances the performance of open-source Fortran compilers but also promotes the utilization of the MLIR ecosystem, avoiding technological lock-in. Future research will focus on extending the method to support a broader range of Fortran features and validating its performance in more HPC applications.

Deep Analysis

Background

Fortran has a nearly 70-year history in scientific computing and is the primary programming language for HPC applications. Flang, part of the LLVM project, is an open-source Fortran compiler aiming to support the full Fortran language specification. MLIR, as part of LLVM, provides composable intermediate representations that promote sharing of compiler infrastructure.

Core Problem

While Flang leverages MLIR, it does not fully integrate with it, necessitating bespoke translation and optimization processes. This not only increases code redundancy but also potentially impacts performance as it cannot leverage community progress in MLIR.

Innovation

The innovation lies in proposing a method to map Flang's MLIR dialects to standard MLIR dialects, using existing MLIR transformations and optimizations to generate LLVM-IR. This method reduces code redundancy, improves compilation efficiency, and significantly enhances performance.

Methodology

  • �� Developed a research prototype to lower Flang's MLIR dialects to standard MLIR dialects.
  • �� Leveraged existing MLIR transformations and optimizations to generate LLVM-IR.
  • �� Conducted performance testing on the ARCHER2 supercomputer.

Experiments

Experiments were conducted on the ARCHER2 supercomputer using the Polyhedron Fortran benchmark suite and other representative HPC workloads. Performance comparisons were made between Flang, Cray, and GNU Gfortran compilers.

Results

Results show that the new method achieves up to three times performance improvement across multiple benchmarks compared to existing Flang methods, particularly excelling in compute-intensive tasks like Jacobi iteration and PW advection.

Applications

The method can be directly applied to HPC applications requiring high-performance Fortran compilation, especially in scientific computing and engineering simulations.

Limitations & Outlook

The current implementation is validated only on specific benchmarks, which may not apply to all Fortran applications. Dependency on MLIR may pose challenges in keeping up with its rapidly evolving ecosystem.

Plain Language Accessible to non-experts

Imagine you're cooking in a kitchen. The Flang compiler is like a chef with its own set of recipes (compilation processes), but these recipes aren't very efficient. MLIR is like a shared recipe library full of proven, efficient recipes. This paper's method is about getting the Flang chef to use the MLIR recipe library, making tastier dishes (more efficient executables). This way, Flang not only speeds up cooking but also reduces repetitive work.

ELI14 Explained like you're 14

Imagine you're playing a game, and Flang is your character with its own skill tree (compilation process). But there's a bigger skill tree (MLIR) with lots of cool skills. This paper's method is about letting Flang learn from this bigger skill tree, making it stronger. This way, your character can defeat more enemies (generate more efficient code) and save skill points (reduce code redundancy)!

Glossary

Flang

LLVM's Fortran frontend compiler, aiming to support the full Fortran language specification.

In this paper, Flang is used to generate LLVM-IR.

MLIR

A reusable compiler infrastructure providing composable intermediate representations.

In this paper, MLIR is used to optimize Flang's compilation process.

LLVM

A set of compiler and toolchain technologies for developing compilers across various languages and architectures.

In this paper, LLVM is used to generate the final executable.

HPC

High-performance computing involves using supercomputers and parallel processing to solve complex computational problems.

In this paper, HPC applications are the primary target for the Flang compiler.

Fortran

A programming language primarily used for scientific computing, with a history of nearly 70 years.

In this paper, Fortran is the target language processed by the Flang compiler.

Open Questions Unanswered questions from this research

  • 1 How can this method be extended to support a broader range of Fortran features?
  • 2 What are the specific steps to validate its performance in more HPC applications?

Applications

Immediate Applications

Scientific Computing

Improve the compilation efficiency and performance of scientific computing applications, especially in areas requiring high-performance computing.

Long-term Vision

Engineering Simulations

Apply this method in engineering simulations to enhance simulation accuracy and speed, driving advancements in engineering technology.

Abstract

Fortran is the lingua franca of HPC code development and as such it is crucial that we as a community have open source Fortran compilers capable of generating high performance executables. Flang is LLVM's Fortran compiler and leverages MLIR which is a reusable compiler infrastructure which, as part of LLVM, has become popular in recent years. However, whilst Flang leverages MLIR it does not fully integrate with it and instead provides bespoke translation and optimisation passes to target LLVM-IR. In this paper we first explore the performance of Flang against other compilers popular in HPC for a range of benchmarks before describing a mapping between Fortran and standard MLIR, exploring the performance of this. The result of this work is an up to three times speed up compared with Flang's existing approach across the benchmarks and experiments run, demonstrating that the Flang community should seriously consider leveraging standard MLIR.

cs.DC cs.PL