May 2019
Intermediate to advanced
452 pages
12h 16m
English
You can also use Numba to write kernels explicitly in NVIDIA CUDA or AMD ROCm (HSA).
In CUDA, we use syntax that we are already familiar with:
@cuda.jitdef multiply(p, q): # Thread id in a 1D block tx = cuda.threadIdx.x # Block id in a 1D grid ty = cuda.blockIdx.x # Block width, i.e. number of threads per block bw = cuda.blockDim.x # Computing flattened index inside the array index = tx + ty * bw if index < N: # Check array size limit q[index]=p[index]*q[index]
In ROCm, we use the following OpenCL syntax:
@roc.jitdef multiply(p, q): # workitem id in a 1D workgroup tx = roc.get_local_id(0) # workgroup id in a 1D grid ty = roc.get_group_id(0) # workgroup size, i.e. number of workitems per workgroup bw = roc.get_local_size(0) ...
Read now
Unlock full access