xcl_dependence
Description
Thexcl_dependence
attribute is used to provide additional information that can overcome loop-carry dependencies and allow loops to be pipelined (or pipelined with lower intervals).
Vivado HLS automatically detects dependencies:
- Within loops (loop-independent dependence), or
- Between different iterations of a loop (loop-carry dependence).
These dependencies impact when operations can be scheduled, especially during function and loop pipelining.
- Loop-independent dependence: The same element is accessed in the same loop iteration.
for (i=0;i
- Loop-carry dependence: The same element is accessed in a different loop iteration.
for (i=0;i
Under certain complex scenarios automatic dependence analysis can be too conservative and fail to filter out false dependencies. Under certain circumstances, such as variable dependent array indexing, or when an external requirement needs to be enforced (for example, two inputs are never the same index), the dependence analysis might be too conservative. Thexcl_dependence
attribute allows you to explicitly specify the dependence and resolve a false dependence.
Syntax
This attribute must be assigned at the declaration of the variable:
__attribute__((xcl_dependence( distance= )))
Where:
: Specifies a class of variables in which the dependence needs clarification. Valid values includearrayorpointer. Tip:is mutually exclusive with variable=
as you can either specify a variable or a class of variables.: Valid values include intra
orinter
. Specifies whether the dependence is:intra
: dependence within the same loop iteration. When dependenceis specified as intra
, andis false, Vivado HLS may move operations freely within a loop, increasing their mobility and potentially improving performance or area. When is specified as true, the operations must be performed in the order specified. inter
: dependence between different loop iterations. This is the default. If dependence is specified as inter
, andis false, it allows Vivado HLS to perform operations in parallel if the function or loop is pipelined, or the loop is unrolled, or partially unrolled, and prevents such concurrent operation when is specified as true.
: Valid values include RAW
,WAR
, orWAW
. This is relevant for loop-carry dependencies only, and specifies the direction for a dependence:- RAW(Read-After-Write - true dependence) The write instruction uses a value used by the read instruction.
- WAR(Write-After-Read - anti dependence) The read instruction gets a value that is overwritten by the write instruction.
- WAW(Write-After-Write - output dependence) Two write instructions write to the same location, in a certain order.
distance=
: Specifies the inter-iteration distance for array access. Relevant only for loop-carry dependencies where dependence is set totrue.: Specifies whether a dependence needs to be enforced (true) or removed (false). The default istrue.
Example 1
cols
and conservatively assumes that there is always a dependence between the write to
buff_A[1][col]
and the read from
buff_A[1][col]
. In an algorithm such as this, it is unlikely
cols
will ever be zero, but Vivado HLS cannot make assumptions about data dependencies. To overcome this deficiency, you can use the
xcl_dependence
attribute to state that there is no dependence between loop iterations (in this case, for both
buff_A
and
buff_B
).
void foo(int rows, int cols, ...) for (row = 0; row < rows + 1; row++) { for (col = 0; col < cols + 1; col++) __attribute__((xcl_pipeline_loop(II=1))) { if (col < cols) { buff_A[2][col] = buff_A[1][col] __attribute__((xcl_dependence(inter false))); // read from buff_A buff_A[1][col] = buff_A[0][col]; // write to buff_A buff_B[1][col] = buff_B[0][col] __attribute__((xcl_dependence(inter false))); temp = buff_A[0][col]; }
Example 2
Removes the dependence betweenVar1
in the same iterations ofloop_1
in functionfoo
.
__attribute__((xcl_dependence(intra false)));
Example 3
Defines the dependence on all arrays inloop_2
of functionfoo
to inform Vivado HLS that all reads must happen after writes (RAW) in the same loop iteration.
__attribute__((xcl_dependence(array intra RAW true)));
See Also
- pragma HLS dependence
- SDAccel Environment Optimization Guide(UG1207)
- Vivado Design Suite User Guide: High-Level Synthesis(UG902)