pragma HLS inline
Description
Removes a function as a separate entity in the hierarchy. After inlining, the function is dissolved into the calling function and no longer appears as a separate level of hierarchy in the RTL. In some cases, inlining a function allows operations within the function to be shared and optimized more effectively with surrounding operations. An inlined function cannot be shared. This can increase area required for implementing the RTL.
INLINE
pragma applies differently to the scope it is defined in
depending on how it is specified: INLINE
: Without arguments, the pragma means that the function it is specified in should be inlined upward into any calling functions or regions.INLINE OFF
: Specifies that the function it is specified in should NOT be inlined upward into any calling functions or regions. This disables the inline of a specific function that may be automatically inlined, or inlined as part of a region or recursion.INLINE REGION
: This applies the pragma to the region or the body of the function it is assigned in. It applies downward, inlining the contents of the region or function, but not inlining recursively through the hierarchy.INLINE RECURSIVE
: This applies the pragma to the region or the body of the function it is assigned in. It applies downward, recursively inlining the contents of the region or function.
By default, inlining is only performed on the next level of function hierarchy, not
sub-functions. However, the recursive
option lets you specify inlining
through levels of the hierarchy.
Syntax
Place the pragma in the C source within the body of the function or region of code.
#pragma HLS inline <region | recursive | off>
Where:
region
: Optionally specifies that all functions in the specified region (or contained within the body of the function) are to be inlined, applies to the scope of the region.recursive
: By default, only one level of function inlining is performed, and functions within the specified function are not inlined. Therecursive
option inlines all functions recursively within the specified function or region.off
: Disables function inlining to prevent specified functions from being inlined. For example, ifrecursive
is specified in a function, this option can prevent a particular called function from being inlined when all others are.TIP: Vivado HLS automatically inlines small functions and using the INLINE pragma with theoff
option may be used to prevent this automatic inlining.
Example 1
This example inlines all functions within the region it is specified in, in this case the body of
foo_top
, but does not inline any lower level functions within those
functions.
void foo_top { a, b, c, d} {
#pragma HLS inline region
...
Example 2
The following example, inlines all functions within the body of foo_top
,
inlining recursively down through the function hierarchy, except function
foo_sub
is not inlined. The recursive pragma is placed in function
foo_top
. The pragma to disable inlining is placed in the function
foo_sub
:
foo_sub (p, q) {
#pragma HLS inline off
int q1 = q + 10;
foo(p1,q);// foo_3
...
}
void foo_top { a, b, c, d} {
#pragma HLS inline region recursive
...
foo(a,b);//foo_1
foo(a,c);//foo_2
foo_sub(a,d);
...
}
foo_top
, but applies upward to the code calling foo_sub
. Example 3
This example inlines the copy_output
function into any functions or
regions calling copy_output
.
void copy_output(int *out, int out_lcl[OSize * OSize], int output) {
#pragma HLS INLINE
// Calculate each work_item's result update location
int stride = output * OSize * OSize;
// Work_item updates output filter/image in DDR
writeOut: for(int itr = 0; itr < OSize * OSize; itr++) {
#pragma HLS PIPELINE
out[stride + itr] = out_lcl[itr];
}
See Also
- pragma HLS allocation
- pragma HLS function_instantiate
- Vivado Design Suite User Guide: High-Level Synthesis (UG902)