One thread per element assigns each array position to its own GPU thread. Each thread performs the same operation independently; in a pure map, it reads only same-index inputs, so outputs do not depend on one another. section 4.0
For a one-dimensional array:
- Compute a unique global index with blockIdx.x * blockDim.x + threadIdx.x. section 3.4
- Check that the index is within the array’s bounds before accessing an element. section 4.16
__global__ void kernel(int* data) { #A
int idx = blockIdx.x * blockDim.x + threadIdx.x; #B
data[idx] = data[idx] * 2; #C
}This kernel doubles each element in place: each thread computes its index and updates that slot. section 4.3
Vector addition
Thread i reads A[i] and B[i] and writes C[i]. A grading-room analogy makes the independence intuitive: each worker handles one exam without needing another worker’s work. section 4.0
