将常量与编译指示搭配使用 - 2023.2 简体中文

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

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

您可将 const intconstexpr 等常量与编译指示或指令搭配使用。例如:

const int MY_DEPTH=1024; 
#pragma HLS stream variable=my_var depth=MY_DEPTH

在 C 语言代码中也可使用宏来实现此功能。使用宏的关键在于使用宏中的层级。这样即可正确执行扩展。代码将按如下方式进行编译:

#include <hls_stream.h>
using namespace hls;

#define PRAGMA_SUB(x) _Pragma (#x)
#define PRAGMA_HLS(x) PRAGMA_SUB(x)
#define STREAM_IN_DEPTH 8

void foo (stream<int> &InStream, stream<int> &OutStream) {

// Legal pragmas 
PRAGMA_HLS(HLS stream depth=STREAM_IN_DEPTH variable=InStream)
#pragma HLS stream depth=8 variable=OutStream

}