Global variables can be freely used in the code and are fully synthesizable. However, global variables can not be inferred as arguments to the top-level function, but must instead be explicitly specified as arguments for ports in the RTL design.
The following code example shows the default synthesis behavior of global variables. It uses three global variables. Although this example uses arrays, Vitis HLS supports all types of global variables.
- Values are read from array
Ain. - Array
Aintis used to transform and pass values fromAintoAout. - The outputs are written to array
Aout.
Important: Access to the global variables
Ain and Aout must be explicitly listed in the
argument list. #include "top.h"
void top(const int idx, const int Ain[N], int Aout[Nhalf]) {
int Aint[N];
// Move elements in the input array
ILOOP: for (int i = 0; i < N; i++) {
int iadj = (i + idx) % N;
Aint[i] = Ain[i] + Ain[iadj];
} // end ILOOP
// sum the 1st and 2nd halves
OLOOP: for (int i = 0; i < Nhalf; i++) {
Aout[i] = (Aint[i] + Aint[Nhalf + i]);
} // end OLOOP
} // end top()