pragma HLS inline - 2024.1 English

Vitis High-Level Synthesis User Guide (UG1399)

Document ID
UG1399
Release Date
2024-07-03
Version
2024.1 English

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.

Important: Inlining a function also dissolves any pragmas or directives applied to that function. In Vitis HLS, any pragmas or directives applied to the inlined function are ignored.

In some cases, inlining a function allows operations within the function to be shared and optimized more effectively with the calling function. However, an inlined function cannot be shared or reused, so if the parent function calls the inlined function multiple times, this can increase the area required for implementing the RTL.

The 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.
INLINE off
Specifies that the function it is specified in should not be inlined upward into any calling functions. This disables the inline of a specific function that can be automatically inlined or inlined as part of recursion.
INLINE recursive
Applies the pragma to the body of the function it is assigned in. It applies downward, recursively inlining the contents of the 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 <recursive | off>

Where:

recursive
By default, only one level of function inlining is performed, and functions within the specified function are not inlined. The recursive option inlines all functions recursively within the specified function or region.
Important: Recursive inlining of functions in a dataflow region can result in a single function in the region which does not meet the conditions of dataflow. In this case the INLINE recursive pragma or directive is ignored.
off
Disables function inlining to prevent specified functions from being inlined. For example, if recursive is specified in a function, this option can prevent a particular called function from being inlined when all others are.
Tip: The Vitis HLS tool automatically inlines small functions, and using the INLINE pragma with the off option can be used to prevent this automatic inlining.

Example 1

The following example inlines all functions within the body of func_top inlining recursively down through the function hierarchy, except function func_sub is not inlined. The recursive pragma is placed in function func_top. The pragma to disable inlining is placed in the function func_sub:

func_sub (p, q) {
#pragma HLS inline off
int q1 = q + 10;
func(p1,q);// foo_3
...
}
void func_top { a, b, c, d} {
  #pragma HLS inline recursive 
  ...
  func(a,b);//func_1
  func(a,c);//func_2
  func_sub(a,d);
  ...
}
Tip: Notice in this example that INLINE RECURSIVE applies downward to the contents of function func_top, but INLINE OFF applies to func_sub directly.

Example 2

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];
    }