GPU programming with Numba

Numba is a Python compiler that provides CUDA-based APIs. It has been designed primarily for numerical computing tasks, just like the NumPy library. In particular, the numba library manages and processes the array data types provided by NumPy.

In fact, the exploitation of data parallelism, which is inherent in numerical computation involving arrays, is a natural choice for GPU accelerators.

The Numba compiler works by specifying the signature types (or decorators) for Python functions and enabling the compilation at runtime (this type of compilation is also called Just In Time).

The most important decorators are as follows:

  • jit: This allows the developer to write CUDA-like functions. When encountered, the compiler translates the code under the decorator into the pseudo-assembly PTX language, so that it can be executed by the GPU.
  • autojit: This annotates a function for a deferred compilation procedure, which means that the function with this signature is compiled exactly once.
  • vectorize: This creates a so-called NumPy Universal Function (ufunc) that takes a function and executes it in parallel with vector arguments.
  • guvectorize: This builds a so-called NumPy Generalized Universal Function (gufunc). A gufunc object may operate on entire sub-arrays. 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset