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

LevelGranularityMechanismExample
Bit-levelWithin a wordWider data paths64-bit vs 32-bit ALU
Instruction-level (ILP)Within a threadPipeline, superscalar, OOOOut-of-order execution
Data-level (DLP)SIMD / vectorSingle op on multiple dataAVX-512, GPU shader
Thread-level (TLP)Multiple threadsSMT, multi-coreHyper-Threading
Task-levelProcesses / nodesOS scheduling, MPICluster computing

Instruction-Level Parallelism (ILP)

ILP is the number of independent instructions in a program that can execute simultaneously.

Limits on ILP:

HazardDescription
RAW (true dependence)Instruction needs result of previous — cannot overlap
WAR, WAW (false dependences)Eliminated by register renaming
Control dependencesBranch outcome unknown until resolved
Memory aliasingUnknown whether two addresses overlap

Techniques to exploit ILP:

TechniqueDescription
PipeliningOverlap stages of different instructions
SuperscalarIssue multiple instructions per cycle
Out-of-order executionIssue instructions when ready, not in program order
Speculative executionExecute past branches using prediction
VLIWCompiler-scheduled wide issue

SIMD / Vector Parallelism

One instruction operates on a vector of values simultaneously.

x86 SIMD Extensions

ExtensionRegister widthIntegerFPYear
MMX64-bit8-/16-/32-bit1997
SSE128-bit32-bit × 41999
SSE2128-bit8–64-bit32/64-bit2001
AVX256-bit32/64-bit2011
AVX2256-bit8–64-bit32/64-bit2013
AVX-512512-bit8–64-bit16/32/64-bit2017
AMX2D tile (1 KB)INT8BF162022

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).

ResourceShared?
Execution units (ALU, FPU, Load/Store)Yes
L1/L2 cachesYes
Branch predictorUsually shared
Program counterNo (per thread)
RegistersNo (per thread, renamed)
ROB / RS entriesPartitioned 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.

CoresBenefitLimit
More coresScale with parallelizable workAmdahl's Law, power, memory bandwidth
Bigger L3Less off-chip traffic per coreArea/cost
More memory channelsHigher aggregate bandwidthPackage 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 coresSpeedup with 64 coresSpeedup with ∞ cores
5%3.48×15.4×20×
10%3.08×8.8×10×
25%2.29×3.82×
50%1.60×1.97×

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

PrimitiveDescription
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-addAtomically add and return old value
Load-linked / Store-conditional (LL/SC)ARM, RISC-V; SC succeeds only if no intervening write
Memory fence / barrierPrevents reordering across the barrier
Mutex / lockSoftware construct built on atomics
SemaphoreCounter-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:

ConceptGPU termDescription
CoreCUDA Core / Shader UnitSingle FP/INT ALU
Warp / WavefrontWarp (NVIDIA, 32 threads) / Wavefront (AMD, 64)Group executing same instruction
SM / CUStreaming Multiprocessor / Compute UnitCluster of cores + shared memory
Global memoryVRAMHBM/GDDR on GPU card
Shared memoryScratchpad (L1 per SM)Fast, manually managed, per-SM
Thread divergenceBranches within a warpInactive threads masked, not executed in parallel

NVIDIA H100 (Hopper) overview:

PropertyValue
SM count132
CUDA cores per SM128
Total CUDA cores16,896
FP32 peak67 TFLOPS
FP16 (Tensor Core)1,979 TFLOPS with sparsity (~990 dense)
HBM3 memory80 GB
Memory bandwidth3.35 TB/s

Multi-Processor Interconnects

Network topologyDescriptionUsed in
BusAll nodes share one mediumOld SMPs
CrossbarEvery pair has a dedicated pathSmall clusters, GPU interconnects
Fat-treeHierarchical; full bisection bandwidthInfiniBand HPC clusters
Torus (2D, 3D)Grid with wrap-around edges; short avg. pathIBM Blue Gene, Cray
DragonflyGroups connected by all-to-all + inter-group linksHPE 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).