要在代码中使用 hls::stream<>
对象,请按如下所示方式包含头文件 hls_stream.h。串流数据对象是通过指定类型和变量名称来定义的。在此示例中,已定义 1 个 128 位无符号整数类型,用于创建名为 my_wide_stream
的串流变量。
#include "ap_int.h"
#include "hls_stream.h"
typedef ap_uint<128> uint128_t; // 128-bit user defined type
hls::stream<uint128_t> my_wide_stream; // A stream declaration
串流必须使用限定作用域的命名。赛灵思建议使用限定作用域的 hls::
命名,如上示例所示。但如要使用 hls
名称空间,可将前述示例重写为:
#include <ap_int.h>
#include <hls_stream.h>
using namespace hls;
typedef ap_uint<128> uint128_t; // 128-bit user defined type
stream<uint128_t> my_wide_stream; // hls:: no longer required
给定指定为 hls::stream<T>
的串流的情况下,类型 T 可以是:
- 任何 C++ 原生数据类型
-
Vitis HLS 任意精度类型(例如,
ap_int<>
和ap_ufixed<>
) - 用户定义的结构体(包含以上任意类型)
注释: 用户定义的通用类(或结构),所含方法(成员函数)不应用作为串流变量的类型 (T)。
串流还可指定为 hls::stream<Type, Depth>
用于指示 HLS 工具为 RTL 协同仿真所创建的验证适配器中所需 FIFO 的深度。
串流命名为可选操作。为串流提供名称即可在报告中使用此名称。例如,Vitis HLS 会自动检查以确保仿真期间读取来自输入串流的所有元素。给定以下 2 个串流的情况下:
hls::stream<uint8_t> bytestr_in1;
hls::stream<uint8_t> bytestr_in2("input_stream2");
有关串流元素的任何警告均按如下方式报告,其中显而易见,input_stream2
表示 bytestr_in2
:
WARNING: Hls::stream 'hls::stream<unsigned char>.1' contains leftover data, which
may result in RTL simulation hanging.
WARNING: Hls::stream 'input_stream2' contains leftover data, which may result in RTL
simulation hanging.
传入或传出函数的串流必须按引用传递,如以下示例所示:
void stream_function (
hls::stream<uint8_t> &strm_out,
hls::stream<uint8_t> &strm_in,
uint16_t strm_len
)
在 GitHub 上的 Vitis-HLS-Introductory-Examples 仓库内的 Interface/Streaming 下提供了串流示例。同样在 GitHub 上的 Vitis_Accel_Examples 中提供了使用串流的其它设计示例。
对于 hls::stream
对象,Vitis HLS 还支持阻塞访问方式和非阻塞访问方式,如下章节中所述。