May 2019
Intermediate to advanced
452 pages
12h 16m
English
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:
@jitdef multiply(p_cpu, q_cpu): for i in range(N): q_cpu[i] = p_cpu[i] * q_cpu[i]
Read now
Unlock full access