Hardware–software co-design and program modelling
Hardware–software co-design is the combined, iterative partitioning and modelling of a system into hardware and software parts so the final embedded product meets functional, timing, cost and power goals.
Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.
Why it matters
Hardware–software co-design is used when an engineer must decide which parts of an embedded function run as software on a processor and which parts become dedicated hardware (accelerators or peripherals). Correct co-design shortens time-to-market and meets constraints (deadline, area, power, cost) that neither pure hardware nor pure software alone can satisfy.
Key ideas
Finite-state machine (FSM): a 6-tuple (S, I, O, δ, λ, s0) where S = set of states, I = input alphabet, O = output alphabet, s0 ∈ S is the initial state; for a Mealy machine λ: S×I → O, for a Moore machine λ: S → O; δ: S×I → S (state transition function). Distinguish Moore FSM (output depends only on state) and Mealy FSM (output depends on state and input). Draw Mealy FSMs with edges labelled "input/output"; draw Moore FSMs with outputs labelled on states and edges labelled by inputs only.
Synchronous (clock-driven): components execute steps at discrete clock ticks; communication synchronises on ticks. Useful when synthesising hardware or modelling processors.
Asynchronous (event-driven): components react to events; no global clock. Useful for modelling interrupts and some communication protocols.
Dataflow: computation expressed as actors consuming and producing tokens on channels; actors fire when required tokens are present. Well-suited to signal processing and streaming tasks.
Program and system models used in co-design:
- Control-flow graph (CFG): nodes are basic blocks (straight-line code); directed edges show possible transfers of control. Used for static analysis such as cyclomatic complexity and path timing.
- Dataflow graph (DFG): nodes are operations, edges are data dependencies. Used for scheduling operations on hardware resources.
- Register-transfer level (RTL): hardware description in terms of registers and combinational logic between register transfers; the target of synthesis.
- Transaction-level modelling (TLM): an abstract model where communication is described as transactions (reads/writes) rather than signal-level handshakes; used to speed simulation and to prototype HW/SW interfaces.
Hardware/software partitioning problem (formal statement):
- Given: a set of tasks (or functions) T with attributes: software execution cost Cs(t) (time on processor), hardware execution time Th(t) (latency if implemented in hardware), and hardware area cost Ah(t) (area/gates); optionally include energy Es(t), Eh(t). Also given constraints: total area A_max, power P_max, timing deadline D.
- Objective: choose subset H ⊆ T to implement in hardware to minimise overall execution time (or energy or cost), subject to constraints. This is an optimisation problem, often NP-hard.
Common solution methods:
- Exact: Integer Linear Programming (ILP), Branch-and-bound. Requires small problem sizes.
- Heuristics: greedy selection by benefit-per-cost ratio, iterative refinement, simulated annealing, genetic algorithms. These scale better and give near-optimal solutions.
Co-synthesis loop (practical steps):
- Model application: extract CFG and DFG from source code.
- Estimate costs: Cs, Ch, memory, communication overhead.
- Partition: apply ILP or heuristics to pick H.
- Generate hardware model (RTL or HLS-generated RTL) and software (drivers, API).
- Integrate and simulate (cycle-accurate or transaction-level) and measure.
- Refine: adjust partition and repeat until constraints are met.
HW/SW interface concerns: memory-mapped registers, interrupts, DMA (direct memory access), bus arbitration. When drawing, show: processor block, memory block, bus, accelerator block, arrows for data (label widths in bits), arrows for control (interrupt lines), and labels for protocols (e.g., AMBA, AXI). Include latency and throughput annotations.
Timing and performance modelling basics:
- Instruction count (IC): number of executed instructions.
- Cycles per instruction (CPI): average cycles per instruction.
- Clock period (Tc) or frequency f.
- Use these to estimate software run-time and combine with hardware latencies for system-level timing.
Assumptions stated: processor execution times are average or estimated worst-case; communication overhead between HW and SW can be non-negligible and must be included in cost estimates.
Formulas
T_sw = IC · CPI · Tc — where T_sw is execution time (s), IC is instruction count (dimensionless), CPI is cycles per instruction (cycles/instruction), Tc is clock period (s/cycle). Applies for single-threaded program execution estimation.
f = 1 / Tc — clock frequency (Hz = s^-1), Tc in seconds.
P_dyn = α · C_L · V^2 · f — dynamic power (W), where 0 ≤ α ≤ 1 is the switching activity factor (dimensionless), C_L is load capacitance (F), V is supply voltage (V), f is switching frequency (Hz). Many texts fold α·C_L into an effective C_eff; explicitly state which you use. Applies to CMOS dynamic power; ignores static/leakage power.
Speedup_total = 1 / ((1 - f_accel) + f_accel / S) — Amdahl's law: total speedup when fraction f_accel of execution is accelerated by factor S. f_accel is fraction of original execution time (dimensionless). Assumes perfect parallelism within accelerated fraction and no extra overhead.
Cyclomatic complexity V(G) = E - N + 2P — where E = number of edges in CFG, N = number of nodes, P = number of connected components (usually 1). Used to count independent paths for testing.
Worked examples
- Hardware acceleration, Amdahl application
Given: A program runs in 100.0 s on software. A portion f_accel = 0.30 (30%) of runtime can be moved to a hardware accelerator that runs that portion S = 10 times faster. Find new total time and speedup.
Step 1 — Apply Amdahl's law formula:
Speedup_total = 1 / ((1 - f_accel) + f_accel / S).
Step 2 — Substitute numbers:
Speedup_total = 1 / ((1 - 0.30) + 0.30 / 10) = 1 / (0.70 + 0.03) = 1 / 0.73 ≈ 1.36986.
Step 3 — New total time = original time / Speedup_total = 100.0 s / 1.36986 = 73.0 s.
Answer: New total time = 73.0 s, overall speedup ≈ 1.37×.
Notes: This ignores overheads (driver calls, data movement). If overhead is known, include it as additional time in the non-accelerated fraction before applying Amdahl.
- Estimating software runtime from IC/CPI/clock
Given: Instruction count IC = 200×10^6 instructions, average CPI = 1.5 cycles/instruction, clock frequency f = 200 MHz.
Step 1 — Clock period Tc = 1 / f = 1 / (200×10^6 Hz) = 5.0×10^-9 s = 5.0 ns.
Step 2 — Use T_sw = IC · CPI · Tc:
T_sw = 200e6 · 1.5 · 5.0e-9 s = (200e6 · 1.5) · 5e-9 = 300e6 · 5e-9 = 1.5 s.
Answer: Execution time = 1.5 s.
- Control-flow graph and cyclomatic complexity (small program)
Function: int f(int x) { if (x > 0) x = x + 1; else x = x - 1; for (int i = 0; i < 3; ++i) x = x * 2; return x; }
Step 1 — Basic blocks (nodes): B1 (entry + if cond), B2 (then), B3 (else), B4 (for-condition), B5 (for-body), B6 (exit). So N = 6.
Step 2 — Edges: B1→B2, B1→B3 (2); B2→B4 (1); B3→B4 (1); B4→B5 (true) and B4→B6 (false) (2); B5→B4 (back edge) (1). Total E = 7.
Step 3 — Cyclomatic complexity: V(G) = E - N + 2P = 7 - 6 + 2·1 = 3.
Answer: Cyclomatic complexity = 3 (three independent paths).
Common mistakes
- Mixing average-case and worst-case numbers without noting assumptions: e.g., using average CPI but expecting worst-case deadline guarantees.
- Forgetting to include memory hierarchy effects (cache misses, DMA setup) in Cs estimates.
- Using cyclomatic complexity to measure code quality or runtime performance — it only measures control-flow complexity for testing.
- Not modelling interrupts and shared resource contention when doing worst-case analysis for real-time systems.
For your exam
Question types you will see:
- Definitions (e.g., define hardware–software co-design, model of computation, FSM). Full answer: short formal definition plus one-line example.
- Short notes (advantages of co-design, steps in co-synthesis). Full answer: list with brief explanation and when to use.
- Derivations (derive Amdahl's law, derive T = IC·CPI·Tc). Full answer: show algebraic steps and assumptions.
- Numericals (apply Amdahl to given times, compute execution time from IC/CPI/clock). Full answer: show formula, substitute, show units and final bold result.
- Programs/algorithms (draw CFG or DFG for a function and compute cyclomatic complexity). Full answer: draw labelled nodes and edges, count N and E, compute V(G).
- Diagrams (sketch HW/SW integration). Full answer: draw processor, memory, bus, accelerator, label data/control, and explain handshaking or interrupt lines.
What a full-marks answer includes: clear definitions (bold term if asked), stated assumptions, correct formula or model, step-by-step calculation with units, and explicit discussion of overheads and constraints where relevant.
Quick check
- What is a model of computation (MoC)?
- State Amdahl's law in one formula and explain each symbol.
- How do you compute cyclomatic complexity from a CFG?
Answers: 1. A formal abstraction describing how components compute and communicate (e.g., FSM, synchronous, dataflow). 2. Speedup_total = 1 / ((1 - f_accel) + f_accel / S), where f_accel is fraction of original runtime accelerated and S is acceleration factor. 3. V(G) = E - N + 2P where E = edges, N = nodes, P = connected components (usually 1).
Finished this topic? Mark it so your progress, study plan and readiness keep up.
Stuck on something here?