系统架构和加速器架构均可使用 VPP_ACC
类上衍生的加速器类来完整指定。在代码示例中,卷积滤波器系统架构、计算组合、CU 数量以及计算连接均可由 conv_acc
类来完整定义。生成的系统架构如下。
图 1. 硬件架构
conv_acc
类用于指定通过将 krnl_conv()
函数封装在 compute()
函数内部来对前者进行加速。由于视频具有 3 条不同的颜色通道,可使用相同功能来分别单独处理,因此加速器类还指定要使用的 3 个 CU。根据 ACCESS_PATTERN
数据宏指定的方式,这些 CU 通过使用数据移动器来进行复制并插入存储器系统。在主机侧,此图显示了 2 个独立线程,分别对应接收线程和发送线程,这 2 条线程使用来自 VSC 的低层次运行时驱动程序与硬件进行交互。
CU 功能必须在独立 .cpp 文件中通过 compute()
函数来定义。在此示例中,只有 1 个处理元素 (PE),因此 compute()
直接将其封装即可。以下代码片段显示了 .cpp 文件的一部分,此处并未提供该文件所含的子函数详细信息。如需获取更完整的示例,请参阅 受支持的平台和启动示例。
// the compute() function wraps the processing function in this example
void conv_acc::compute(
char *coeffs,
float factor,
short bias,
unsigned short width,
unsigned short height,
unsigned char *src,
unsigned char *dst)
{
krnl_conv(coeffs,factor,bias,width,height,src,dst);
}
// ... the processing function implements the CU functionality
void conv_acc::krnl_conv(
char *coeffs,
float factor,
short bias,
unsigned short width,
unsigned short height,
unsigned char *src,
unsigned char *dst) {
#pragma HLS DATAFLOW
hls::stream<window,3> window_stream; // Set a stream depth to 3
// Read incoming pixels and form valid HxV windows
Window2D(width, height, src, window_stream);
// Process incoming stream of pixels, and stream pixels out
Filter2D(width, height, factor, bias, coeffs, window_stream, dst);
}