Abstract FPGAs are promising accelerators for scientific computing tasks because of their potential for delivering high performance-per-Watt. However, programming for optimal performance remains a complex task. Our goal is to bring FPGAs within the reach of domain scientists by developing compilers targeting scientific Fortran code. In this paper, we present a novel approach to aggressively reduce memory utilisation of stencil-based finite-difference Fortran code through a compiler-based automatic program transformation that trades memory accesses for computation. The key contribution of this work is a set of type-driven rewrite rules that identify and eliminate the intermediate arrays in stencil computations and replace them with re-computation, thus reducing the number of memory accesses. The main novelty lies in the transformations to move stencil operations out of maps and folds and to fuse stencils. We demonstrate the effectiveness of our approach using a set of five 3-D and 2-D stencil benchmarks evaluated on an Intel Arria 10 FPGA board. Our transformation result on average in a 2. 5 reduction in DRAM usage, a 3. 4 increase in DSP usage, and a 25 improvement in throughput. We show on a real-world exemplar, the Large Eddy Simulator for Urban Flows, that our algorithm successfully removes all intermediate arrays (18 in total), reducing the memory footprint by a factor of 4. 5. The memory-reduced FPGA code, automatically transpiled from the original Fortran source, is 9. 7 faster than the original Fortran code, and performance competitive with a hand optimised FPGA version while supporting a four times larger domain size.
Szafarczyk et al. (Mon,) studied this question.