Numba - Numpy Aware Dynamic Python Compiler Using LLVM

July 25, 2018, 4:27 p.m. By: Kirti Bakshi


Numba: A compiler that has been designed for array and numerical functions in Numpy is an Open Source Numpy-aware optimizing compiler sponsored by Anaconda, Inc. The compiler makes the use of the remarkable LLVM compiler infrastructure in order to compile the Python syntax to machine code.

What is the LLVM Compiler?

The LLVM compiler infrastructure project is basically a "collection of a modular and reusable compiler as well as toolchain technologies" that are used in order to develop compiler front ends and back ends.

Moving on with Numba:

Numba is well aware of Numpy arrays as typed memory regions and so it can successfully speed-up the code making the use of Numpy arrays. Other, less well-typed code by removing the "interpreter will be effectively translated to Python C-API calls" but not removing the dynamic indirection.

To conclude effectively, we can say that Numba is a mechanism that from Python syntax produces machine code and typed data structures such as those that exist in Numpy.

Numba is also not a tracing JIT. It compiles the user code before it begins running either by making the use of run-time type information or type information that is provided by the user in the decorator. The compiler provides its users with the power to speed up their applications with high-performance functions that have been written directly in Python.

With only a few annotations, just-in-time, an array-oriented, as well as math-heavy Python code, can be compiled to native machine instructions, similar in performance to C,C++ and Fortran, without having any need to switch languages or Python interpreters.

How Does Numba work?

The compiler works by the generation of an optimized machine code making the use of the LLVM compiler infrastructure at import time, runtime, or statically using the included pycc tool. Numba supports compilation of Python to run on either CPU or GPU hardware and has been designed to integrate with the Python scientific software stack.

What are the main features of Numba?

  • On-the-fly code generation at the user’s preference (at import time or runtime)

  • Native code generation for the CPU (default) and GPU hardware

  • Integration with the python scientific software stack (thanks to Numpy)

Now, How do we Install Numba?

The easiest way to install Numba and get updates is by making the use of the Anaconda Distribution.

More info regarding the same: Click Here

Moving onto its Dependencies:

  • Llvmlite

  • Numpy (version 1.9 or higher)

  • Funcsigs (for Python 2)

Numba for CUDA GPU's:

Numba following the CUDA execution model, by directly compiling a restricted subset of Python code into CUDA kernels and device functions supports CUDA GPU programming. Kernels that are written in Numba appear to have direct access to numpy arrays. And these numpy arrays are automatically transferred between the CPU and the GPU.

As of now, Numba does not implement all features of CUDA and some features that are missing have been listed below:

  • Dynamic parallelism

  • Texture memory

The team welcomes everyone who wishes to make contributions to Numba. Even documentation improvements that are very simple are encouraged. For any further questions, one can refer to their official site and put them up as well.

For now, we can say that Numba rightly is a compiler for Python bytecode with optional type-specialization!

For More Information: GitHub

Official Link: Click Here