Using #define with Pragma Directives - 2021.2 English

Vitis High-Level Synthesis User Guide (UG1399)

Document ID
UG1399
Release Date
2021-12-15
Version
2021.2 English

Pragma directives support the use of values specified by #define statements.

For example, the following code seeks to specify the depth of a stream using the #define statement:

#include <hls_stream.h>
using namespace hls;

#define STREAM_IN_DEPTH 8

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

// pragma using #DEFINE 
#pragma HLS stream depth=STREAM_IN_DEPTH variable=InStream

// pragma using value 
#pragma HLS stream depth=8 variable=OutStream

}

You can use a constant such as const int, or constexpr. For example:

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

You can also use macros in the C code to implement this functionality. The key to using macros is to use a level of hierarchy in the macro. This allows the expansion to be correctly performed. The code can be made to compile as follows:

#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

}