Article

GSTF Journal on Computing (JoC)

, 3:21

First online:

Open Access This content is freely available online to anyone, anywhere at any time.

Just-In-Time Compilation of NumPy Vector Operations

  • Johannes LundAffiliated withNiels Bohr Institute, University of Copenhagen Email author 
  • , Mads R. B. KristensenAffiliated withNiels Bohr Institute, University of Copenhagen
  • , Simon A. F. LundAffiliated withNiels Bohr Institute, University of Copenhagen
  • , Brian VinterAffiliated withNiels Bohr Institute, University of Copenhagen

Abstract

In this paper, we introduce JIT compilation for the high-productivity framework Python/NumPy in order to boost the performance significantly. The JIT compilation of Python/NumPy is completely transparent to the user – the runtime system will automatically JIT compile and execute the NumPy instructions encountered in a Python application. In other words, we introduce a framework that provides the high-productivity from Python while maintaining the high-performance of a low-level, compiled language.

We transforms NumPy vector instruction into an Abstract Syntax Tree representation that creates the basis for further optimizations. From the AST we auto-generate C code which we compile into computational kernels and execute. These incorporate temporary array removal and loop-fusion which are main benefactors in the achieved speedups. In order to amortize the overhead of creation, we also implement a cache for the compiled kernels.

We evaluate the JIT compilation by executing several scientific computing benchmarks on an AMD. Compared to NumPy, we achieve speedups of a factor 4.72 for a N-Body application and 7.51 for a Jacobi Stencil application executing on a single CPU core.

Keywords:

JIT automatic dynamic runtime