Computer Architecture Cheatsheet
Parallelism
Use this Computer Architecture reference while you build software engineering projects, review code for technical interview prep, or polish examples for a software engineer resume.
Levels of Parallelism
| Level | Granularity | Mechanism | Example |
|---|---|---|---|
| Bit-level | Within a word | Wider data paths | 64-bit vs 32-bit ALU |
| Instruction-level (ILP) | Within a thread | Pipeline, superscalar, OOO | Out-of-order execution |
| Data-level (DLP) | SIMD / vector | Single op on multiple data | AVX-512, GPU shader |
| Thread-level (TLP) | Multiple threads | SMT, multi-core | Hyper-Threading |
| Task-level | Processes / nodes | OS scheduling, MPI | Cluster computing |
Instruction-Level Parallelism (ILP)
ILP is the number of independent instructions in a program that can execute simultaneously.
Limits on ILP:
| Hazard | Description |
|---|---|
| RAW (true dependence) | Instruction needs result of previous — cannot overlap |
| WAR, WAW (false dependences) | Eliminated by register renaming |
| Control dependences | Branch outcome unknown until resolved |
| Memory aliasing | Unknown whether two addresses overlap |
Techniques to exploit ILP:
| Technique | Description |
|---|---|
| Pipelining | Overlap stages of different instructions |
| Superscalar | Issue multiple instructions per cycle |
| Out-of-order execution | Issue instructions when ready, not in program order |
| Speculative execution | Execute past branches using prediction |
| VLIW | Compiler-scheduled wide issue |
SIMD / Vector Parallelism
One instruction operates on a vector of values simultaneously.
x86 SIMD Extensions
| Extension | Register width | Integer | FP | Year |
|---|---|---|---|---|
| MMX | 64-bit | 8-/16-/32-bit | — | 1997 |
| SSE | 128-bit | — | 32-bit × 4 | 1999 |
| SSE2 | 128-bit | 8–64-bit | 32/64-bit | 2001 |
| AVX | 256-bit | — | 32/64-bit | 2011 |
| AVX2 | 256-bit | 8–64-bit | 32/64-bit | 2013 |
| AVX-512 | 512-bit | 8–64-bit | 16/32/64-bit | 2017 |
| AMX | 2D tile (1 KB) | INT8 | BF16 | 2022 |
Example: adding 8 pairs of floats in one AVX instruction vs 8 scalar adds:
// Scalar: 8 iterations for (int i = 0; i < 8; i++) c[i] = a[i] + b[i]; // AVX (conceptually): one instruction __m256 va = _mm256_loadu_ps(a); // load 8 floats __m256 vb = _mm256_loadu_ps(b); // load 8 floats __m256 vc = _mm256_add_ps(va, vb); // add 8 pairs
Thread-Level Parallelism (TLP)
SMT (Simultaneous Multi-Threading)
Multiple hardware threads (logical processors) share the same physical core's execution units. Intel calls this Hyper-Threading (HT).
| Resource | Shared? |
|---|---|
| Execution units (ALU, FPU, Load/Store) | Yes |
| L1/L2 caches | Yes |
| Branch predictor | Usually shared |
| Program counter | No (per thread) |
| Registers | No (per thread, renamed) |
| ROB / RS entries | Partitioned or shared |
HT adds ~5–30% throughput for mixed workloads; may reduce single-thread performance (resource competition). Disabled on some security-sensitive servers (Spectre-class attacks).
Multi-Core
Multiple complete CPU cores on one die, sharing L3 cache and memory controller.
| Cores | Benefit | Limit |
|---|---|---|
| More cores | Scale with parallelizable work | Amdahl's Law, power, memory bandwidth |
| Bigger L3 | Less off-chip traffic per core | Area/cost |
| More memory channels | Higher aggregate bandwidth | Package pins |
Amdahl's Law
S(n) = 1 / (s + (1 − s) / n)
Where: - S(n) = speedup with n processors - s = serial fraction (cannot be parallelized) - (1 − s) = parallelizable fraction
| Serial fraction (s) | Speedup with 4 cores | Speedup with 64 cores | Speedup with ∞ cores |
|---|---|---|---|
| 5% | 3.48× | 15.4× | 20× |
| 10% | 3.08× | 8.8× | 10× |
| 25% | 2.29× | 3.82× | 4× |
| 50% | 1.60× | 1.97× | 2× |
Amdahl's Law shows that the serial fraction dominates at large core counts. Reducing s is more valuable than adding cores.
Gustafson's Law (Scaled Speedup)
When the problem size scales with the number of processors:
S(n) = n − s(n − 1)
More optimistic: if you fix time and scale problem size, efficiency stays high. Models scientific computing (e.g., larger simulations, not the same simulation faster).
Memory Consistency and Synchronization
Synchronization Primitives
| Primitive | Description |
|---|---|
| Atomic compare-and-swap (CAS) | if (*addr == expected) *addr = new; return old — indivisible |
| Test-and-set (TAS) | Atomically write 1 and return old value |
| Fetch-and-add | Atomically add and return old value |
| Load-linked / Store-conditional (LL/SC) | ARM, RISC-V; SC succeeds only if no intervening write |
| Memory fence / barrier | Prevents reordering across the barrier |
| Mutex / lock | Software construct built on atomics |
| Semaphore | Counter-based; up/down operations |
Lock Implementation (x86)
// Compare-and-swap spin lock void lock(int *l) { while (__sync_val_compare_and_swap(l, 0, 1) != 0) _mm_pause(); // hint to CPU: spin loop } void unlock(int *l) { __sync_lock_release(l); // atomic store 0 with release fence }
Cache Effects on Synchronization
- False sharing: two threads write to different variables that share a cache line. Cache coherence thrashes the line between cores even though the threads don't logically share data. - Fix: pad variables to 64-byte (cache line) boundaries.
// Bad: x and y share a cache line struct { int x; int y; } shared; // Good: each on its own line struct { int x; char _pad[60]; int y; char _pad2[60]; } padded;
GPU Architecture
GPUs exemplify SIMT (Single Instruction Multiple Threads) — a hardware variant of SIMD:
| Concept | GPU term | Description |
|---|---|---|
| Core | CUDA Core / Shader Unit | Single FP/INT ALU |
| Warp / Wavefront | Warp (NVIDIA, 32 threads) / Wavefront (AMD, 64) | Group executing same instruction |
| SM / CU | Streaming Multiprocessor / Compute Unit | Cluster of cores + shared memory |
| Global memory | VRAM | HBM/GDDR on GPU card |
| Shared memory | Scratchpad (L1 per SM) | Fast, manually managed, per-SM |
| Thread divergence | Branches within a warp | Inactive threads masked, not executed in parallel |
NVIDIA H100 (Hopper) overview:
| Property | Value |
|---|---|
| SM count | 132 |
| CUDA cores per SM | 128 |
| Total CUDA cores | 16,896 |
| FP32 peak | 67 TFLOPS |
| FP16 (Tensor Core) | 1,979 TFLOPS with sparsity (~990 dense) |
| HBM3 memory | 80 GB |
| Memory bandwidth | 3.35 TB/s |
Multi-Processor Interconnects
| Network topology | Description | Used in |
|---|---|---|
| Bus | All nodes share one medium | Old SMPs |
| Crossbar | Every pair has a dedicated path | Small clusters, GPU interconnects |
| Fat-tree | Hierarchical; full bisection bandwidth | InfiniBand HPC clusters |
| Torus (2D, 3D) | Grid with wrap-around edges; short avg. path | IBM Blue Gene, Cray |
| Dragonfly | Groups connected by all-to-all + inter-group links | HPE Slingshot, large HPC |
Bisection bandwidth: bandwidth across a cut that divides the network into two equal halves. Key metric for all-to-all communication (e.g., MPI Allreduce in deep learning).