Global Variables - 2024.1 English

Vitis High-Level Synthesis User Guide (UG1399)

Document ID
UG1399
Release Date
2024-05-30
Version
2024.1 English

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 (idx, Ain and Aout). Although this example uses arrays, Vitis HLS supports all types of global variables.

  • Values are read from array Ain.
  • Array Aint is used to transform and pass values from Ain to Aout.
  • 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()