Elective Computer Architecture

Computer ArchitectureUnit 79 min read

Pipelining & Parallelism: Hazards, Speedup, Flynn’s Taxonomy & Multicore

Unit 7 of Computer Architecture covers pipelining stages, hazards (structural, data, control), speedup calculations, Flynn’s taxonomy (SISD/SIMD/MISD/MIMD), and multicore parallelism with real-world examples from eSewa, Ncell, and YouTube.

Key points

  • Pipelining breaks instructions into stages (IF/ID/EX/MEM/WB) to overlap execution, but hazards (data dependencies, branch mispredictions) stall the pipeline.
  • Speedup = \( \frac{\text{Number of stages}}{\text{1 + average stalls per instruction}} \), so a 5-stage pipeline with 1 stall per 10 instructions achieves 4.8× speedup.
  • Flynn’s taxonomy classifies computers by instruction/thread parallelism: SIMD (e.g., GPU rendering) vs. MIMD (e.g., cloud servers).
  • Multicore systems use shared memory (UMA) or distributed memory (NUMA) to parallelize tasks, but suffer from Amdahl’s law (sequential bottlenecks).
  • Real-world: YouTube’s transcoding uses SIMD for video encoding; eSewa’s payment queues use pipelined I/O.
  • ```

1. Pipelining: The Assembly Line of Computers

1.1 How Pipelining Works

Pipelining divides instruction execution into stages, like an assembly line. Each stage processes a different instruction simultaneously while passing partial results to the next stage.

IF: Instruction FetchID: Instruction DecodeEX: ExecuteMEM: Memory AccessWB: Write Back
5-stage pipeline stages with EX stage highlighted (where ALU operations occur)
graph LR
    A["IF: Instruction Fetch"] --> B["ID: Instruction Decode"]
    B --> C["EX: Execute"]
    C --> D["MEM: Memory Access"]
    D --> E["WB: Write Back"]
    E --> A

Stages in a 5-stage pipeline:

  1. IF (Instruction Fetch): Fetch opcode from memory.
  2. ID (Instruction Decode): Decode opcode, read registers.
  3. EX (Execute): Perform ALU operations (e.g., ADD R1, R2, R3).
  4. MEM (Memory Access): Load/store data (if needed).
  5. WB (Write Back): Write result to register.

Example: Fetching ADD R1, R2, R3 while decoding SUB R4, R5, R6, executing ADD, etc.


1.2 Pipelining Hazards & Solutions

Hazards occur when stages cannot proceed as planned. There are three types:

stateDiagram-v2
  [*] --> IF
  IF --> ID: Fetch
  ID --> EX: Decode
  EX --> MEM: Execute
  MEM --> WB: Memory Access
  WB --> [*]: Write Back
  EX --> EX: Data Hazard (stall)
  EX --> EX: Forwarding (bypass)
  EX --> EX: Branch Prediction
State diagram showing pipeline stalls, forwarding, and branch prediction
Hazard Type Cause Example Solution
Structural Resource conflict (e.g., two ALUs) ADD and MUL both need ALU Add more hardware (dual ALUs)
Data Read-after-write dependency ADD R1, R2, R3 → SUB R4, R1, R5 Forwarding (bypass) or stalling
Control (Branch) Mispredicted branch BEQ R1, R2, Label (jump) Delayed branching or branch prediction

Worked Example (Data Hazard):

LW R1, 0(R2)   // Load word from memory to R1 (takes 2 cycles)
ADD R3, R1, R4 // Needs R1 (ready in cycle 3)
  • Problem: ADD needs R1 in cycle 2, but LW writes R1 in cycle 3 → stall.
  • Solution: Forward R1 from MEM stage to EX stage (bypass).

1.3 Speedup & Efficiency

Ideal speedup = Number of pipeline stages (e.g., 5-stage → 5× faster). Real-world speedup is lower due to hazards: Example: A 5-stage pipeline with 1 stall every 10 instructions:


2. Flynn’s Taxonomy: Classifying Parallel Computers

Flynn’s taxonomy categorizes computers by instruction stream (I) and data stream (D) parallelism:

Single CPU (e.g., Intel Core i5)SISDGPU (e.g., NVIDIA RTX 3060)YouTube transcodingSIMDPipeline stages (rare)MISDCloud servers (AWS EC2)eSewa payment processingMIMDFlynn’s Taxonomy
Type Instruction Streams Data Streams Example Used in
SISD Single Single Traditional CPU (e.g., Intel Core i5) Desktop PCs
SIMD Single Multiple GPU (NVIDIA RTX 3060) Video encoding (YouTube), AI training
MISD Multiple Single Rare (e.g., pipeline stages) Pipelined processors
MIMD Multiple Multiple Cloud servers (AWS EC2) Distributed databases (eSewa)

Real-World Tie-In:

  • YouTube’s transcoding uses SIMD to encode multiple video streams simultaneously on GPUs.
  • eSewa’s payment processing uses MIMD: multiple servers handle different transactions in parallel.

3. Multicore & Multiprocessor Systems

3.1 Shared Memory vs. Distributed Memory

Type Memory Model Communication Example
UMA (SMP) Uniform Memory Access Shared bus/cache Dual-core Intel i7
NUMA Non-Uniform Access High-speed interconnect Supercomputers (IBM)
Distributed Separate memory Message passing Cluster (Hadoop)

Amdahl’s Law: Limits speedup due to sequential bottlenecks. Where:

  • = Fraction of code parallelizable
  • = Number of cores

Example: If 80% of code is parallelizable () on 4 cores:


3.2 Real-World: Ncell’s Load Balancing

Ncell’s 4G base stations use multicore processors to handle:

  • SIMD: Parallel signal processing for multiple users.
  • MIMD: Different cores manage handover, billing, and encryption.

4. Pipelining in I/O Systems

4.1 Programmed I/O vs. Interrupt-Driven I/O vs. DMA

Method How It Works Pros Cons
Programmed I/O CPU polls device until ready Simple Wastes CPU cycles
Interrupt I/O Device sends interrupt on completion Efficient Latency for frequent interrupts
DMA Dedicated hardware transfers data Zero CPU overhead Complex hardware
Polling (Programmed I/O)InterruptDMA TransferCPUDeviceMemory
Comparison of I/O methods: polling, interrupts, and DMA

Example (DMA in eSewa): When you pay via eSewa, the DMA controller transfers transaction data directly to memory without CPU intervention, reducing latency.


In the Real World

  1. YouTube (SIMD):

    • Uses GPU pipelines (SIMD) to encode videos in parallel. A single RTX 3060 can transcode 4K video streams simultaneously using AV1 encoding (SIMD instructions like AVX-512).
  2. eSewa (MIMD + Pipelining):

    • MIMD: Multiple servers handle payments, KYC, and notifications in parallel.
    • Pipelining: Transaction processing stages (authentication → deduction → confirmation) overlap like an assembly line.
  3. Ncell 5G Base Stations (Multicore + SIMD):

    • Quad-core ARM processors run:
      • Core 1: Signal modulation (SIMD for parallel users).
      • Core 2: Handover management (MIMD).
      • Core 3: Encryption (AES-NI SIMD).
      • Core 4: Billing (sequential).

Exam Tip

  1. Pipelining Questions:

    • Always draw the 5-stage pipeline diagram for any hazard question.
    • For speedup: State the formula and plug in numbers (e.g., "3 stalls per 10 instructions → speedup = 5/1.3 ≈ 3.85×").
  2. Flynn’s Taxonomy:

    • Memorize the table (SISD/SIMD/MISD/MIMD) and match examples (GPU = SIMD, cloud = MIMD).
    • Common pitfall: Confusing SIMD (same instruction, multiple data) with MIMD (multiple instructions, multiple data).
  3. Multicore:

    • Amdahl’s Law is tested: If 90% is parallelizable, even 100 cores give only 10× speedup.
    • NUMA vs. UMA: NUMA has non-uniform access times (critical for databases like eSewa).
  4. I/O Methods:

    • Programmed I/O is busy-waiting (bad for high-speed devices like SSDs).
    • DMA is used in network cards, GPUs, and storage controllers (e.g., NVMe SSDs).

5 stage pipeline diagramLabel stages IF/ID/EX/MEM/WB with arrows showing overlap. (Image: Inductiveload, Public domain, via Wikimedia Commons)

In the real world

  • YouTube (SIMD): Uses NVIDIA GPUs (e.g., RTX 3060) with AV1 encoding to process 4K video streams in parallel via SIMD instructions like AVX-512, reducing transcoding time by ~80% compared to single-core CPUs.
  • eSewa (MIMD + Pipelining): MIMD distributes transactions across servers (e.g., Core 1: Authentication, Core 2: Deduction, Core 3: Confirmation), while pipelining overlaps stages (e.g., KYC check → payment → notification) to handle 10,000+ transactions/sec.
  • Ncell 5G (Multicore + SIMD): Quad-core ARM processors in base stations use SIMD for parallel signal processing (e.g., FFT for 4G/5G modulation) and MIMD for handover management, reducing latency by ~30% vs. single-core systems.

Based on the PU BE Computer (PU) syllabus for Computer Architecture, unit 7.

Discussion

Loading…