Function inlining removes the function hierarchy by disolving the function logic into the calling function. A function is inlined using the INLINE directive. Inlining a function can improve the area by allowing the components within the function to be better shared or optimized with the logic in the calling function. This type of function inlining is also performed automatically by Vitis HLS for small functions.
Inlining allows function sharing to be better controlled. For
functions to be shared they must be used within the same
level of hierarchy. In this code example, function
foo_top
calls
foo
twice and function
foo_sub
.
foo_sub (p, q) {
int q1 = q + 10;
foo(p1,q); // foo_3
...
}
void foo_top { a, b, c, d} {
...
foo(a,b); //foo_1
foo(a,c); //foo_2
foo_sub(a,d);
...
}
Inlining function foo_sub
and using the ALLOCATION
directive to specify that only one instance of the
function foo
is used, results in a design
that only has one instance of function
foo
: one-third the area of the
example above. Using this strategy allows for more
fine-grained control of what user-defined resources can be
shared and is a useful feature to when area utilization is
a consideration.
foo_sub (p, q) {
#pragma HLS INLINE
int q1 = q + 10;
foo(p1,q); // foo_3
...
}
void foo_top { a, b, c, d} {
#pragma HLS ALLOCATION instances=foo limit=1 function
...
foo(a,b); //foo_1
foo(a,c); //foo_2
foo_sub(a,d);
...
}
The INLINE directive optionally allows all functions below the
specified function to be recursively inlined by using the
recursive
option. If the
recursive
option is used on the
top-level function, all function hierarchy in the design
is removed.
The INLINE off
option can optionally be applied to
functions to prevent them from being inlined. This option
may be used to prevent Vitis HLS from automatically inlining a
function.
The INLINE directive is a powerful way to substantially modify the structure of the code without actually performing any modifications to the source code and provides a very powerful method for architectural exploration.