pragma HLS dependence

Description

TheDEPENDENCEpragma 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. TheDEPENDENCEpragma allows you to explicitly specify the dependence and resolve a false dependence.

Important:Specifying a false dependency, when in fact the dependency is not false, can result in incorrect hardware. Be sure dependencies are correct (true or false) before specifying them.

Syntax

Place the pragma within the boundaries of the function where the dependence is defined.

#pragma HLS dependence variable=\distance=

Where:

  • variable=: Optionally specifies the variable to consider for the dependence.
  • : Optionally specifies a class of variables in which the dependence needs clarification. Valid values includearrayorpointer.
    Tip: and variable=do not need to be specified together as you can either specify a variable or a class of variables within a function.
  • : Valid values includeintraorinter. Specifies whether the dependence is:
    • intra: dependence within the same loop iteration. When dependenceis specified asintra, andis false, Vivado HLS may move operations freely within a loop, increasing their mobility and potentially improving performance or area. Whenis specified as true, the operations must be performed in the order specified.
    • inter: dependence between different loop iterations. This is the default. If dependenceis specified asinter, 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 whenis specified as true.
  • : Valid values includeRAW,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

In the following example, Vivado HLS does not have any knowledge about the value of colsand 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 colswill ever be zero, but Vivado HLS cannot make assumptions about data dependencies. To overcome this deficiency, you can use the DEPENDENCEpragma to state that there is no dependence between loop iterations (in this case, for both buff_Aand buff_B).
void foo(int rows, int cols, ...) for (row = 0; row < rows + 1; row++) { for (col = 0; col < cols + 1; col++) { #pragma HLS PIPELINE II=1 #pragma HLS dependence variable=buff_A inter false #pragma HLS dependence variable=buff_B inter false if (col < cols) { buff_A[2][col] = buff_A[1][col]; // read from buff_A[1][col] buff_A[1][col] = buff_A[0][col]; // write to buff_A[1][col] buff_B[1][col] = buff_B[0][col]; temp = buff_A[0][col]; }

Example 2

Removes the dependence betweenVar1in the same iterations ofloop_1in functionfoo.

#pragma HLS dependence variable=Var1 intra false

Example 3

Defines the dependence on all arrays inloop_2of functionfooto inform Vivado HLS that all reads must happen after writes (RAW) in the same loop iteration.

#pragma HLS dependence array intra RAW true

See Also