StencilFlow: Mapping Large Stencil Programs to Distributed Spatial Computing Systems

Johannes de Fine Licht, Andreas Kuster, Tiziano De Matteis, Tal Ben-Nun, Dominic Hofer, Torsten Hoefler

TL;DR

StencilFlow is a full-stack framework that automatically maps complex, multi-stage stencil programs—like those used in production weather forecasting—onto distributed FPGA clusters. By treating an entire program as a single, deep, deadlock-free dataflow pipeline, it achieves record-breaking performance of up to 4.18 TOp/s across eight devices.

What Problem Does This Paper Address?

Stencil computations (updating a grid point based on its neighbors) are the computational backbone of weather prediction, climate modeling, and physical simulations. While spatial architectures like FPGAs are theoretically perfect for stencils due to their high energy efficiency and customizability, a massive gap exists between theory and practice.

Most existing research focuses on "toy" problems: a single stencil operation unrolled over time. Real-world applications, such as the COSMO weather model, consist of "messy" Directed Acyclic Graphs (DAGs) containing dozens of different, heterogeneous stencil operations with complex dependencies. Manually mapping these to hardware is incredibly difficult because the designer must manage thousands of on-chip buffers to ensure data reuse and prevent "deadlocks"—where the hardware stops because one part of the pipeline is waiting for data that another part is blocked from sending.

Methods

The authors introduce StencilFlow, an end-to-end pipeline that takes a high-level program description and emits optimized hardware. Key components include:

  • High-Level DSL: A JSON-based language allows users to define stencils, their iteration spaces, and their dependencies without worrying about hardware specifics.
  • Automated Dataflow Analysis: This is the core "intelligence" of the system. StencilFlow analyzes the DAG to calculate two types of buffers:
  • Internal Buffers: To maximize temporal locality (reusing data already on-chip).
  • Delay Buffers: To synchronize different paths in the DAG, ensuring that data arrives at "join" nodes exactly when needed, which guarantees a deadlock-free execution.
  • Spatial Stencil Fusion: Unlike traditional CPU/GPU fusion (which aims to reduce memory trips), StencilFlow fuses stencils to reduce initialization latency and increase the ratio of "useful" compute logic to overhead logic.
  • Integration with DaCe & SMI: The system leverages the Data-Centric (DaCe) framework for low-level optimizations and the Streaming Message Interface (SMI) to handle seamless communication between multiple FPGAs over a network.

Datasets

The paper evaluates the framework using two main approaches:

  1. Microbenchmarks: Chained linear sequences of standard stencils (Jacobi 3D, 2D/3D Diffusion) to establish peak performance limits.
  2. Production Case Study: The Horizontal Diffusion kernel from the COSMO weather model. This is a complex, real-world program involving 28 accesses to 10 unique input fields and a DAG of multiple heterogeneous stencil stages.

Key Insights and Ideas

  • The "Deep Pipeline" Philosophy: Instead of thinking about stencils as loops to be executed, StencilFlow views the entire program as a single, massive pipeline. Every cell of the grid flows through the entire graph of operations in a "fully pipeline-parallel" manner.
  • Deadlock Prevention via Buffering: In a complex graph, if one path has more latency than another, the "faster" path must be buffered. StencilFlow’s ability to automatically calculate these "delay buffers" is what makes targeting large-scale programs feasible.
  • Vectorization is Crucial: The authors found that 4-way or 8-way vectorization is mandatory to saturate the FPGA’s compute resources and memory bandwidth. Without it, the overhead of the pipeline logic outweighs the compute gains.
  • Silicon Efficiency: The paper highlights that while GPUs have higher raw throughput, FPGAs can achieve much higher "silicon efficiency" (performance per $mm^2$ of silicon) for specific arithmetic intensities.

Key Results

  • Record Performance: StencilFlow achieved 1.31 TOp/s on a single Intel Stratix 10 FPGA and 4.18 TOp/s on a cluster of eight FPGAs. This represents the highest performance recorded for stencil programs on FPGAs to date.
  • Real-World Speedup: For the COSMO Horizontal Diffusion kernel, the FPGA outperformed a 12-core Intel Xeon CPU by 4.5x.
  • Competitive with GPUs: The FPGA implementation was competitive with an NVIDIA Tesla P100 GPU, though it was outperformed by the newer V100 (largely due to the V100's superior HBM2 memory bandwidth compared to the Stratix 10's DDR4).

Limitations and Future Work

  • Memory Bandwidth Bottleneck: For many real-world stencils, the performance is limited by off-chip memory bandwidth. The authors note that FPGAs equipped with High Bandwidth Memory (HBM) would likely close the gap with high-end GPUs.
  • Spatial Tiling: The current implementation assumes the internal buffers can fit on-chip for the given grid dimensions. For extremely large grids, "spatial tiling" (breaking the grid into blocks) would be required. The authors discuss this as a clear path for future extension.
  • Precision: While the framework supports various types, the benchmarks focused on 32-bit floats. Exploring half-precision (FP16) or fixed-point math could further boost performance for applications that tolerate lower precision.

Summary updated

BibTeX
@inproceedings{licht2021stencilflow,
  author = {Johannes de Fine Licht and Andreas Kuster and Tiziano De Matteis and Tal Ben-Nun and Dominic Hofer and Torsten Hoefler},
  title = {{StencilFlow: Mapping Large Stencil Programs to Distributed Spatial Computing Systems}},
  booktitle = {CGO},
  year = {2021},
  doi = {10.1109/cgo51591.2021.9370315},
}

Loading related content...

Figure