fpga-凯发k8网页登录

main content

fpga-in-the-loop

fpga-in-the-loop (fil) enables you to run a simulink® or matlab® simulation that is synchronized with an hdl design running on an fpga board. this link between the simulator and the board enables you to verify hdl implementations directly against simulink or matlab algorithms. you can apply real-world data and test scenarios from these algorithms to the hdl design that is running on the fpga.

in simulink, you can use the and blocks to accelerate communication between simulink and the fpga board. in matlab, you can modify the generated code to speed up communication with the fpga board.

fpga-in-the-loop simulation with vision hdl toolbox blocks

this example shows how to modify the generated fpga-in-the-loop (fil) model for more efficient simulation of the vision hdl toolbox™ streaming video protocol.

autogenerated fil model

when you generate a programming file for a fil target in simulink, the hdl workflow advisor creates a model to compare the fil simulation with your simulink design. for details of how to generate fil artifacts for a simulink model, see (hdl verifier).

for vision hdl toolbox designs, the fil block in the generated model replicates the pixel-streaming interface and sends one pixel at a time to the fpga. the model shown was generated from the example model in .

the top part of the model replicates your simulink design. the generated fil block at the bottom communicates with the fpga. tofilsrc subsystem copies the pixel-stream input of the hdl algorithm block to the fromfilsrc subsystem. the tofilsink subsystem copies the pixel-stream output of the hdl algorithm block into the compare subsystem, where it is compared with the output of the hdl algorithm_fil block. for image and video processing, this setup is slow because the model sends only a single pixel, and its associated control signals, in each packet to and from the fpga board.

modified fil model for pixel streaming

to improve the communication bandwidth with the fpga board, you can use the generated fil block with vector input rather than streaming. this example includes a model, , created by modifying the generated fil model. the modified model uses the fil frame to pixels and fil pixels to frame blocks to send one frame at a time to the generated fil block. you cannot run this model as is. you must generate your own fil block and bitstream file that use your board and connection settings.

to convert from the generated model to the modified model:

  1. remove the tofilsrc, fromfilsrc, tofilsink, and compare subsystems, and create a branch at the frame input of the frame to pixels block.

  2. insert the fil frame to pixels block before the hdl algorithm_fil block. insert the fil pixels to frame block after the hdl algorithm_fil block.

  3. branch the frame output of the pixels to frame block for comparison. you can compare the entire frame at once with a diff block. compare the validout signals using an xor block.

  4. in the fil frame to pixels and fil pixels to frame blocks, set the video format parameter to match the video format of the frame to pixels and pixels to frame blocks.

  5. set the vector size in the fil frame to pixels and fil pixels to frame blocks to frame or line. the size of the fil frame to pixels vector output must match the size of the fil pixels to frame vector input. the vector size of the fil block interfaces does not modify the generated hdl code. it affects only the packet size of the communication between the simulator and the fpga board.

the modified model sends an entire frame to the fpga board in each packet, significantly improving the efficiency of the communication link.

fpga-in-the-loop simulation with multipixel streaming

when using fpga-in-the-loop with a multipixel streaming design, you must flatten the pixel ports to vectors for input and output of the fil block. use selector blocks to separate the input pixel streams into numpixels vectors, and use a vector concatenate block to recombine the output vectors.

if each pixel is represented by more than one component, the fil frame to pixels block has one data port per component and the fil block has numpixels×numcomponents ports. split each component matrix into numpixels vectors.

this model shows a multipixel, single component design.

multipixel, single component fil model

for vhdl code generation, in configuration parameters > hdl code generation > global settings > ports, set the scalarize ports parameter to dut level.

configuration parameters, open to the hdl code generation > global settings pane and showing the drop down menu options for the scalarize ports parameter

fpga-in-the-loop simulation with vision hdl toolbox system objects

this example shows how to modify the generated fpga-in-the-loop (fil) script for more efficient simulation of the vision hdl toolbox™ streaming video protocol. for details of how to generate fil artifacts for a matlab® system object™, see (hdl verifier).

autogenerated fil function

when you generate a programming file for a fil target in matlab, the hdl workflow advisor creates a test bench to compare the fil simulation with your matlab design. for vision hdl toolbox designs, the dutname_fil function in the test bench replicates the pixel-streaming interface and sends one pixel at a time to the fpga. dutname is the name of the function that you generated hdl code from.

this code snippet is from the generated test bench tbname_fil.m, generated from the example script in . the code calls the generated dutname_fil function once for each pixel in a frame.

for p = 1:numpixperfrm
    [pixoutvec( p ),ctrloutvec( p )] = pixelstreamingdesignhdldesign_fil( pixinvec( p ), ctrlinvec( p ) );
end

the generated dutname_fil function calls your hdl-targeted function. it also calls the dutname_sysobj_fil function, which contains a system object that connects to the fpga. dutname_fil compares the output of the two functions to verify that the fpga implementation matches the original matlab results. this snippet is from the file dutname_fil.m.

% call the original matlab function to get reference signal
[ref_pixout,tmp_ctrlout] = pixelstreamingdesignhdldesign(pixin,ctrlin);
  ...
% run fpga-in-the-loop
[pixout,ctrlout_hstart,ctrlout_hend,ctrlout_vstart,ctrlout_vend,ctrlout_valid] ...
  = pixelstreamingdesignhdldesign_sysobj_fil(pixin,ctrlin_hstart,ctrlin_hend,ctrlin_vstart,ctrlin_vend,ctrlin_valid);
  ...
% verify the fpga-in-the-loop output
hdlverifier.assert(pixout,ref_pixout,'pixout');

for image and video processing, this setup is slow because the function sends only one pixel, and its associated control signals, in each packet to and from the fpga board.

modified fil test bench for pixel streaming

to improve the communication bandwidth with the fpga board, you can modify the autogenerated test bench, tbname_fil.m. the modified test bench calls the fil system object directly, with one frame at a time. these snippets are from the pixelstreamingdesignhdltestbench_fil_frame.m script, modified from fil artifacts generated from the example script in . you cannot run this script as is. you must generate your own fil system object, function, and bitstream file that use your board and connection settings. then, either modify your version of the generated test bench, or modify this script to use your generated fil object.

declare an instance of the generated fil system object.

fil = class_pixelstreamingdesignhdldesign_sysobj;

comment out the loop over the pixels in the frame.

%         for p = 1:numpixperfrm
%            [pixoutvec( p ),ctrloutvec( p )] = pixelstreamingdesignhdldesign_fil( pixinvec( p ), ctrlinvec( p ) );
%         end

replace the commented loop with the code below. call the step method of the fil object with vectors containing the whole frame of data pixels and control signals. pass each control signal to the object separately, as a vector of logical values. then, recombine the control signal vectors into a vector of structures.

[pixoutvec,hstartout,hendout,vstartout,vendout,validout] = ...
    fil(pixinvec,[ctrlinvec.hstart]',[ctrlinvec.hend]',[ctrlinvec.vstart]',[ctrlinvec.vend]',[ctrlinvec.valid]');
ctrloutvec = arrayfun(@(hstart,hend,vstart,vend,valid) ...
    struct('hstart',hstart,'hend',hend,'vstart',vstart,'vend',vend,'valid',valid),...
    hstartout,hendout,vstartout,vendout,validout);     

these code changes remove the pixel-by-pixel verification of the fil results against the matlab results. optionally, you can add a pixel loop to call the reference function, and a frame-by-frame comparison of the results. however, calling the original function for a reference slows down the simulation.

for p = 1:numpixperfrm
     [ref_pixoutvec(p),ref_ctrloutvec(p)] = pixelstreamingdesignhdldesign(pixinvec(p),ctrlinvec(p));
end

after the call to the fil object, compare the output vectors.

hdlverifier.assert(pixoutvec',ref_pixoutvec,'pixout')
hdlverifier.assert([ctrloutvec.hstart],[ref_ctrloutvec.hstart],'hstart')
hdlverifier.assert([ctrloutvec.hend],[ref_ctrloutvec.hend],'hend')
hdlverifier.assert([ctrloutvec.vstart],[ref_ctrloutvec.vstart],'vstart')
hdlverifier.assert([ctrloutvec.vend],[ref_ctrloutvec.vend],'venc')
hdlverifier.assert([ctrloutvec.valid],[ref_ctrloutvec.valid],'valid')

this modified test bench sends an entire frame to the fpga board in each packet, significantly improving the efficiency of the communication link.

see also

blocks

  • | |

objects

related topics

  • (hdl verifier)
网站地图