Hi I'm trying to understand each step of cuda kernel. It will by nice to get all grid indexes that are occupy by data. My code is to add 2 vectors and is written in python numba.
n = 10
x = np.arange(n).astype(np.float32)
y = x + 1
setup number of threads and blocks in grid
threads_per_block = 8
blocks_per_grid = 2
Kernel
def kernel_manual_add(x, y, out):
threads_number = cuda.blockDim.x
block_number = cuda.gridDim.x
thread_index = cuda.threadIdx.x
block_index = cuda.blockIdx.x
grid_index = thread_index + block_index * threads_number
threads_range = threads_number * block_number
for i in range(grid_index, x.shape[0], threads_range):
out[i] = x[i] + y[i]
Initialize kernel:
kernel_manual_add[blocks_per_grid, threads_per_block](x, y, out)
When i try to print out grid_index i get all input indexes 2*8.
How to get grid indexes (10 of them) that are used to compute data?