主要内容

定制深度学习处理器生成,以满足性能要求

这个例子展示了如何创建自定义处理器配置和预训练系列网络的性能评估。然后,您可以修改自定义处理器配置的参数并重新估计性能。一旦达到了性能要求,就可以使用自定义处理器配置生成自定义位流。

先决条件

  • 用于Xilinx FPGA和SoC的深度学习HDL工金宝app具箱™支持包

  • 深度学习工具箱™

  • 深度学习HDL工具箱™

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

  • 深度学习库的MATLAB编码器接口

负载预训练系列网络

要加载预先训练的系列网络LogoNet,输入:

snet = getLogoNetwork;

创建自定义处理器配置

要创建自定义处理器配置,请使用dlhdl。ProcessorConfig对象。有关更多信息,请参见dlhdl。ProcessorConfig.要了解处理器配置的可修改参数,请参见getModulePropertysetModuleProperty

hPC = dlhdl.ProcessorConfig;高性能计算。TargetFrequency = 220;hPC
hPC =处理模块”conv“ModuleGeneration:‘“LRNBlockGeneration:”“ConvThreadNumber: 16 InputMemorySize: [227 227 3] OutputMemorySize: [227 227 3] FeatureSizeLimit: 2048处理模块“俱乐部”ModuleGeneration:”“SoftmaxBlockGeneration:‘off’FCThreadNumber: 4 InputMemorySize: 25088 OutputMemorySize:4096 Processing Module "adder" ModuleGeneration: 'on' InputMemorySize: 40 OutputMemorySize: 40 Processor Top Level Properties RunTimeControl: 'register' InputDataInterface: 'External Memory' OutputDataInterface: 'External Memory' ProcessorDataType: 'single' System Level Properties'Xilinx Zynq UltraScale+ MPSoC ZCU102 Evaluation Kit' TargetFrequency: 220 SynthesisTool: 'Xilinx Vivado' ReferenceDesign: ' axio - stream DDR Memory Access: 3-AXIM' synthesistolchipfamily: 'Zynq UltraScale+' synthesistoldevicename: 'xczu9e -ffvb1156-2-e' synthesistolpackagename: " synthesistolspeedvalue: "

估计LogoNet性能

估计性能的LogoNet系列网络,使用estimatePerformance的函数dlhdl。ProcessorConfig对象。该函数以帧/秒(frames /s)为单位返回估计的层延迟、网络延迟和网络性能。

hPC.estimatePerformance (snet)
###注意:类型为' net.cnn.layer. imageinputlayer '的图层'imageinput'是在软件中实现的。###注意:类型为' net.cnn.layer. classificationoutputlayer '的classoutput层是在软件中实现的。Deep Learning Processor Estimator Performance Results LastFrameLatency(cycles) LastFrameLatency(seconds) FramesNum Total Latency Frames/s ------------- ------------- --------- --------- --------- Network 39926006 0.18148 1 39926006 5.5 ____conv_1 6825671 0.03103 ____maxpool_1 3755088 0.01707 ____conv_2 10440701 0.04746 ____maxpool_2 1447840 0.00658____conv_3 9405685 0.04275 ____maxpool_3 1765856 0.00803 ____conv_4 1819636 0.00827 ____maxpool_4 28098 0.00013 ____fc_1 2651288 0.01205 ____fc_2 1696632 0.00771 ____fc_3 89511 0.00041 * The clock frequency of the DL processor is: 220MHz

估计每秒帧数为5.5帧/秒。为了提高网络性能,修改自定义处理器卷积模块内核数据类型、卷积处理器线程数、全连接模块内核数据类型、全连接模块线程数。有关这些处理器参数的更多信息,请参见getModulePropertysetModuleProperty

创建修改的自定义处理器配置

要创建自定义处理器配置,请使用dlhdl。ProcessorConfig对象。有关更多信息,请参见dlhdl。ProcessorConfig.要了解处理器配置的可修改参数,请参见getModulePropertysetModuleProperty

hPCNew = dlhdl.ProcessorConfig;hPCNew。TargetFrequency = 300;hPCNew。ProcessorDataType =“int8”;hPCNew.setModuleProperty (“conv”“ConvThreadNumber”, 64);hPCNew.setModuleProperty (“俱乐部”“FCThreadNumber”16);hPCNew
hPCNew =处理模块”conv“ModuleGeneration:‘“LRNBlockGeneration:”“ConvThreadNumber: 64 InputMemorySize: [227 227 3] OutputMemorySize: [227 227 3] FeatureSizeLimit: 2048处理模块“俱乐部”ModuleGeneration:”“SoftmaxBlockGeneration:‘off’FCThreadNumber: 16 InputMemorySize: 25088 OutputMemorySize:4096 Processing Module "adder" ModuleGeneration: 'on' InputMemorySize: 40 OutputMemorySize: 40 Processor Top Level Properties RunTimeControl: 'register' InputDataInterface: 'External Memory' OutputDataInterface: 'External Memory' ProcessorDataType: 'int8' System Level Properties'Xilinx Zynq UltraScale+ MPSoC ZCU102 Evaluation Kit' TargetFrequency: 300 SynthesisTool: 'Xilinx Vivado' ReferenceDesign: ' axio - stream DDR Memory Access: 3-AXIM' synthesistolchipfamily: 'Zynq UltraScale+' synthesistoldevicename: 'xczu9e -ffvb1156-2-e' synthesistolpackagename: " synthesistolspeedvalue: "

量化LogoNet系列网络

要量化LogoNet网络,输入:

dlquantObj = dlquantizer (snet,“ExecutionEnvironment”FPGA的);形象= imageDatastore (“heineken.png”“标签”“喜力”);dlquantObj.calibrate(图片);

估计LogoNet性能

估计LogoNet系列网络的性能,使用estimatePerformance的函数dlhdl。ProcessorConfig对象。该函数以帧/秒(frames /s)为单位返回估计的层延迟、网络延迟和网络性能。

hPCNew.estimatePerformance (dlquantObj)
###注意:类型为' net.cnn.layer. imageinputlayer '的图层'imageinput'是在软件中实现的。###注意:类型为' net.cnn.layer. classificationoutputlayer '的classoutput层是在软件中实现的。深度学习处理器估计器性能结果LastFrameLatency(cycles) LastFrameLatency(seconds) FramesNum Total Latency Frames/s ------------- ------------- --------- --------- --------- Network 14306694 0.04769 1 14306694 21.0 ____conv_1 3477191 0.01159 ____maxpool_1 1876680 0.00626 ____conv_2 2932291 0.00977 ____maxpool_2 723536 0.00241____conv_3 2611391 0.00870 ____maxpool_3 882544 0.00294 ____conv_4 641788 0.00214 ____maxpool_4 14025 0.00005 ____fc_1 665265 0.00222 ____fc_2 425425 0.00142 ____fc_3 56558 0.00019 * DL处理器的时钟频率为:300MHz

估计每秒帧数为21.2帧/秒。

生成自定义处理器和比特流

使用新的自定义处理器配置来构建和生成自定义处理器和位流。使用自定义位流将LogoNet网络部署到目标FPGA板。

% hdlsetuptoolpath('ToolName', 'Xilinx Vivado', 'ToolPath', 'C: Xilinx Vivado\2019.2\bin\ Vivado .bat');% dlhdl.buildProcessor (hPCNew);

要了解如何使用生成的位流文件,请参见生成定制的比特流

本例中生成的位流类似于zcu102_int8比特流。要部署量化的LogoNet网络,使用zcu102_int8比特流,看获得量化LogoNet网络的预测结果