Xilinx recommends writing the code inside a dataflow region using canonical forms. There are canonical forms for dataflow optimizations for both functions and loops.
- Functions: The canonical form coding guideline for dataflow inside a function specifies:
- Use only the following types of variables inside the dataflow region:
- Local non-static scalar/array/pointer variables.
- Local static
hls::stream
variables.
- Function calls transfer data only in the forward direction.
- Array or
hls::stream
should have only one producer function and one consumer function. - The function arguments (variables coming from outside the dataflow region) should only be read, or written, not both. If performing both read and write on the same function argument then read should happen before write.
- The local variables (those that are transferring data in forward direction) should be written before being read.
The following code example illustrates the canonical form for dataflow within a function. Note that the first function (
func1
) reads the inputs and the last function (func3
) writes the outputs. Also note that one function creates output values that are passed to the next function as input parameters.void dataflow(Input0, Input1, Output0, Output1) { UserDataType C0, C1, C2; #pragma HLS DATAFLOW func1(read Input0, read Input1, write C0, write C1); func2(read C0, read C1, write C2); func3(read C2, write Output0, write Output1); }
- Use only the following types of variables inside the dataflow region:
- Loop: The canonical form coding guideline for dataflow inside a loop body includes the coding guidelines for a function defined above, and also specifies the following:
- Initial value 0.
- The loop condition is formed by a comparison of the loop variable with a numerical constant or variable that does not vary inside the loop body.
- Increment by 1.
The following code example illustrates the canonical form for dataflow within a loop.
void dataflow(Input0, Input1, Output0, Output1) { UserDataType C0, C1, C2; for (int i = 0; i < N; ++i) { #pragma HLS DATAFLOW func1(read Input0, read Input1, write C0, write C1); func2(read C0, read C0, read C1, write C2); func3(read C2, write Output0, write Output1); } }