How Numba saves you time and speed up your code

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/9d4221a6-c79e-4731-8ef8-02debd507554/1ZBRdJA1CKJqUi35vHpbjHw.jpeg

Numba is a Python compiler, specifically for numerical functions and allows you to accelerate your applications with high performance functions written directly in Python.

Numba generates machine code optimized from pure Python code using LLVM. With a couple of simple changes, our Python code (function-oriented) can be optimized “just-in-time” to obtain a performance similar to that of C, C++, without having to change the language.

You can find the entire code in my GitHub! :)

Index

  1. What is Numba?
  2. First steps: Compile for the CPU
  3. Numba for GPU
  4. Conclusion

What is Numba?

Numba is a compiler that allows you to accelerate Python code (numerical functions) for both CPU and GPU:

  1. Function Compiler: Numba compiles Python functions, not whole applications or parts of it. Basically, Numba is another Python module to improve the performance of our functions.
  2. Just-in-time: (Dynamic translation) Numba translates the bytecode (intermediate code more abstract than the machine code) to machine code immediately before its execution to improve the execution speed.
  3. Numerically-focused: Numba is focused on numerical data, such as int, float, complex. For now, there are limitations to use it with string data.

Numba is not the only way to program in CUDA, it is usually programmed in C/C ++ directly for it. But Numba allows you to program directly in Python and optimize it for both CPU and GPU with few changes in our code. In relation to Python, there are other alternatives such as pyCUDA, here is a comparison between them:

CUDA C/C++:

  1. It is the most common and flexible way to program in CUDA
  2. Accelerate applications in C, C ++.

pyCUDA