pragma HLS allocation - 2023.1 English

Vitis High-Level Synthesis User Guide (UG1399)

Document ID
UG1399
Release Date
2023-07-17
Version
2023.1 English

Description

Specifies restrictions to limit resource allocation in the implemented kernel. The ALLOCATION pragma or directive can limit the number of RTL instances and hardware resources used to implement specific functions, loops, or operations. The ALLOCATION pragma is specified inside the body of a function, a loop, or a region of code.

For example, if the C source has four instances of a function foo_sub, the ALLOCATION pragma can ensure that there is only one instance of foo_sub in the final RTL. All four instances of the C function are implemented using the same RTL block. This reduces resources used by the function, but negatively impacts performance by sharing those resources.

Template functions can also be specified for ALLOCATION by specifying the function pointer instead of the function name, as shown in the examples below.

The operations in the C code, such as additions, multiplications, array reads, and writes, can also be limited by the ALLOCATION pragma.

Syntax

Place the pragma inside the body of the function, loop, or region where it will apply.
Important: The order of the arguments below is important. The <type> as operation or function must follow the allocation keyword.
#pragma HLS allocation <type> instances=<list> 
limit=<value>

Where:

<type>
The type is specified as one of the following:
function
Specifies that the allocation applies to the functions listed in the instances= list. The function can be any function in the original C or C++ code that has not been:
  • Inlined by the pragma HLS inline, or the set_directive_inline command, or
  • Inlined automatically by the Vitis HLS tool.
operation
Specifies that the allocation applies to the operations listed in the instances= list.
instances=<list>
Specifies the names of functions from the C code, or operators.

For a complete list of operations that can be limited using the ALLOCATION pragma, refer to the config_op command.

limit=<value>
Optionally specifies the limit of instances to be used in the kernel.

Example 1

Given a design with multiple instances of function foo, this example limits the number of instances of foo in the RTL for the hardware kernel to two.

#pragma HLS allocation function instances=foo limit=2

Example 2

Limits the number of multiplier operations used in the implementation of the function my_func to one. This limit does not apply to any multipliers outside of my_func, or multipliers that might reside in sub-functions of my_func.

Tip: To limit the multipliers used in the implementation of any sub-functions, specify an allocation directive on the sub-functions or inline the sub-function into function my_func.
void my_func(data_t angle) {
#pragma HLS allocation operation instances=mul limit=1 
...
}

Example 3

The ALLOCATION pragma can also be used on template functions as shown below. The identification is generally based on the function name, but in the case of template functions it is based on the function pointer:

template <typename DT>
void foo(DT a, DT b){
}
// The following is valid
#pragma HLS ALLOCATION function instances=foo<DT>
...
// The following is not valid
#pragma HLS ALLOCATION function instances=foo