%% Evaluate Performance of Deep Learning Network on Custom Processor Configuration
% Benchmark the performance of a deep learning network on a custom bitstream configuration by comparing it to the performance on a reference (shipping) bitstream configuration. Use the comparison results to adjust your custom deep learning processor parameters to achieve optimum performance.
% In this example compare the performance of the ResNet-18 network on the zcu102_single bitstream configuration to the performance on the default custom bitstream configuration.
%% Prerequisites
% Deep Learning HDL Toolbox™ Support Package for Xilinx FPGA and SoC
% Deep Learning Toolbox™
% Deep Learning HDL Toolbox™
% Deep Learning Toolbox Model for ResNet-18 Network
%
%% Load Pretrained Network
% Load the pretrained network.

snet = resnet18;

%
%% Retrieve zcu102_single Bitstream Configuration
% To retrieve the zcu102_single bitstream configuration, use the dlhdl.ProcessorConfig object. For more information, see dlhdl.ProcessorConfig. To learn about modifiable parameters of the processor configuration, see getModuleProperty and setModuleProperty.

hPC_shipping = dlhdl.ProcessorConfig('Bitstream',"zcu102_single")

%
%% Estimate ResNet-18 Performance for zcu102_single Bitstream Configuration
% To estimate the performance of the ResNet-18 DAG network, use the estimatePerformance function of the dlhdl.ProcessorConfig object. The function returns the estimated layer latency, network latency, and network performance in frames per second (Frames/s).

hPC_shipping.estimatePerformance(snet)

%
%% Create Custom Processor Configuration
% To create a custom processor configuration, use the dlhdl.ProcessorConfig object. For more information, see dlhdl.ProcessorConfig. To learn about modifiable parameters of the processor configuration, see getModuleProperty and setModuleProperty.

hPC_custom = dlhdl.ProcessorConfig

%
%% Estimate ResNet-18 Performance for Custom Bitstream Configuration
% To estimate the performance of the ResNet-18 DAG network, use the estimatePerformance function of the dlhdl.ProcessorConfig object. The function returns the estimated layer latency, network latency, and network performance in frames per second (Frames/s).

hPC_custom.estimatePerformance(snet)

% The performance of the ResNet-18 network on the custom bitstream configuration is lower than the performance on the zcu102_single bitstream configuration. The difference between the custom bitstream configuration and the zcu102_single bitstream configuration is the target frequency.
%
%% Modify Custom Processor Configuration
% Modify the custom processor configuration to increase the target frequency. To learn about modifiable parameters of the processor configuration, see dlhdl.ProcessorConfig.

hPC_custom.TargetFrequency = 220;
hPC_custom

%
%% Re-estimate ResNet-18 Performance for Modified Custom Bitstream Configuration
% Estimate the performance of the ResNet-18 DAG network on the modified custom bitstream configuration.

hPC_custom.estimatePerformance(snet)

%
% Copyright 2020 The MathWorks, Inc.
%