Numba

From Wikipedia, the free encyclopedia
Jump to: navigation, search
Numba
Original author(s) Continuum Analytics
Developer(s) Community project
Initial release 2012 (2012)
Stable release
0.35.0 / 6 September 2017; 36 days ago (2017-09-06)
Preview release
0.35.0rc1 / 24 August 2017; 49 days ago (2017-08-24)
Repository github.com/numba/numba
Written in Python, C
Operating system Cross-platform
Type Technical computing
Website numba.pydata.org

Numba is an open-source NumPy-aware optimizing compiler for Python sponsored by Continuum Analytics, Inc. It uses the LLVM compiler infrastructure to compile Python to machine code.[1]

Traits[edit]

Numba compiles Python code with LLVM to code which can be natively executed at runtime. This happens by decorating Python functions, which allows users to create native functions for different input types, or to create them on the fly:

@jit('f8(f8[:])')
def sum1d(my_double_array):
    total = 0.0
    for i in range(my_double_array.shape[0]):
        total += my_double_array[i]
    return total

This optimized function runs 200 times faster than the interpreted original function on a long NumPy array; and it is 30% faster than NumPy's builtin sum()function (version 0.27.0).[2][3]

To make the above example work for any compatible input types automatically, we can create a function that specializes automatically:

@jit
def sum1d(my_array):
    ...

GPU Kernels[edit]

GPU kernels can be written in Python, and run on the GPU. There are two approaches available currently:

NVIDIA CUDA[edit]

Example CUDA kernel, written using Python source-code:

@cuda.jit
def increment_a_2D_array(an_array):
    x, y = cuda.grid(2)
    if x < an_array.shape[0] and y < an_array.shape[1]:
       an_array[x, y] += 1

numba.pydata.org/numba-doc/dev/cuda/overview.html

AMD HSA[edit]

Simply use the annotation '@hsa.jit':

@hsa.jit(device=True)
def a_device_function(a, b):
    return a + b

numba.pydata.org/numba-doc/dev/hsa/overview.html

Alternative approaches[edit]

The following projects are alternative approaches to accelerating Python:

References[edit]