全局变量 - 2023.2 简体中文

Vitis 高层次综合用户指南 (UG1399)

Document ID
UG1399
Release Date
2023-12-18
Version
2023.2 简体中文

全局变量可在代码中自由使用并且完全可综合。但不允许将全局变量推断为顶层函数的实参,必须改为将其显式指定为 RTL 设计中端口的实参。

以下代码示例显示了全局变量的默认综合行为。其中使用了 3 个全局变量:idxAinAout。虽然此示例使用阵列,但 Vitis HLS 支持所有类型的全局变量。

  • Ain 阵列读取值。
  • Aint 阵列用于将值从 Ain 变换并传输到 Aout
  • 输出写入 Aout 阵列。
重要: 在实参列表中,必须显式列出针对全局变量 AinAout 的访问权。
#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()