Get Started with Deep Learning FPGA Deployment on Xilinx ZC706 SoC
This example shows how to create, compile, and deploy a handwritten character detection series network to an FPGA and use MATLAB® to retrieve the prediction results.
Prerequisites
Xilinx® Zynq® ZC706 Evaluation Kit
Deep Learning HDL Toolbox™ Support Package for Xilinx® FPGA and SoC
Deep Learning Toolbox™
Deep Learning HDL Toolbox™
Load Pretrained Network
Load the pretrained series network trained on the Modified National Institute of Standards and Technology (MNIST) database[1].
snet = getDigitsNetwork;
View the layers of the pretrained series network by using the Deep network Designer app.
deepNetworkDesigner(snet)
Define FPGA Board Interface
Define the target FPGA board programming interface by using the dlhdl.Target
object. Create a programming interface with custom name for your target device and a JTAG interface to connect the target device to the host computer. To use JTAG, install Xilinx™ Vivado™ Design Suite 2022.1. Set the toolpath by using the hdlsetuptoolpath
function.
hdlsetuptoolpath('ToolName', 'Xilinx Vivado', 'ToolPath', 'C:\Xilinx\Vivado\2022.1\bin\vivado.bat');
hTarget = dlhdl.Target('Xilinx');
Prepare Network for Deployment
Prepare the network for deployment by creating a dlhdl.Workflow
object. Specify the network and bitstream name. Ensure that the bitstream name matches the data type and the FPGA board that you are targeting. In this example, the target FPGA board is the Xilinx® Zynq® ZC706 Evaluation Kit and the bitstream uses the single data type.
hW = dlhdl.Workflow(Network=snet,Bitstream='zc706_single',Target=hTarget);
Compile Network
Run the compile
method of the dlhdl.Workflow
object to compile the network and generate the instructions, weights, and biases for deployment.
dn = compile(hW)
### Optimizing series network: Fused 'nnet.cnn.layer.BatchNormalizationLayer' into 'nnet.cnn.layer.Convolution2DLayer' offset_name offset_address allocated_space _______________________ ______________ ________________ "InputDataOffset" "0x00000000" "4.0 MB" "OutputResultOffset" "0x00400000" "4.0 MB" "SystemBufferOffset" "0x00800000" "28.0 MB" "InstructionDataOffset" "0x02400000" "4.0 MB" "ConvWeightDataOffset" "0x02800000" "4.0 MB" "FCWeightDataOffset" "0x02c00000" "4.0 MB" "EndOffset" "0x03000000" "Total: 48.0 MB"
dn = struct with fields:
Operators: [1×1 struct]
LayerConfigs: [1×1 struct]
NetConfigs: [1×1 struct]
Program Bitstream onto FPGA and Download Network Weights
To deploy the network on the Xilinx® Zynq® UltraScale+ MPSoC ZCU102 hardware, run the deploy
method of the dlhdl.Workflow
object. This method programs the FPGA board using the output of the compile method and the programming file, downloads the network weights and biases, displays progress messages, and the time it takes to deploy the network.
deploy(hW)
### Programming FPGA Bitstream using JTAG... ### Programming the FPGA bitstream has been completed successfully. ### Loading weights to FC Processor. ### FC Weights loaded. Current time is 12-Jun-2020 14:54:22
Test Network
Load the example image.
inputImg = imread('five_28x28.pgm');
Classify the image on the FPGA by using the predict
method of the dlhdl.Workflow
object and display the results.
[prediction,speed] = hW.predict(single(inputImg),'Profile','on');
### Finished writing input activations. ### Running single input activations. Deep Learning Processor Profiler Performance Results LastLayerLatency(cycles) LastLayerLatency(seconds) FramesNum Total Latency Frames/s ------------- ------------- --------- --------- --------- Network 80141 0.00160 1 80182 623.6 conv_module 47601 0.00095 conv_1 10047 0.00020 maxpool_1 6999 0.00014 conv_2 11367 0.00023 maxpool_2 5465 0.00011 conv_3 13783 0.00028 fc_module 32540 0.00065 fc 32540 0.00065 * The clock frequency of the DL processor is: 50MHz
[val,idx] = max(prediction);
fprintf('The prediction result is %d\n', idx-1);
The prediction result is 5
Bibliography
LeCun, Y., C. Cortes, and C. J. C. Burges. "The MNIST Database of Handwritten Digits." http://yann.lecun.com/exdb/mnist/.