Expression Acceleration: Seamless Parallelization of Typed High-Level Languages

Lars Hummelgren, John Wikman, Oscar Eriksson, Philipp Haller, David Broman · OpenReview

Abstract

Efficient parallelization of algorithms on general-purpose GPUs is today essential in many areas. However, it is a non-trivial task for software engineers to utilize GPUs to improve the performance of high-level programs in general. Although many domain-specific approaches are available for GPU acceleration, it is difficult to accelerate existing high-level programs without rewriting parts of the programs using low-level GPU code. In this paper, we propose a different approach, where expressions are marked for acceleration, and the compiler automatically infers which code needs to be accelerated. We call this approach expression acceleration. We design a compiler pipeline for the approach and show how to handle several challenges, including expression extraction, well-formedness, and compiling using multiple backends. The approach is designed and implemented within a statically-typed functional intermediate language and evaluated using three distinct non-trivial case studies.

Introduction: Bridging the Semantic Gap

Modern software development often relies on high-level languages that offer powerful abstractions like closures, garbage collection, and recursive types. However, a significant "semantic gap" exists between these languages and the low-level requirements of General-Purpose Graphics Processing Units (GPGPUs). GPUs typically demand manual memory management and specialized kernels written in languages like CUDA or OpenCL.

Currently, developers seeking to leverage GPU performance face a difficult choice: either rewrite their entire application in a restricted domain-specific language (DSL) or manually implement complex "glue code" to marshal data between the CPU and GPU. This paper introduces expression acceleration, a middle-ground approach that enables seamless partial acceleration. By simply wrapping computationally intensive expressions in an accelerate keyword, developers can maintain high-level logic while offloading heavy lifting to the GPU.

The Expression Acceleration Pipeline

The authors implemented this approach within the Miking framework, extending its intermediate language (MExpr) with parallel primitives such as map, reduce, and loop. The system utilizes a sophisticated compiler pipeline to automate the transition from high-level code to GPU-executable binaries.

The detailed compiler pipeline for expression acceleration, illustrating the path from source program through extraction and classification to the final accelerated binary.

As shown in the pipeline architecture, the process involves several critical stages:

  1. Extraction: Upon encountering accelerate(expr), the compiler performs lambda lifting and dependency analysis. It identifies all functions and variables required by the expression, pulling them into a self-contained "accelerated" Abstract Syntax Tree (AST).
  2. Classification: The compiler analyzes the extracted AST to select the optimal backend. Pure functional sequences target Futhark (a high-performance functional array language), while imperative tensor operations target CUDA.
  3. Well-formedness Checking: To ensure hardware compatibility, the compiler performs static checks. This prevents the use of features GPUs cannot handle, such as arbitrary recursion or higher-order functions passed as arguments.
  4. Marshaling and Codegen: The system automatically generates the necessary code to move data between CPU memory and GPU VRAM based on variable types, followed by backend-specific code generation.

To aid development, the authors also propose a Debug-first Workflow. The compiler can generate a CPU version with enhanced runtime checks to catch errors in a more accessible environment before the final high-performance GPU binary is compiled.

Evaluation and Key Results

The system was evaluated using two distinct benchmark sets. For the Futhark backend, the Parboil benchmark suite was used to compare the compiler's output against hand-optimized code. For the CUDA backend, the authors implemented an Ordinary Differential Equation (ODE) solver and two Neural Networks (trained on MNIST and CIFAR-10).

Performance comparison (in seconds) between sequential CPU execution and accelerated GPU execution for ODE and Neural Network benchmarks.

The results demonstrate that high-level abstractions do not necessarily compromise performance:

  • Competitive with Hand-Written Code: In Futhark benchmarks, automatically accelerated code performed nearly identically to hand-optimized versions. In some cases, such as the stencil benchmark, the compiler-generated code was faster due to more efficient integer type conversions.
  • Massive Speedups: The CUDA-based benchmarks showed dramatic improvements. As seen in the performance table, a neural network running on the CIFAR-10 dataset was reduced from 12,981 seconds on the CPU to just 3.38 seconds when accelerated—a speedup of approximately 3,800x.
  • Minimal Overhead: Data marshaling time was found to be negligible compared to the computational gains for non-trivial problems.

Limitations and Future Work

While the current implementation is highly effective, some limitations remain. The GPU backends currently cannot handle higher-order functions within accelerated blocks. Additionally, the compiler assumes that operations like reduce use associative and commutative functions; users must manually verify this to avoid non-deterministic results. Future work will focus on expanding backend support and developing more sophisticated static analyses to automatically verify the safety of parallel operations.

Summary updated

BibTeX
@misc{hummelgren2022expression,
  author = {Lars Hummelgren and John Wikman and Oscar Eriksson and Philipp Haller and David Broman},
  title = {{Expression Acceleration: Seamless Parallelization of Typed High-Level Languages}},
  year = {2022},
  eprint = {2211.00621},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2211.00621},
}
Figure