xcl_dependence

Description

The xcl_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<N;i++) {
     A[i]=x;
     y=A[i];
    }
  • Loop-carry dependence: The same element is accessed in a different loop iteration.
    for (i=0;i<N;i++) {
     A[i]=A[i-1]*2;
    }

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. The xcl_dependence attribute 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

This attribute must be assigned at the declaration of the variable:

__attribute__((xcl_dependence(<class> <type> <direction> distance=<int> <dependent>)))

Where:

  • <class>: Specifies a class of variables in which the dependence needs clarification. Valid values include array or pointer.
    TIP: <class> is mutually exclusive with variable= as you can either specify a variable or a class of variables.
  • <type>: Valid values include intra or inter. Specifies whether the dependence is:
    • intra: dependence within the same loop iteration. When dependence <type> is specified as intra, and <dependent> is false, Vivado HLS may move operations freely within a loop, increasing their mobility and potentially improving performance or area. When <dependent> is specified as true, the operations must be performed in the order specified.
    • inter: dependence between different loop iterations. This is the default <type>. If dependence <type> is specified as inter, and <dependent> is 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 <dependent> is specified as true.
  • <direction>: Valid values include RAW, WAR, or WAW. 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=<int>: Specifies the inter-iteration distance for array access. Relevant only for loop-carry dependencies where dependence is set to true.
  • <dependent>: Specifies whether a dependence needs to be enforced (true) or removed (false). The default is true.

Example 1

In the following example, Vivado HLS does not have any knowledge about the value of 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 between Var1 in the same iterations of loop_1 in function foo.

__attribute__((xcl_dependence(intra false)));

Example 3

Defines the dependence on all arrays in loop_2 of function foo 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