Vector Operations for Accelerating Expensive Bayesian Computations – A Tutorial Guide

David J. Warne, Scott A. Sisson, Christopher Drovandi

Abstract

Many applications in Bayesian statistics are extremely computationally intensive. However, they are often inherently parallel, making them prime targets for modern massively parallel processors. Multi-core and distributed computing is widely applied in the Bayesian community, however, very little attention has been given to fine-grain parallelisation using single instruction multiple data (SIMD) operations that are available on most modern CPUs. In this work, we practically demonstrate, using standard programming libraries, the utility of the SIMD approach for several topical Bayesian applications. Using the C programming language, we show that SIMD can improve the single-core floating point arithmetic performance by up to a factor of 6× compared scalar C code and more than 25× compared with optimised R code. Such improvements are multiplicative to any gains achieved through multi-core processing. We illustrate the potential of SIMD for accelerating Bayesian computations and provide the reader with techniques for exploiting modern massively parallel processing environments.

Introduction

Bayesian statistics is notoriously "expensive." Whether dealing with intractable likelihoods in Approximate Bayesian Computation (ABC) or sampling from complex posteriors using Markov Chain Monte Carlo (MCMC), the computational burden is immense. The standard response in the community has been to move toward "coarse-grained" parallelism: running independent chains on different CPU cores or distributed clusters.

However, there is a significant gap in "fine-grained" parallelization. Modern CPUs are designed to perform the same operation on multiple data points simultaneously via Single Instruction Multiple Data (SIMD) operations, yet many statistical implementations treat CPU cores as purely sequential scalar processors. By ignoring SIMD, practitioners are leaving significant performance on the table—performance that is accessible on standard laptops and desktops, not just high-performance computing (HPC) clusters.

Methodology: Exploiting Fine-Grained Parallelism

The paper serves as a tutorial on bridging the gap between high-level statistical programming (R) and low-level hardware acceleration (C with SIMD). The core concept involves moving from scalar operations to vector operations within the CPU's Vector Processing Unit (VPU).

Comparison of scalar loop processing (a) versus SIMD vector processing in a VPU (b).

Key techniques for achieving these speedups include:

  • SIMD Vectorization: Utilizing VPUs to process 4 to 8 floating-point operations in a single clock cycle, as illustrated in the figure above.
  • OpenMP Directives: Using #pragma omp simd to guide compilers to generate vectorized machine code without requiring the user to write manual assembly.
  • Memory Alignment: Aligning data to 64-byte cache line boundaries to prevent "cache misses" and memory bottlenecks.
  • Parallel RNG: Implementing statistically sound random number generation using the Intel Math Kernel Library (MKL) to ensure independent streams for each thread.
  • Algorithmic Refactoring: Moving from "cell-at-a-time" logic to "block-at-a-time" logic to keep data in ultra-fast L1/L2 caches.

Experimental Setup and Datasets

The authors evaluate their approach using three distinct models:

  1. Genetic Toggle Switch Model: A synthetic biological system governed by coupled Stochastic Differential Equations (SDEs).
  2. Bioassay Toxicity Data: A real-world dataset involving acute toxicity tests in animals, used for testing weakly informative priors.
  3. S&P Composite Index: Monthly logged returns from July 1926 to January 2018 (1099 months) used to test the "Bad Environment – Good Environment" (BEGE) volatility model.

Analysis of Performance and Key Insights

The study reveals that SIMD is not an alternative to multi-threading; it is a multiplier. If a 16-core machine achieves a 4× SIMD speedup per core, the total throughput increases by 64×.

Key Results

  • ABC Toggle Switch: The SIMD C implementation achieved a 6× speedup over scalar C and a 25× speedup over optimized R code.
  • Weakly Informative Priors: Using AVX-512 (512-bit vectors), the authors saw a 2.3× improvement in SMC proposal kernels compared to scalar versions.
  • BEGE Volatility Model: For complex mathematical evaluations like the incomplete gamma function, SIMD provided a 4× speedup using AVX-512.

Critical Observations

  • Memory Bottlenecks: The VPU can process data much faster than RAM can provide it. SIMD forces practitioners to organize data linearly, which often speeds up the code even before the vector instructions are executed.
  • The R "Vectorization" Myth: While R users are encouraged to "vectorize" code, this usually means calling pre-compiled C/Fortran functions. Custom SIMD code in C still outperforms this by an order of magnitude by avoiding the overhead of repeated high-level function calls.
  • Algorithm Suitability: Discrete-time models (like Euler-Maruyama simulations) are "embarrassingly" suited for SIMD. However, exact continuous-time simulations (like the Gillespie algorithm) are much harder to vectorize due to their inherent sequential nature.

Conclusion and Future Work

While the performance gains are substantial, the primary limitation is the "human cost." Moving from R to C with OpenMP requires significant technical expertise. Furthermore, algorithms with heavy branching (if-else statements) can break the SIMD pipeline.

Future work should focus on integrating these SIMD techniques into higher-level probabilistic programming languages (like Stan or Julia) so that statisticians can reap the rewards without writing low-level C code. The authors also highlight the potential for "hybrid" algorithms that combine SIMD blocks with asynchronous multi-threading.

Summary updated

BibTeX
@inproceedings{warne2021vector,
  author = {David J. Warne and Scott A. Sisson and Christopher Drovandi},
  title = {{Vector Operations for Accelerating Expensive Bayesian Computations – A Tutorial Guide}},
  booktitle = {Bayesian},
  year = {2021},
  doi = {10.1214/21-ba1265},
}
Figure