主要内容

自定义比特流配置,满足资源使用需求

用户希望在Xilinx™ZCU102 ZU4CG设备上部署一个目标性能为每秒500帧(FPS)的数字识别网络。目标设备资源计数为:

  • 数字信号处理器(DSP)片数240

  • 块随机存取存储器(BRAM)计数-128

参考资料(运输)zcu102_int8位流配置用于Xilinx ZCU102 ZU9EG设备。缺省情况下,单板资源计数如下:

  • 数字信号处理器(DSP)片数- 2520

  • 块随机存取存储器(BRAM)计数-912

缺省的单板资源计数超过了用户资源预算,处于成本范围的较高一端。通过量化目标深度学习网络并自定义自定义默认比特流配置,可以实现目标性能和资源使用预算。

在本例中,创建一个自定义比特流配置来匹配您的资源预算和性能要求。

先决条件

  • 深度学习HDL工具箱™支持包Xilinx FPGA和S万博1manbetxoC

  • 深度学习工具箱™

  • 深度学习HDL工具箱™

  • 深度学习工具箱模型量化库

负荷预训练网络

要加载预先训练的系列网络,该网络已在修改的国家技术标准研究所(MNIST)数据库上进行了训练,请输入:

snet = getDigitsNetwork;

数字转换网络

要量化基于MNIST的数字网络,输入:

dlquantObj = dlquantizer(snet,“ExecutionEnvironment”FPGA的);Image = imageDatastore(“five_28x28.pgm”“标签”“五”);dlquantObj.calibrate(图片);

检索zcu102_int比特流配置

检索zcu102_int8位流配置,使用dlhdl。ProcessorConfig对象。有关更多信息,请参见dlhdl。ProcessorConfig.要了解处理器配置的可修改参数,请参见getModuleProperty而且setModuleProperty

hPC_reference = dlhdl。ProcessorConfig (“比特流”“zcu102_int8”
hPC_reference =处理模块”conv“ModuleGeneration:‘“LRNBlockGeneration:‘off’SegmentationBlockGeneration:”“ConvThreadNumber: 64 InputMemorySize: [227 227 3] OutputMemorySize: [227 227 3] FeatureSizeLimit: 2048处理模块“俱乐部”ModuleGeneration:”“SoftmaxBlockGeneration:‘off’SigmoidBlockGeneration:‘off’FCThreadNumber: 16 InputMemorySize: 25088 OutputMemorySize: 4096处理模块“定制”ModuleGeneration:”“加法:”“乘法:”“Resize2D:'off' Sigmoid: 'off' TanhLayer: 'off' InputMemorySize: 40 OutputMemorySize: 120处理器顶级属性RunTimeControl: 'register' RunTimeStatus: 'register' InputStreamControl: 'register' OutputStreamControl: 'register' SetupControl: 'register' ProcessorDataType: 'int8'系统级属性TargetPlatform: 'Xilinx Zynq UltraScale+ MPSoC ZCU102 Evaluation Kit' TargetFrequency: 250 SynthesisTool: 'Xilinx Vivado' ReferenceDesign: ' axis - stream DDR内存访问:3-AXIM' SynthesisToolChipFamily: 'Zynq UltraScale+' SynthesisToolDeviceName: 'xczu9eg-ffvb1156-2-e' SynthesisToolPackageName: " SynthesisToolSpeedValue: "

估计网络性能和资源利用率zcu102_int8比特流的配置

要估计数字序列网络的性能,请使用estimatePerformance的功能dlhdl。ProcessorConfig对象。该函数返回估计的层延迟、网络延迟和网络性能,单位是帧/秒(frames /s)。

以估计资源的使用情况zcu102_int8比特流使用estimateResources的功能dlhdl。ProcessorConfig对象。该函数返回估计的DSP片和BRAM使用情况。

hPC_reference.estimatePerformance (dlquantObj)
优化网络:将“nnet.cnn.layer.BatchNormalizationLayer”融合为“nnet.cnn.layer.Convolution2DLayer”1“imageinput”图像输入28××28日1图像“zerocenter”正常化(SW层)2的conv_1卷积8 3×3×1的隆起与步幅[1]和填充“相同”(HW层)3的relu_1 ReLU ReLU (HW层)4“maxpool_1”马克斯池2×2马克斯池步(2 - 2)和填充[0 0 0 0](HW层)5‘conv_2卷积16 3×3×8旋转步[1]和填充“相同”(HW层)6的relu_2 ReLU ReLU (HW层)7“maxpool_2”马克斯池2×2马克斯池步(2 - 2)和填充[0 0 0 0] (HW层)8 'conv_3' Convolution 32 3×3×16 convolutions with stride[1 1]和padding 'same' (HW层)9 'relu_3' ReLU ReLU (HW层)10 'fc'全连接10全连接层(HW层)11 'softmax' softmax softmax (SW层)12 'classoutput' Classification Output crossentropyex with '0'和9个其他类(SW层)###注意:层'imageinput'与类型'nnet.cnn.layer.ImageInputLayer'是在软件中实现的。注意:类型为'nnet.cnn.layer.SoftmaxLayer'的层'softmax'是在软件中实现的。注意:层'classoutput'类型为'nnet.cnn.layer.ClassificationOutputLayer'是在软件中实现的。Deep Learning Processor Estimator Performance Results LastFrameLatency(cycles) LastFrameLatency(seconds) FramesNum Total Latency Frames/s ------------- ------------- --------- --------- --------- Network 58101 0.00023 1 58101 4302.9 ____conv_1 4391 0.00002 ____maxpool_1 2877 0.00001 ____conv_2 2351 0.00001 ____maxpool_2 2265 0.00001 ____conv_3 2651 0.00001 ____fc 43566 0.00017 * DL处理器的时钟频率为:250MHz
hPC_reference.estimateResources
深度学习处理器估计资源结果dsp块RAM* LUTs(CLB/ALUT) ------------- ------------- -------------可用2520 912 274080 ------------- ------------- ------------- DL_Processor 797(32%) 386(43%) 142494(52%) *块RAM代表Xilinx设备中的块RAM瓦和英特尔设备中的块RAM位

估计的性能为4303 FPS,估计的资源使用计数为:

  • 数字信号处理器(DSP)片数797

  • 块随机存取存储器(BRAM)计数-386

估计的DSP片计数和BRAM计数使用超过了目标设备资源预算。自定义比特流配置,减少资源使用。

创建自定义比特流配置

属性可以创建自定义处理器配置dlhdl。ProcessorConfig对象。有关更多信息,请参见dlhdl。ProcessorConfig.要了解处理器配置的可修改参数,请参见getModuleProperty而且setModuleProperty

若要减少自定义位流的资源使用,请修改KernelDataTypeConv, fc,和加法器模块。修改ConvThreadNumber减少DSP片数.减少InputMemorySize而且OutputMemorySizeconv模块减少BRAM计数。

hPC_custom = dlhdl.ProcessorConfig;hPC_custom。ProcessorDataType =“int8”;hPC_custom.setModuleProperty (“conv”“ConvThreadNumber”4);hPC_custom.setModuleProperty (“conv”“InputMemorySize”,[30 30 1]);hPC_custom.setModuleProperty (“conv”“OutputMemorySize”,[30 30 1]);hPC_custom
hPC_custom =处理模块”conv“ModuleGeneration:‘“LRNBlockGeneration:‘off’SegmentationBlockGeneration:”“ConvThreadNumber: 4 InputMemorySize: [30 30 1] OutputMemorySize: [30 30 1] FeatureSizeLimit: 2048处理模块“俱乐部”ModuleGeneration:”“SoftmaxBlockGeneration:‘off’SigmoidBlockGeneration:‘off’FCThreadNumber: 4 InputMemorySize: 25088 OutputMemorySize: 4096处理模块“定制”ModuleGeneration:”“加法:”“乘法:”“Resize2D:‘off’s形的:'off' TanhLayer: 'off' InputMemorySize: 40 OutputMemorySize: 120处理器顶级属性RunTimeControl: 'register' RunTimeStatus: 'register' InputStreamControl: 'register' OutputStreamControl: 'register' SetupControl: 'register' ProcessorDataType: 'int8'系统级属性TargetPlatform: 'Xilinx Zynq UltraScale+ MPSoC ZCU102 Evaluation Kit' TargetFrequency: 200 SynthesisTool: 'Xilinx Vivado' ReferenceDesign: ' axis - stream DDR Memory Access: 3-AXIM' SynthesisToolChipFamily: ''Zynq UltraScale+' SynthesisToolDeviceName: 'xczu9eg-ffvb1156-2-e' SynthesisToolPackageName: " SynthesisToolSpeedValue: "

估计自定义比特流配置的网络性能和资源利用率

要估计数字序列网络的性能,请使用estimatePerformance的功能dlhdl。ProcessorConfig对象。该函数返回估计的层延迟、网络延迟和网络性能,单位是帧/秒(frames /s)。

以估计资源的使用情况hPC_custom比特流使用estimateResources的功能dlhdl。ProcessorConfig对象。该函数返回估计的DSP片和BRAM使用情况。

hPC_custom.estimatePerformance (dlquantObj)
优化网络:将“nnet.cnn.layer.BatchNormalizationLayer”融合为“nnet.cnn.layer.Convolution2DLayer”1“imageinput”图像输入28××28日1图像“zerocenter”正常化(SW层)2的conv_1卷积8 3×3×1的隆起与步幅[1]和填充“相同”(HW层)3的relu_1 ReLU ReLU (HW层)4“maxpool_1”马克斯池2×2马克斯池步(2 - 2)和填充[0 0 0 0](HW层)5‘conv_2卷积16 3×3×8旋转步[1]和填充“相同”(HW层)6的relu_2 ReLU ReLU (HW层)7“maxpool_2”马克斯池2×2马克斯池步(2 - 2)和填充[0 0 0 0] (HW层)8 'conv_3' Convolution 32 3×3×16 convolutions with stride[1 1]和padding 'same' (HW层)9 'relu_3' ReLU ReLU (HW层)10 'fc'全连接10全连接层(HW层)11 'softmax' softmax softmax (SW层)12 'classoutput' Classification Output crossentropyex with '0'和9个其他类(SW层)###注意:层'imageinput'与类型'nnet.cnn.layer.ImageInputLayer'是在软件中实现的。注意:类型为'nnet.cnn.layer.SoftmaxLayer'的层'softmax'是在软件中实现的。注意:层'classoutput'类型为'nnet.cnn.layer.ClassificationOutputLayer'是在软件中实现的。Deep Learning Processor Estimator Performance Results LastFrameLatency(cycles) LastFrameLatency(seconds) FramesNum Total Latency Frames/s ------------- ------------- --------- --------- --------- Network 433577 0.00217 1 433577 461.3 ____conv_1 26160 0.00013 ____maxpool_1 31888 0.00016 ____conv_2 44736 0.00022 ____maxpool_2 22337 0.00011 ____conv_3 265045 0.00133 ____fc 43411 0.00022 * DL处理器的时钟频率为:200MHz
hPC_custom.estimateResources
深度学习处理器估计资源结果dsp块RAM* LUTs(CLB/ALUT) ------------- ------------- -------------可用2520 912 274080 ------------- ------------- ------------- DL_Processor 131(6%) 108(12%) 56270(21%) *块RAM代表Xilinx设备中的块RAM瓦和英特尔设备中的块RAM位

估计的性能为461.3 FPS,估计的资源使用计数如下:

  • 数字信号处理器(DSP)片数- 131

  • 块随机存取存储器(BRAM)计数-108

自定义比特流的资源估算值与用户目标设备资源预算相匹配,性能估算值与目标网络性能相匹配。