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:
| Field | Meaning |
|---|---|
kernel.thread_idx | Thread index within its block |
kernel.block_idx | Block index within the grid |
kernel.block_dim | Threads per block |
kernel.grid_dim | Blocks per grid |
kernel.global_idx | block_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.