  We present Sailfish, an open source fluid simulation package implementing the
lattice Boltzmann method (LBM) on modern Graphics Processing Units (GPUs) using
CUDA/OpenCL. We take a novel approach to GPU code implementation and use
run-time code generation techniques and a high level programming language
(Python) to achieve state of the art performance, while allowing easy
experimentation with different LBM models and tuning for various types of
hardware. We discuss the general design principles of the code, scaling to
multiple GPUs in a distributed environment, as well as the GPU implementation
and optimization of many different LBM models, both single component (BGK, MRT,
ELBM) and multicomponent (Shan-Chen, free energy). The paper also presents
results of performance benchmarks spanning the last three NVIDIA GPU
generations (Tesla, Fermi, Kepler), which we hope will be useful for
researchers working with this type of hardware and similar codes.
