March 2020
Intermediate to advanced
366 pages
9h 8m
English
You have seen how simple it is to create CPU-accelerated code using Numba. Numba also provides a similar interface to make a computation on a GPU using Compute Unified Device Architecture (CUDA). Let's port our IOU matrix calculation function to be computed on a GPU using Numba.
We can instruct Numba to make the computation on a GPU by slightly modifying the decorator parameters, as follows:
@numba.guvectorize(['(f8[:, :], f8[:, :], f8)'], '(m,k),(n,k1)->()',target="cuda")def mat_mul(x, y, z): for i in range(x.shape[0]): for j in range(y.shape[1]): z=iou(x[i],y[j])
Here, we have instructed Numba to make the computation on a GPU by passing target="cuda". We also have work to do on the iou function. ...
Read now
Unlock full access