在 PL 内核中,通过 hls::stream
采用 ap_axiu<D,0,0,0>
作为数据类型,来定义两个内核串流接口之间直接执行的数据发送或接收操作。ap_axiu<D,0,0,0>
数据类型需要使用 ap_axi_sdata.h 报头文件。
以下示例显示了生产者和使用者内核的串流接口。
// Producer kernel - provides output as a data stream
// For simplicity the example only shows the streaming output.
void kernel1 (.... , hls::stream<ap_axiu<32, 0, 0, 0> >& stream_out) {
for(int i = 0; i < ...; i++) {
int a = ...... ; // Internally generated data
ap_axiu<32, 0, 0, 0> v; // temporary storage for ap_axiu
v.data = a; // Writing the data
stream_out.write(v); // Writing to the output stream.
}
}
// Consumer kernel - reads data stream as input
// For simplicity the example only shows the streaming input.
void kernel2 (hls::stream<ap_axiu<32, 0, 0, 0> >& stream_in, .... ) {
for(int i = 0; i < ....; i++) {
ap_axiu<32, 0, 0, 0> v = stream_in.read(); // Reading the input stream
int a = v.data; // Extract the data
// Do further processing
}
}
鉴于已定义 hls::stream
数据类型,Vitis HLS 工具可推断 axis
接口。以下 INTERFACE 编译指示作为示例显示,但在代码中并非必需。
#pragma HLS INTERFACE axis port=stream_out
#pragma HLS INTERFACE axis port=stream_in
提示: 这些示例内核显示了内核特征符内的串流输入/输出端口的定义,以及内核代码中输入/输出串流的处理方式。在链接进程期间,必须定义从
kernel1
到 kernel2
的串流接口连接,如 指定串流连接 中所述。