SPMD means “single program, multiple data”: one kernel runs across many threads, and each thread works on a different slice of the data. Applying the same operation to different data elements is data parallelism, the foundation of GPU computing. section 2.7
SPMD describes how the code is written; SIMT describes how hardware runs the threads. Thread execution order is not guaranteed, so correctness should not depend on which thread runs first. section 2.7
#include <stdio.h>
#include <cuda_runtime.h>
__global__ void printIndexKernel() {
int idx = threadIdx.x; #A
if (idx == 2) { #B
printf("Thread %d: Hello!\n", idx); #C
}
}
int main() {
printIndexKernel<<<1, 4>>>();
cudaDeviceSynchronize();
return 0;
}This kernel launches four threads, each reading its own threadIdx.x; only thread 2 prints, illustrating one program running across threads. section 2.7


