liveBook · Manning

Cuda.grid

As explained in Fast Python: High performance techniques for large datasets

cuda.grid is a Numba CUDA intrinsic that computes a thread's global index in a one-, two-, or three-dimensional execution grid.

cuda.grid is a Numba CUDA intrinsic for obtaining the calling thread's global position. A kernel typically handles one array element, uses cuda.grid(1) for a one-dimensional index, and writes directly to that element. section 9.2.2

Doubling an array

A kernel can obtain position = cuda.grid(1) and multiply my_array[position] by two. With 1,000 elements, a 50-by-20 launch covers the array exactly; a 63-by-16 launch requires a bounds check.

How Fast Python: High performance techniques for large datasets covers it

How deep it goes
Explains one- and two-dimensional indexing, launch coverage, bounds checks, and the equivalent block/thread arithmetic.
Examples
Uses array doubling and two-dimensional matrix doubling as concrete indexing kernels.
What it assumes
Assumes basic arrays and CUDA kernel launches while teaching thread-to-element mapping through direct examples.
What you can do after
Apply via Numba CUDA by writing element-wise kernels and launching them across configured grids and blocks.
How it connects
Connects CUDA kernels with thread blocks, grids, blockIdx, blockDim, and threadIdx.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Fast Python: High performance techniques for large datasets. The section links point to the parts of the book it draws on.