Knowledge / Computer Science and Engineering / Parallel computing and GPUs

Parallel computing and GPUs

Computer Science and Engineering (B.E./B.Tech) · Theory and architecture · free study notes for exams, placements and interviews

In short

Parallel computing solves one problem by running many operations at the same time on multiple cores, processors or accelerators, instead of one instruction stream on one core. It became unavoidable once clock speeds stopped rising (power wall) around 2004, so performance now comes from more cores rather than faster cores. A GPU is the extreme form: thousands of simple arithmetic units run the same instruction on different data (SIMT), giving tens of TFLOPS for graphics, deep learning, simulation and crypto workloads. Universities examine it in "Parallel and Distributed Computing" / "GPU Computing" electives and in computer architecture papers (Flynn's taxonomy, Amdahl's law, coherence, interconnects); GATE asks speedup, dependence and synchronisation questions. It is interviewed hard at NVIDIA, AMD, Intel, Qualcomm, Samsung R&D, Texas Instruments, Mercedes-Benz R&D India, Ola Krutrim, Zoho, Mathworks and every HPC/AI-infrastructure team.

Explained

Why parallelism, and what limits it

Classification and architectures

Coherence, consistency and synchronisation

Interconnection networks (examined with diameter and bisection width)

GPU architecture and the CUDA model

__global__ void saxpy(int n, float a, const float* x, float* y) {
    int i = blockIdx.x * blockDim.x + threadIdx.x;   // global index
    if (i < n) y[i] = a * x[i] + y[i];               // coalesced, 1 FMA
}
// host: saxpy<<<(n + 255) / 256, 256>>>(n, 2.0f, d_x, d_y);

Parallel algorithm patterns and performance analysis

Key points

Formulas and examples

Speedup S(p) = T(1) / T(p); Efficiency E = S(p)/p; Cost = p × T(p)
Amdahl: S(p) = 1 / (s + (1 − s)/p), maximum 1/s as p → ∞ (s = serial fraction)
Gustafson (scaled): S(p) = s + p(1 − s)
Karp–Flatt experimental serial fraction: e = (1/S − 1/p) / (1 − 1/p)
Peak FLOPS = (number of cores) × (clock in Hz) × (FLOP per cycle per core; 2 for one FMA)
Peak bandwidth (GB/s) = bus width (bytes) × effective transfer rate (GT/s)
Machine balance (FLOP/byte) = peak FLOPS / peak bandwidth
Arithmetic intensity AI = FLOPs executed / bytes moved to and from DRAM
Roofline: attainable FLOPS = min(peak FLOPS, peak bandwidth × AI)
Occupancy = active warps per SM / maximum warps per SM
Threads per grid: blocks = ceil(N / threads_per_block); global id = blockIdx.x × blockDim.x + threadIdx.x
Parallel time of a reduction of N items on p threads ≈ N/p + log₂p steps
Little's law: concurrency (bytes in flight) = bandwidth × latency

Example 1 - Amdahl vs Gustafson. A program is 95% parallelisable, so s = 0.05.

Example 2 - GPU peak and machine balance. A GPU has 80 SMs × 64 FP32 lanes = 5,120 cores at 1.41 GHz, with 900 GB/s HBM2.

Example 3 - SAXPY is memory-bound. y[i] = a*x[i] + y[i] on N = 2²⁰ × 64 = 67,108,864 floats.

Example 4 - Occupancy from registers. SM limits: 2,048 threads (64 warps), 65,536 32-bit registers. Kernel: 256 threads/block, 48 registers/thread.

Example 5 - Coalescing cost. A warp of 32 threads reads 4-byte floats.

Example 6 - Reduction of N = 1,048,576 with 1,024 threads. Steps ≈ N/p + log₂p = 1,024 + 10 = 1,034 against 1,048,576 serial additions → speedup ≈ 1,014, efficiency ≈ 99% (ignoring memory limits) — reductions are work-efficient; the real cost is the memory sweep.

CPU (multicore)GPU (throughput)
Cores4-64 complex, out-of-orderthousands of simple lanes in SMs
Threads in flighttenstens of thousands
Cache per corelarge (MB of L2/L3)small L1/shared (KB), large shared L2
Latency handlingcaches, prefetch, OoOswitch warps (latency hiding)
Branchingbranch prediction, cheapdivergence serialises a warp
Best forirregular, branchy, latency-critical coderegular, data-parallel, high-bandwidth code
Peak bandwidth~50-400 GB/s (DDR5)~0.9-8 TB/s (HBM)
ModelMemory viewTypical useUnit of work
OpenMP / pthreadssharedone node, loopsthread
MPIdistributedclusters, PARAM systemsprocess + messages
CUDA / HIP / OpenCLhost + device, explicitGPU kernelsthread in a warp/block
MapReduce / Sparkdistributed filesdata analyticstask on a partition

Where it is used

Interview questions

Common mistakes

Related topics

Open in the Knowledge reader →Find jobs →