Intel® High Level Synthesis Compiler Standard Edition: Best Practices Guide
ID
683259
Date
12/18/2019
Public
1. Intel® HLS Compiler Standard Edition Best Practices Guide
2. Best Practices for Coding and Compiling Your Component
3. Interface Best Practices
4. Loop Best Practices
5. Memory Architecture Best Practices
6. Datatype Best Practices
7. Advanced Troubleshooting
A. Intel® HLS Compiler Standard Edition Best Practices Guide Archives
B. Document Revision History for Intel® HLS Compiler Standard Edition Best Practices Guide
4.7. Declare Variables in the Deepest Scope Possible
To reduce the FPGA hardware resources necessary for implementing a variable, declare the variable just before you use it in a loop. Declaring variables in the deepest scope possible minimizes data dependencies and FPGA hardware usage because the Intel® HLS Compiler Standard Edition does not need to preserve the variable data across loops that do not use the variables.
Consider the following example:
int a[N];
for (int i = 0; i < m; ++i)
{
int b[N];
for (int j = 0; j < n; ++j)
{
// statements
}
}
The array a requires more resources to implement than the array b. To reduce hardware usage, declare array a outside the inner loop unless it is necessary to maintain the data through iterations of the outer loop.
Tip: Overwriting all values of a variable in the deepest scope possible also reduces the resources necessary to represent the variable.