Algorithm Search⌘K

Problemadvanced

Hardware-software partitioning

Also called hardware/software codesign partitioning, HW/SW partitioning.

Split the tasks of a system between software on a processor and custom hardware to meet timing at the least cost, as in the Vulcan and COSYMA codesign systems.

Hardware-software partitioning decides, for each task of a system, whether it runs as software on a processor or as a custom hardware block, such as a coprocessor made by high-level synthesis. Hardware is faster but costs area, and moving data between the two sides costs time. The goal is the least running time within an area budget, or the least area that meets a deadline. With an area budget, the problem contains the knapsack problem and is NP-hard. With communication costs but no budget, it is a minimum cut and takes polynomial time. The codesign systems Vulcan (Gupta and De Micheli, 1993) and COSYMA (Ernst, Henkel and Benner, 1993) attacked it from opposite ends.

In plain words

A gadget has many jobs to do. Each job can run as a program on a cheap general processor, or as a special circuit that is much faster but takes chip area. The chip area is limited. If two jobs that talk a lot sit on different sides, the data must cross between processor and circuit, which costs time too. The task is to choose which jobs become circuits so that the whole gadget is as fast as possible without going over the area limit. It is like packing a bag: each job that becomes a circuit takes room and saves time, and the bag has a fixed size.

Definition

Input.

  • A set of nn tasks. Task ii takes time si≥0s_i \ge 0 in software and hi≥0h_i \ge 0 in hardware, and its hardware version has area ai≥0a_i \ge 0.
  • A communication cost cij≥0c_{ij} \ge 0 for each pair of tasks, paid when ii and jj are on different sides. It is 0 for tasks that do not exchange data.
  • An area budget AA.

Feasible solutions. A set HH of tasks to put in hardware, with ∑i∈Hai≤A\sum_{i \in H} a_i \le A. The other tasks run in software.

Objective. The processor and the hardware run one task at a time, so the time is

t(H)=∑i∉Hsi+∑i∈Hhi+∑{i,j}: ∣{i,j}∩H∣=1cij.t(H) = \sum_{i \notin H} s_i + \sum_{i \in H} h_i + \sum_{\{i, j\} :\ |\{i, j\} \cap H| = 1} c_{ij}.

Minimize t(H)t(H).

Decision form. Given the input and a time KK, is there a feasible HH with t(H)≤Kt(H) \le K?

The gain of task ii is gi=si−hig_i = s_i - h_i, the time saved by moving it to hardware. With no communication costs, t(H)=∑isi−∑i∈Hgit(H) = \sum_i s_i - \sum_{i \in H} g_i, so the problem is to choose tasks of largest total gain within the area budget.

Variants

  • Least area for a deadline. Fix the time bound KK and minimize ∑i∈Hai\sum_{i \in H} a_i. Vulcan works in this form.
  • Concurrent execution. The processor and the hardware run at the same time, so the time is the length of a schedule of the task graph, as in resource-constrained scheduling, not a sum.
  • Several processors and accelerators. Each task picks one of several targets, which is a form of module selection at the system level.
  • Granularity. The tasks can be processes, functions, loops or basic blocks. COSYMA partitions basic blocks, and finer grains give more choices and more communication.
  • Shared hardware. Two tasks in hardware may share units, so the area of HH is less than the sum of the aia_i. Then the cost depends on a later resource binding.
  • Energy. The objective is the energy, with a deadline, for battery-powered devices.

Examples

Four tasks. The tasks, with software time, hardware time and area, are P=(9,2,5)P = (9, 2, 5), Q=(6,1,4)Q = (6, 1, 4), R=(4,1,2)R = (4, 1, 2) and S=(7,3,3)S = (7, 3, 3), with no communication costs. All in software takes 9+6+4+7=269 + 6 + 4 + 7 = 26. The gains are 7,5,3,47, 5, 3, 4. The best time for each budget:

budget AA best HH time
5 {P}\{P\} or {R,S}\{R, S\} 19
6 {Q,R}\{Q, R\} 18
7 {P,R}\{P, R\} 16
9 {Q,R,S}\{Q, R, S\} or {P,Q}\{P, Q\} 14
14 all four 7

The task with the best gain per unit of area is RR (3 per 2), then PP (7 per 5), SS (4 per 3) and QQ (5 per 4). Taking tasks in this order while they fit gives {R,S}\{R, S\} with time 19 for budget 6, while {Q,R}\{Q, R\} gives 18. So the order by gain per area is not optimal.

Communication. Add a cost cQR=4c_{QR} = 4 to the example. With budget 6, {Q,R}\{Q, R\} still takes 18, since both are in hardware and pay nothing. With budget 4, {Q}\{Q\} takes 26−5+4=2526 - 5 + 4 = 25 and {R}\{R\} takes 26−3+4=2726 - 3 + 4 = 27, and {S}\{S\} takes 26−4=2226 - 4 = 22, the best. Communication makes tasks that talk prefer the same side.

Known algorithms

  • Dynamic programming. With no communication costs, the knapsack recurrence over the budget is exact in O(nA)O(nA) time for integer areas, which is pseudo-polynomial. See the knapsack problem.
  • Greedy by gain per area. Fast, and exact for the fractional relaxation, see fractional knapsack. The example shows it is not exact for whole tasks.
  • Integer programming. A 0-1 variable per task, and one per communicating pair, gives exact solutions for moderate sizes, see 0-1 integer programming.
  • Minimum cut. With no area budget, exact in polynomial time, as shown below.
  • Moves from all hardware. Vulcan (Gupta and De Micheli, 1993) starts with everything in hardware and moves operations to software while the timing constraints hold. Heuristic.
  • Moves from all software. COSYMA (Ernst, Henkel and Benner, 1993) starts with everything in software and moves basic blocks to hardware by simulated annealing until the time constraint holds. Heuristic.
  • Local search. Moves in the style of Kernighan-Lin swap tasks between the sides to reduce the communication. Heuristic.

Bounds

Lower bound. Every partition takes at least ∑imin⁡(si,hi)\sum_i \min(s_i, h_i), which is reached when the budget allows every task its faster side and there are no communication costs.

Fractional bound. With no communication costs, the best gain is at most the gain of the fractional relaxation, in which a task may be split. Taking tasks by gain per area and a fraction of the first that does not fit gives that relaxation. In the example with budget 6, it takes RR and 4/54/5 of PP, for a gain of 3+5.6=8.63 + 5.6 = 8.6, so no partition beats a time of 26−8.6=17.426 - 8.6 = 17.4. The best is 18.

Approximation. With no communication costs, the better of the greedy set and the single task of largest gain that fits has at least half of the best gain, as for the knapsack problem, and the knapsack approximation schemes apply to the gain.

Reductions

From knapsack, so NP-hard. Take a knapsack instance with values viv_i, weights wiw_i, capacity WW and target TT. Make task ii with si=vis_i = v_i, hi=0h_i = 0 and ai=wia_i = w_i, no communication costs, and budget A=WA = W. Then t(H)=∑ivi−∑i∈Hvit(H) = \sum_i v_i - \sum_{i \in H} v_i, and HH fits the budget exactly when its weight is at most WW. So some HH has t(H)≤∑ivi−Tt(H) \le \sum_i v_i - T exactly when some set of weight at most WW has value at least TT. The construction takes linear time, and a partition is checked in polynomial time, so the decision form is NP-complete. The areas carry the numbers of the knapsack instance, so this shows NP-hardness in the weak sense, matching the pseudo-polynomial dynamic program.

To minimum cut, with no budget. Take A=∑iaiA = \sum_i a_i, so every HH fits. Build a network with a source σ\sigma for software and a sink τ\tau for hardware, an arc σ→i\sigma \to i of capacity hih_i and an arc i→τi \to \tau of capacity sis_i for each task, and arcs i→ji \to j and j→ij \to i of capacity cijc_{ij} for each pair. For a cut with the side X∋σX \ni \sigma, put the tasks of XX in software and the others in HH. The cut contains i→τi \to \tau for each software task, σ→i\sigma \to i for each hardware task, and one arc of capacity cijc_{ij} for each pair split by the cut. So the cut capacity is exactly t(H)t(H), and a minimum cut gives an optimal partition. This is Stone's construction (1977) for assigning modules to two processors.

Applications

  • Embedded systems. Codesign tools choose which functions of a controller, a codec or a signal chain become accelerators.
  • FPGA systems on chip. Chips with a processor and programmable logic let the designer move functions between the two, and the partition is redone as the design evolves.
  • Accelerator offload. The choice of which kernels go to a GPU or an accelerator, with the data transfer cost, is the same problem with the bus as the communication cost. The speedup is limited by the software part, as in Amdahl's law.

References

  1. Rajesh K. Gupta and Giovanni De Micheli, Hardware-software cosynthesis for digital systems, IEEE Design and Test of Computers 10(3), 29 to 41, 1993, whole paper (the Vulcan system, which starts from an all-hardware design and moves operations to software under timing constraints)
  2. Rolf Ernst, Jörg Henkel and Thomas Benner, Hardware-software cosynthesis for microcontrollers, IEEE Design and Test of Computers 10(4), 64 to 75, 1993, whole paper (the COSYMA system, which starts from an all-software design and moves basic blocks to hardware by simulated annealing)
  3. Harold S. Stone, Multiprocessor scheduling with the aid of network flow algorithms, IEEE Transactions on Software Engineering SE-3(1), 1977, whole paper (the assignment of program modules to two processors with communication costs as a minimum cut)
  4. Michael R. Garey and David S. Johnson, Computers and Intractability, A Guide to the Theory of NP-Completeness, W. H. Freeman, 1979, Appendix A6, problem MP9, Knapsack

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a known algorithm
  • a contract.yaml