BACKGROUND OF THE INVENTION
Field of the Invention
[0001] The present invention relates, in general, to improving processing efficiency in
reconfigurable hardware. More specifically, the invention relates to optimizing the
compilation of algorithms on reconfigurable hardware to reduce the time required to
execute a program on the hardware.
Relevant Background
[0002] As microprocessors continue to increase rapidly in processing power, they are used
more often to do computationally intensive calculations that were once exclusively
done by supercomputers. However, there are still computationally intensive tasks,
including compute-intensive image processing and hydrodynamic simulations that can
take significant amounts of time to execute on modern microprocessors.
[0003] Paralleling the progress of microprocessors, reconfigurable hardware such as field
programmable gate arrays (FPGAs) has made advances both in terms of increased circuit
density as well as ease of reprogramming, among other areas. Originally developed
as simple logic for interconnecting components on digital systems, reconfigurable
hardware has become so easy to reprogram that it can be used today as reconfigurable
logic for executing a program.
[0004] A number of advantages may be realized when the reconfigurable hardware can be reprogrammed
to meet the needs of individual programs. For example, the reconfigurable hardware
may be programmed with a logic configuration that has more parallelism and pipelining
characteristics than a conventional microprocessor. Also, the reconfigurable hardware
may be programmed with a custom logic configuration that is very efficient for executing
the tasks assigned by the program. Furthermore, dividing a program's processing requirements
between the microprocessor and the reconfigurable hardware may increase the overall
processing power of the computer.
[0005] Unfortunately, an important stumbling block for users who may wish to take advantage
of reconfigurable hardware is the difficulty of programming the hardware. Conventional
methods of programming reconfigurable hardware included the use of hardware description
languages (HDLs); low-level languages that require digital circuit expertise as well
as explicit handling of timing.
[0006] Progress has been made in the development of technology for compiling conventional
high-level languages to reconfigurable hardware. However, existing compilers that
compile the algorithms written in these high-level languages still benefit from optimization
to get the reconfigurable hardware to process data in the most efficient way possible.
[0007] The document "
An Automated Process for Compiling Dataflow Graphs into Reconfigurable Hardware",
Robert Rinker et al, illustrates such a compilation technology. One performance limit comes from
the time required when reconfigurable hardware reads data elements from a source array
in memory located outside the hardware. This limit is observed when, for example,
a compute-intensive algorithm consists of loops that operate over a multi-dimensional
source array located outside the reconfigurable hardware, where each iteration of
a loop computes on a rectangular sub-array or stencil of the source array.
[0008] For example, in a conventional windowed loop the elements of the source array are
stored in a memory external to the reconfigurable hardware and are accessed by the
hardware at a rate of one cell value per clock cycle. Thus, when the windowed array
is a 3x3, two-dimensional array, nine clock cycles are needed to read the nine values
of the array into the reconfigurable hardware. If the source array is a two-dimensional
array of size S
i x S
j, and the windowed array is size W
i x W
j, then the number of clock cycles needed to run the loop may be represented as:

where L is the pipeline depth of the loop. Accordingly, significant efficiencies
can be realized by reducing the number of times that a data element from outside the
reconfigurable hardware has to be reread into the hardware. Moreover, efficiencies
can be realized by eliminating intermediate steps in processing the data that involve
writing data to memory outside the reconfigurable processor and later reading the
data back into the hardware.
SUMMARY OF THE INVENTION
[0009] Accordingly, a first embodiment provides a method as detailed in claim 1. Advantageous
embodiments are provided in the dependent claims.
BRIEF DESCRIPTION OF THE DRAWINGS
[0010]
Figure 1 shows an example of a two-dimensional source array that may be used with
the present invention;
Figure 2 shows iterations of a window array across a portion of a source array according
to an example of the present invention;
Figures 3A-F show values from a source array loaded into delay queues and a windowed
array in reconfigurable hardware according to an embodiment of the invention;
Figure 4 shows an example of loop stripmining in a source array according to an example
of the present invention; and
Figure 5 shows an example of data flow in reconfigurable hardware where loop fusion
couples output data between a producer loop and a consumer loop.
DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS
[0011] Fig. 1 shows an example of a two-dimensional source array 100 that may be used with
the present invention. In one embodiment, the size of source array 100 may be represented
as S
i x S
j, where Si represents the number of rows in the two-dimensional array and S
j represents the number of columns. An address for each cell 102 of source array 100
may be represented by S
ij where i represents a row number and j represents a column number. For example, the
upper-leftmost corner cell 102 of source array 100 may be represented by S
00.
[0012] While source array 100, a small two-dimensional array, is described here for the
sake of simplicity, embodiments of the invention also include more complex arrays
having three or more dimensions. In addition, embodiments of the invention also include
two-dimensional source arrays with a greater number of cells 102 and where the number
of columns and rows may or may not be equal (i.e., the width and depth of the source
array may or may not have equal lengths).
[0013] Referring now to Fig. 2, iterations of a window array 202 across a portion of a source
array 204 according to an example of the present invention is shown. A two-dimensional
window array 202 with dimensions W
i x W
j (3x3 in the example shown) may overlap a portion of source array 204. The window
array 202 defines a portion of source array 204 that may be operated upon by the reconfigurable
hardware. For example, window array 202 may select a portion of source array 204 that
is processed by a median filter function that calculates a median value of the elements
in window array 202. In another example, an average value of the elements in window
array 202 may be calculated.
[0014] As shown in Fig. 2, successive iterations of a windowed loop may step window array
202 down the columns of source array 204. In this example, the window array 202 may
move vertically down the rows of the source array 204, stepping one row per iteration.
When the window array 202 reaches the last row of the source array 204 the window
array 202 may move horizontally by one column and back up to the top row of the source
array 204. The loop may repeat this down row/across column pattern for the entire
source array 204.
[0015] An example of a windowed loop nest that makes use of a window array 202 that overlaps
a source array 204 may be represented in computer code by:
Dj = Wj-1; // Wj is the window width
Di = Wi-1; // Wi is the window height
for (j=0; j<Sj-Dj; j++)
for (i=0; i<Si-Di; i++) {
a00 = A[i] [j] ; a01 = A[i] [j+1]; a02 = A[i] [j+2]
a10 = A[i+1] [j]; a11 = A[i+1] [j+1]; a12 = A[i+1] [j+2]
a20 = A[i+2] [j]; a21 = A[i+2] [j+1]; a22 = A[i+2] [j+2]
rval = F (a00, a01, a02,
a10, a11, a12,
a20, a21, a22);
B[i] [j] = rval; }
In the example computer code shown above, F represents a computation using the nine
values from the nine cells of the window array 202 (referred to as "A" in the computer
code) and may be implemented as a function call. The definition of function F may
be specific to the algorithm being implemented. For example, F may represent a function
for image processing including, but not limited to, edge detection, median filter,
erode and dilate. The resultant calculations of F may be stored in a result array,
B (not shown). As shown in this example, the vertical iterations of window array 202
may span the full depth of the source array 204.
[0016] While Fig. 2 and the example computer code shows window array 202, as a 3x3 array,
the size of the window array may vary in both dimensions and may not be square. In
some instances, the size of the window array may be fixed by the algorithm that is
executed on the reconfigurable hardware. For example, the function F above may fix
the size of window array 202 to a 3x3 array. Also, while this example shows all nine
cells of window array 202 being used by the function, F, there is also contemplated
loop stenciling of source array 204 where fewer than all the window array cells are
used by a function.
[0017] Referring now to Fig. 3A, an output value from a source array 304 loaded into a first
delay queue 306 and a 3x3 window array 302 in reconfigurable hardware 310 according
to an embodiment of the invention is shown. In an embodiment, the memory of the reconfigurable
hardware 310 comprises first delay queue 306, a second delay queue 308. The two delay
queues 306 and 308 may be the same length (i.e., hold the same number of data values)
and may comprise First In First Out (FIFO) buffers. In this embodiment, data values
from source array 304 may be read from outside memory of the reconfigurable hardware
310 and stored in the delay queues 306 and 308 in order to reduce the number of times
that each value of source array 304 needs to be reread into the reconfigurable hardware.
[0018] As shown in Fig. 3A, a first value 312 of source array 304 may be read into array
cell 314 of window array 302 and first delay queue 306. In the next iteration that
is illustrated by Fig. 3B, two more values 316 from the first column of source array
304 are read into window array 302 and first delay queue 306. When each of the values
314 are read into array cell 320, the previous value occupying the cell may be pushed
up the column of window array 302.
[0019] As illustrated by Fig. 3C, the first delay queue 306 may fill to capacity when the
last value in the left column 318 of source array 304 is read into the delay queue
306 and the window array 302. In an embodiment, the oldest value 320 may also be read
into array cell 322 of the middle column of window array 302 when a new value is read
into first delay queue 306. In another embodiment, the oldest value 320 of first delay
queue 306 may be transferred to the second delay queue 308 when a new value is read
into first delay queue 306.
[0020] Referring now to Fig. 3D, a second column 324 from source array 304 has been read
into reconfigurable hardware 310. In an embodiment, the oldest value from first delay
queue 306 may be read into window array 302 and second delay queue 308 for each new
value read into first delay queue 306 from source array 304. In this embodiment, when
the values from the second column of source array 304 fills into first delay queue
306, second delay queue 308 may fill with the values from the first column of source
array 304. Also, as the values are transferred from first delay queue 306 to second
delay queue 308, they may also be written to array cell 322. Also, the newest values
read from source array 304 may be input into array cell 314 of window array 302 as
they are input into first delay queue 306.
[0021] Referring now to Fig. 3E three values 326 from the third column of source array 304
are input into reconfigurable hardware 310. As each of these values 326 are input
into first delay queue 306, the oldest values 320 from the first delay queue are input
into second delay queue 308, which in turn may push the oldest values from the second
delay queue 308 into array cell 328 of the left column of window array 302. The net
effect of these transfers after all three values 326 are input into the reconfigurable
hardware 310 may be that the nine values in window array 302 may match the nine values
in the 3x3 sub-array of source array 304.
[0022] As the next value is read from the third column of source array 304, as shown in
Fig. 3F, this value replaces element 314 of the window array 302. In addition, the
oldest value in first delay queue 306 and the oldest value in second delay queue 308
replace elements 322 and 328, respectively, of the window array 302. The values in
window array 302 may now be the same as sub-array 330 of source array 304, which is
similar to incrementing a window array vertically down the rows of source array 304.
[0023] As noted above, delay queues 306 and 308 may eliminate the need to reread values
into the reconfigurable hardware as window array 302 moves vertically down the rows
of source array 304. When window array 302 starts a new cycle at the top row of source
array 304, first delay queue 306 may be empty or loaded with "junk" values. As shown
in Figs. 3A-C, "dummy iterations" may be needed to load first delay queue 306 with
correct values. In one embodiment, the dummy iterations may be accounted for in the
computer code by starting the inner loop induction value (represented by i in the
code above) at -2 instead of 0. In this embodiment, the first two iterations may compute
nonsense values for the function F, and these may be discarded by placing a conditional
on writes to the results array, B.
[0024] In another embodiment, the rereading of source array 304 values into the configuration
hardware may be eliminated as the window array 302 moves horizontally across the columns
of source array 304. As noted above, with each downward pass of the inner loop, one
new column of data may be read from source array 304. The remaining columns, however,
were read in previous iteration of the outer loop, and may be stored in delay queues
306 and 308 in the reconfigurable hardware to eliminate the need to reread them. In
one embodiment, the windowed loop computer code may be modified to look like:
Di = Wi-1;
Dj = Wj-1;
for (k=0; k<Sj-Dj; k+=DEPTH-Di) {
st = k;
if (st + DEPTH > Si)
st = Si - DEPTH;
for (j=-Dj; j<Sj-Dj; j++)
for (i=st-Di; i<st+DEPTH-Di; i++) {
aval = A[i+Dj][j+Dj]
a00 = a01; a01 = a11; a02 = a12
a10 = a20; a11 = a21; a12 = a22
a22 = aval;
a21 = delay (&dly2, a22);
a20 = delay (&dly1, a21);
rval = F (a00, a01, a02,
a10, a11, a12,
a20, a21, a22);
if ((i >= st) && (j >=0)
B [i] [j] = rval; } }
[0025] In this embodiment of the code, the value of A[i+2][j] may be the same value that
was read as A[i+2][j+1] in the previous iteration of the outer loop, and A[i+2][j+1]
may be the same value that was read as A[i+2][j+2]. The previously read values are
stored in delay queues in the reconfigurable hardware.
[0026] The variable DEPTH in the above code represents the height of the portion of the
source array being processed during an iteration of the outer loop. In one embodiment,
the value of DEPTH may span the entire height of the source array, S
j. In another embodiment, loop stripmining may be employed to process the full source
array as two or more sub-arrays or data blocks. In this embodiment, DEPTH may have
a value less than the height of the height of the source array S
j. In still another embodiment, DEPTH may be made a power of two in order to simplify
divide and mod operations to compute the array indices as simple shifts and masks.
[0027] FIG. 4 shows a source array 400 that is processed in sections in the reconfigurable
hardware with loop stripmining. In an embodiment of this method, a first sub-array
402 may have a width equal to the width of the source array and height equal to DEPTH,
where, in this embodiment, DEPTH is equal to the length of a delay queue in the reconfigurable
hardware. In the first iteration of the outer loop, first sub-array 402 defines the
portion of source array 400 that may be processed by successive iterations of the
inner loop where a windowed array moves down the rows and across the columns of first
sub-array 402. During the iterations of the inner loop, each value from the source
array may be read into the reconfigurable hardware and stored in a delay queue by
calling the delay function with a function call. When each new source array value
is written into the delay queue the oldest value in the delay queue may be output
from the tail of the delay queue and as the function call's return. In another embodiment,
the inner loops produce dummy iterations, and the write to the result array, B, may
include conditional statements to ignore the results of these iterations.
[0028] In the second iteration of the outer loop, second sub-array 404 may have the same
width and height as first sub-array 402, but is positioned further down on source
array 400. In the embodiment shown, two rows of the first sub-array 402 overlap with
two rows of second sub-array 404. In another embodiment, one or more rows of a sub-array
may overlap another sub-array. In still another embodiment, no cells of the sub-arrays
overlap each other.
[0029] In the third iteration of the outer loop, the bottom of third sub-array 406 may be
aligned with the bottom of source array 400. In the last iteration of the outer loop,
more rows of the source array may be recalculated than for previous iterations as
a result of the bottom edge of the last sub-array being aligned with the bottom of
the source array.
[0030] In an embodiment, the storage array is a two-dimensional, rectangular array stored
in row-major order, and stored contiguously in memory. Data movement calls to the
source array may be included inside the outer loop to read data from the source array
into the reconfigurable hardware, process it, and write the resultant array to outside
memory. In another embodiment, data movement calls may be configured for the simultaneous
moving one data set while another data set is being processed in the reconfigurable
hardware.
[0031] Referring now to Fig. 5, an embodiment of the invention is shown of data flow in
reconfigurable hardware 510 where loop fusion couples output data between a producer
loop and a consumer loop. In an embodiment, multiple window loops may be connected
in the reconfigurable hardware with producer-consumer loop fusion methods. These methods
include the elimination of intermediate arrays as an output from one nested loop structure,
the producer loop, is directly connected to the input of another nested loop, the
consumer loop. In this embodiment, the elimination of the intermediate loop reduces
the number of reads to reconfigurable hardware 510 thereby reducing processing time.
[0032] An embodiment of the invention includes a method of calculating output values with
a fused producer/consumer loop structure in reconfigurable hardware 510 such as a
FPGA. For example, a calculation may involve applying a first function to nine values
of a source array 504, defined by window array 502, to produce a single output value,
followed by a second function that may be applied to nine output values from the first
function. As noted above, in a conventional loop structure where the first and second
function loops are not fused, the first function loop fills an intermediate array
with the output values and the second function loop processes this intermediate array.
By fusing together the first and second function loops into a producer/consumer loop
structure, the intermediate array may be eliminated.
[0033] The fused producer/consumer loop structure method may start with the formation a
first delay queue 506 and second delay queue 508 in the reconfigurable hardware 510.
In an embodiment, the first and second delay queue 506 and 508 may be the same length
and may be FIFO buffers.
[0034] In another embodiment, a producer function that is part of a producer loop may be
applied to source array 504 values read into the reconfigurable hardware in order
to calculate producer output values. For example, in successive loop iterations the
producer function (which correspond to the row by row steps of window array 502) may
be applied to successive sets of source array values and calculate successive output
values. The output values may be loaded into first delay queue 506 as they are produced
by the producer function. In one embodiment, when first delay queue 506 reaches the
maximum number of output values it can hold, a previously loaded output value may
be transferred from first delay queue 506 to second delay queue 508 for each additional
output value loaded into first delay queue 506 from the producer function.
[0035] For example, a first output value may be loaded into first delay queue 506 followed
by successive output values until first delay queue 506 is filled. Then, as the next
output value is loaded into first delay queue 506, the first output value may be transferred
from first delay queue 506 to the second delay queue 508.
[0036] The consumer function that is part of the consumer loop 512 may be applied to the
output values from the producer function to calculate a consumer output value. In
one embodiment, for each iteration of the consumer loop 512 the consumer function
may be applied to a first output value from second delay queue 508, a second output
value from first delay queue 506, and a third output value coming directly from a
calculation by the producer function on window array 502.
[0037] In another embodiment based on the example above where the consumer function is applied
to an windowed array of 9 output values, each three value row of the array may be
supplied, respectively, by output values from second delay queue 508, the first delay
queue 506 and directly from the producer function operating on window array 502. When
three of these rows stack vertically, a 3x3 array of output values may be formed for
the consumer function.
[0038] In another embodiment, the length of delay queues 506 and 508 may be equal to the
depth of the source array. In another embodiment where loop stripmining may be employed,
the length of a delay queue may be equal to the depth of the sub-array. In these embodiments,
as the producer loop iterates down the column of source array 504 or sub-array of
source array 504, the delay queues 506 and 508 filling with output values may be analogous
to the columns of an intermediate array of output values. For example, when an consumer
function is applied to a three-column, window array of output values from the producer
function, the left column of the window array may be aligned with the first delay
queue, the middle column may be aligned with the second delay queue, and the right
column may be aligned with the sequence of output values produced as the first and
second delay queues are being filled and/or refreshed.
[0039] In another embodiment output values from the producer function may be supplied to
the consumer loop and loaded into first delay queue 506 in the same producer loop
iteration. In another embodiment, an output value transferred from first delay queue
506 to second delay queue 508 may also be supplied to the consumer loop in the same
producer loop iteration. In still another embodiment, an output value may be written
outside reconfigurable hardware 510 from a final delay queue and supplied to the consumer
in the same producer loop iteration.
[0040] An example of how loop fusion may be implemented in computer code may start with
a pair of loops prior to loop fusion such as:
Di = Wi-1;
Dj = Wj-1;
for (k=0; k<Sj-Dj; k+=DEPTH-Di) {
st = k;
if (st + DEPTH > Si)
st = Si - DEPTH;
for (j=-Dj; j<Sj-Dj; j++)
for (i=st-Di; i<st+DEPTH-Di; i++) {
aval = A [i+Dj] [j+Dj]
a00 = a01; a01 = a11; a02 = a12
a10 = a20; a11 = a21; a12 = a22
a22 = aval;
a21 = delay (&dly2, a22);
a20 = delay (&dly1, a21);
rval = F1 (a00, a01, a02,
a10, a11, a12,
a20, a21, a22);
if ((i >= st) && (j >=0)
B[i] [j] = rval; }}
Ei = Vi-1;
Ej = Vj-1;
for (k=0; k<(Sj-Dj)-Ei; k+=DEPTH-Ei) {
st = k;
if (st + DEPTH > (Si-Di))
st = (Si-Di) - DEPTH;
for (j=-Ej; j<(Sj-Dj)-Ei; j++)
for (i=st-Ei; i<st+DEPTH-Ei; i++) {
bval = B[i+Ej] [j+Ej]
b00 = b01; b01 = b11; b02 = b12
b10 = b20; b11 = b21; b12 = b22
b22 = bval;
b21 = delay (&dly2, b22);
b20 = delay (&dly1, b21);
rval = F2 (b00, b01, b02,
b10, b11, b12,
b20, b21, b22);
if ((i >= st) && (j >=0)
C[i] [j] = rival; } }
[0041] In this example, the second loop nest uses values from results array B, whose values
are based on computations of function, F1. Also, the two loops in the code above reuse
some previously read values which may eliminate the need to reread those values from
outside the reconfigurable hardware. In one embodiment, the two nested loops may be
fused together so that the second nested loop may read a stream of values from results
array B in the same order that the first nested loop produced those values.
[0042] In an embodiment where loop fusion is combined with the example of loop stripmining
shown in FIG. 4, there may be overlap between the sub-arrays 402. In this embodiment,
the second loop nest may overlap by two rows due to the two-row overlap at the boundary
of the first sub-array 402 and the second sub-array 404. This overlap may be compensated
for by modifying the first nested loop such that it produces the values in the overlap
rows twice which produces the values in the proper sequence in the second nested loop.
Once this modification is made, the two loops may be fused by feeding the function
values, F1, from the first nested loop into a delay queue that that may be read out
by the second nested loop. An example of the computer code for the fused loops may
be described as:
Di = (Wi-1) + (Vi-1);
Dj = (Wj-1) + (Vj-1);
for (k=0; k<Sj-Dj; k+=DEPTH-Di) {
st = k;
if (st + DEPTH > Si)
st = Si - DEPTH;
for (j=-Dj; j<Sj-Dj; j++)
for (i=st-Di; i<st+DEPTH-Di; i++) {
aval = A[i+Dj] [j+Dj];
a00 = a01; a01=a11; a02 = a12
a10 = a20; a11 = a21; a12 = a22
a22 = aval;
a21 = delay (&dly2, a22);
a20 = delay (&dly1, a21);
bval = F1 (a00, a01, a02,
a10, a11, a12,
a20, a21, a22);
b00 = b01; b01 = b11; b02 = b12
b10 = b20; b11 = b21; b12 = b22
b22 = bval;
b21 = delay (&dly4, b22);
b20 = delay (&dly3, b21);
rval = F2 (b00, b01, b02,
b10, b11, b12,
b20, b21, b22);
if ((i >= st) && (j >=0)
B[i][j] = rval; } }
[0043] In another embodiment, this technique may be extended to fuse any number of loop
nests.
[0044] In still another embodiment, the individual nested loops may be combined into a single
loop. Example code of the pair of nested loops above combined to form a single loop
may look like:
Di = (Wi-1) + (Vi-1);
Dj = (Wj-1) + (Vj-1);
for (k=0; k<Sj-Dj; k+=DEPTH-Di) {
st = k;
if (st + DEPTH > Si)
st = Si - DEPTH;
for (xs=0; xs<Sj*DEPTH; xs++) {
j = xs/DEPTH - Dj;
I = xs%DEPTH + st - Di;
aval = A[i+Dj] [j+Dj];
a00 = a01; a01 = a11; a02 = a12
a10 = a20; a11 = a21; a12 = a22
a22 = aval;
a21 = delay (&dly2, a22);
a20 = delay (&dly1, a21);
bval = F1 (a00, a01, a02,
a10, a11, a12,
a20, a21, a22);
b00 = b01; b01 = b11; b02 = b12
b10 = b20; b11 = b21; b12 = b22
b22 = bval;
b21 = delay (&dly4, b22);
b20 = delay (&dly3, b21);
rval = F2 (b00, b01, b02,
b10, b11, b12,
b20, b21, b22);
if ((i >= st) && (j >=0)
B[i] [j] = rval; } }
[0045] In an embodiment, the loop combing method above may be pipelined in the reconfigurable
hardware to reduce the start-up overhead in the inner loop.
[0046] Although the invention has been described and illustrated with a certain degree of
particularity, it is understood that the present disclosure has been made only by
way of example, and that numerous changes in the combination and arrangement of parts
can be resorted to by those skilled in the art without departing from the scope of
the invention, as hereinafter claimed.
[0047] The words "comprise," "comprising," "include," "including," and "includes" when used
in this specification and in the following claims are intended to specify the presence
of stated features, integers, components, or steps, but they do not preclude the presence
or addition of one or more other features, integers, components, steps, or groups.