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.

The INLINEpragma 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, therecursiveoption 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 

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. Therecursiveoption inlines all functions recursively within the specified function or region.
  • off: Disables function inlining to prevent specified functions from being inlined. For example, ifrecursiveis 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 directive with the offoption 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 offoo_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 offoo_top, inlining recursively down through the function hierarchy, except functionfoo_subis not inlined. The recursive pragma is placed in functionfoo_top. The pragma to disable inlining is placed in the functionfoo_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); ... }
Note:Notice in this example, that INLINE applies downward to the contents of function foo_top, but applies upward to the code calling foo_sub.

Example 3

This example inlines thecopy_outputfunction into any functions or regions callingcopy_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