Using Numba Effectively Today

What is Numba

Numba is an open source JIT compiler that translates a subset of Python and NumPy code into fast machine code.

What is JIT complier

  • just-in-time compiler
  • Python does not compile programs
  • It takes time to complier
  • If there are functions that got used more than once, the 2nd time running a complied version will be faster
  • Perfect for loops

What works with Numba

  • Numpy - what it is designed for
  • Loopings - things that is done more than once

Different modes

  • object mode
    - handles all values as Python objects
    - usually not faster
    - unless loop component can be "jit"

     
  • nopython mode
    - does not access the Python C API
    - high performamce

Different modes

  • @jit
    - automatically fall back to object mode
    - can compile code that failed in nopython mode
     
  • @njit
    - short hand for @jit(nopython=True)
    - garentee high performamce
    - if not supported it will failed to compile

Support CUDA GPUs

  • Numba supports CUDA GPU programming
  • Compiling a restricted subset of Python code
  • Allow CUDA kernels to have direct access to NumPy arrays
  • See PyData Amsterdam 2019 talk recording

Have the doc ready

Using Numba Effectively Today

By Cheuk Ting Ho

Using Numba Effectively Today

  • 128