False dependencies are dependencies that arise when the compiler is too conservative. These dependencies do not exist in the real code, but cannot be determined by the compiler. These dependencies can prevent loop pipelining.
The following example illustrates false dependencies. In this example, the
read and write accesses are to two different addresses in the same loop iteration. Both of
these addresses are dependent on the input data, and can point to any individual element of
the hist
array. Because of this, Vitis HLS assumes that both of these accesses can access the same location. As a
result, it schedules the read and write operations to the array in alternating cycles,
resulting in a loop II of 2. However, the code shows that hist[old]
and hist[val]
can never access the same
location because they are in the else branch of the conditional if(old
== val)
.
void histogram(int in[INPUT SIZE], int hist[VALUE SIZE]) f
int acc = 0;
int i, val;
int old = in[0];
for(i = 0; i < INPUT SIZE; i++)
{
#pragma HLS PIPELINE II=1
val = in[i];
if(old == val)
{
acc = acc + 1;
}
else
{
hist[old] = acc;
acc = hist[val] + 1;
}
old = val;
}
hist[old] = acc;
To overcome this deficiency, you can use the DEPENDENCE directive to provide Vitis HLS with additional information about the dependencies.
void histogram(int in[INPUT SIZE], int hist[VALUE SIZE]) {
int acc = 0;
int i, val;
int old = in[0];
#pragma HLS DEPENDENCE variable=hist type=intra direction=RAW dependent=false
for(i = 0; i < INPUT SIZE; i++)
{
#pragma HLS PIPELINE II=1
val = in[i];
if(old == val)
{
acc = acc + 1;
}
else
{
hist[old] = acc;
acc = hist[val] + 1;
}
old = val;
}
hist[old] = acc;
When specifying dependencies there are two main types:
- Inter
- Specifies the dependency is between different iterations of the same
loop.
If this is specified as FALSE it allows Vitis HLS to perform operations in parallel if the pipelined or loop is unrolled or partially unrolled and prevents such concurrent operation when specified as TRUE.
- Intra
- Specifies dependence within the same iteration of a loop, for example an
array being accessed at the start and end of the same iteration.
When intra dependencies are specified as FALSE, Vitis HLS may move operations freely within the loop, increasing their mobility and potentially improving performance or area. When the dependency is specified as TRUE, the operations must be performed in the order specified.