To understand the basics of GPU computing with Numba, it is important that we first learn how a @jit decorator works. It is a central feature of Numba. Using this decorator, Numba's JIT compiler can be used to optimize a function.
To import jit from Numba, we use the following syntax:
from numba import jit
In traditional Python, we use the following syntax for defining a function (recall our conventional multiply function-based program used earlier):
def multiply(p_cpu, q_cpu):
for i in range(N):
q_cpu[i] = p_cpu[i] * q_cpu[i]
To use JIT with Numba, we only have to add the following just before defining the function:
@jit
def multiply(p_cpu, q_cpu):
for i in range(N):
q_cpu[i] = p_cpu[i] * q_cpu[i]
The preceding change will allow the JIT compiler to take over the multiply function and translate it into fast machine...