Techniqueresearch
Memory partitioning for high-level synthesis
Also called array partitioning, cyclic and block memory partitioning.
Splits an array over several memory banks by a cyclic, block or linear mapping so that the accesses of one pipelined loop iteration hit different banks.
Memory partitioning splits one array of a high-level synthesis design over several memory banks, each a separate on-chip RAM with its own ports. A loop that is pipelined to start one iteration per cycle, or unrolled by loop unrolling, may read several elements of the array in the same cycle, but one RAM has only one or two ports. The partition picks a bank function, which sends element to bank , and an offset function, which gives its address inside the bank, so that the accesses of one iteration fall in different banks. The two classic choices are block partitioning, which cuts the array into contiguous pieces, and cyclic partitioning, which deals the elements out to the banks in turn, . For accesses , the cyclic partition is free of conflicts in every iteration exactly when no more than offsets share a remainder modulo , for banks with ports.
In plain words
An on-chip memory can hand out only one or two numbers per clock tick. A fast loop may want three numbers from the same list in every tick. If the whole list sits in one memory, the loop has to wait. So we cut the list into several smaller memories that work side by side. The trick is to cut so that the numbers one tick wants always come from different memories. Cutting the list into long pieces works badly when the loop reads neighbours, since neighbours sit in the same piece. Dealing the list out like cards, one item to each memory in turn, puts neighbours in different memories, and the loop never waits.
When it applies
- The array lives on chip, in block RAMs or SRAM macros with one or two ports each.
- A loop is pipelined with a target initiation interval, often 1, or unrolled, and its schedule needs more accesses to the array per cycle than the ports allow. The modulo scheduler then reports a resource bound on the initiation interval set by the memory ports.
- The indices are affine functions of the loop variables, such as or , so the bank of each access can be computed at compile time or by a small adder and a modulo. Such indices are what the polyhedral model describes.
The template
Take a one-dimensional array of size , banks with ports each, and a loop body with the references in one iteration, with integer offsets , after unrolling.
CYCLIC-PARTITION(S, p, c_1, ..., c_m)- 1
N ← ⌈m / p⌉ - 2
while some remainder ρ modulo N has more than p of the offsets c_k with c_k ≡ ρ (mod N) do N ← N + 1 - 3
for each element x: B(x) ← x mod N and F(x) ← ⌊x / N⌋ - 4
make N memories of ⌈S / N⌉ words each, and store A[x] at address F(x) of bank B(x) - 5
replace each reference A[i + c_k] by bank (i + c_k) mod N at address ⌊(i + c_k) / N⌋ - 6
build a multiplexer from the N banks to each of the m references, selected by (i + c_k) mod N - 7
return N, B, F
The holes are the bank function of L3 (cyclic, block, block-cyclic or linear), the number of ports , and the routing of L6, which grows with .
Why the test of L2 is exact. In iteration , reference goes to bank . Two references and go to the same bank exactly when divides , which does not depend on . So the references that hit one bank in iteration are exactly those whose offsets share one remainder modulo , and they fit in one cycle exactly when there are at most of them. The same sets appear in every iteration, so the check over the remainders covers all iterations at once.
Why L2 stops. Once , all the differences with lie strictly between and and are not multiples of , so distinct offsets have distinct remainders. Equal offsets read the same element, and a compiler merges them into one access. So the loop ends with . It never ends below , since accesses need at least that many banks of ports. Both bounds can be tight: offsets with need exactly banks.
Block partitioning. Here and . Neighbouring elements share a bank, so it suits loops whose parallel accesses are far apart, such as two halves of an array processed at once.
Classic examples
Least banks for common access patterns. For the cyclic partition, the least found by L1 and L2:
| offsets | one port | two ports |
|---|---|---|
| 3 | 2 | |
| 3 | 2 | |
| 4 | 2 | |
| 3 | 3 | |
| 3 | 1 | |
| 4 | 2 | |
| 6 | 2 |
For with two ports, puts all three offsets in bank 0, so is the least, above the bound . For with one port, and both put two offsets together ( and ), so 6 banks are needed.
Block against cyclic. A 12-element array is read by the loop with the references , and each bank has one port. With 3 blocks of 4 elements, iteration 0 reads elements 0, 1 and 2, all in bank 0, so it takes 3 cycles. Over the 10 iterations, the block partition takes cycles. The cyclic partition into 3 banks reads the three elements from three different banks in every iteration, and takes 10 cycles, one per iteration.
A two-dimensional stencil. A 5-point stencil reads , and . Cyclic partitioning along one dimension leaves two of the five references in the same bank for any number of banks, since , and differ in only and the two references have the same as . The linear bank function maps the five offsets to , all different, so 5 single-port banks suffice, and fewer is impossible with 5 accesses. Wang, Li and Cong (2014) search such linear functions for general patterns.
Variations
- Block-cyclic. Deal out blocks of elements in turn, . It covers loops that read groups of neighbours.
- Linear partitioning for several dimensions. Use with an integer vector . The test of L2 becomes a test on the values modulo .
- Scheduling with the partition. Cong, Jiang, Liu and Zou (2009, 2011) let the accesses of one iteration spread over the cycles of the initiation interval, so a bank may serve of them, and choose the schedule and the partition together.
- Padding. When the offset function needs a division by an awkward , pad each row or round up to a power of two, so that and are bit fields. This costs memory and may raise .
- Duplication. A read-only array can be copied into several memories, one per reference, at the cost of memory and of keeping the copies equal when written.
- Reshaping. Packing several elements into one wide word lets one port read them all, which helps when the accesses are neighbours.
Pitfalls
- Non-affine or data-dependent indices. For with an unknown , no static bank function avoids conflicts, and the tool must keep a conservative schedule or add arbitration.
- The routing cost. Each of the references needs a multiplexer over the banks, so a large adds wide multiplexers that may lengthen the clock period, see resource binding for the same trade-off with units.
- Division and modulo hardware. With a general , the address needs a divider unless it is computed by counters that step with .
- Size not divisible by . The last bank is shorter, or every bank gets words and some stay unused.
- Accesses across loops. A partition chosen for one loop may cause conflicts in another loop that reads the same array in a different pattern.
Exercises
- Find the least number of single-port banks for the cyclic partition of the offsets , and explain why fails.
- Prove that for offsets and banks with ports, the least cyclic is .
- For the 5-point stencil, find every for which sends the five offsets to five different banks.
- A loop reads and in each iteration. Compare the block partition into 2 banks with the cyclic one, and say which needs a wider multiplexer.
References
- Jason Cong, Wei Jiang, Bin Liu and Yi Zou, Automatic memory partitioning and scheduling for throughput and power optimization, ACM Transactions on Design Automation of Electronic Systems 16(2), 2011, whole paper (cyclic partitioning of arrays for loop pipelining, with the accesses scheduled over the initiation interval; first presented at ICCAD 2009)
- Yuxin Wang, Peng Li and Jason Cong, Theory and algorithm for generalized memory partitioning in high-level synthesis, Proceedings of the ACM/SIGDA International Symposium on Field-Programmable Gate Arrays, 2014, whole paper (linear bank functions for multidimensional arrays and the search for the fewest banks)
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.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag JWEWY8 Edit this page History Report an error Markdown