docs / GPU Programming / The kernel Context

The kernel context

Inside any kernel body — forall or gpu fn — the implicit kernel object exposes the launch geometry. All fields have .x, .y, and .z components:

FieldMeaning
kernel.thread_idxThread index within its block
kernel.block_idxBlock index within the grid
kernel.block_dimThreads per block
kernel.grid_dimBlocks per grid
kernel.global_idxblock_idx * block_dim + thread_idx
kernel.barrier()Workgroup synchronization — see Shared Memory
kernel.warp.size / .lane_id / .shuffle_down(v, n)Subgroup ops — see Warp Operations

In a forall, the loop index already is the global index, so you rarely touch kernel there. In an explicitly launched gpu fn, kernel.global_idx is how each thread finds its element.