Main Content

Verify Generated HLS Code Using MATLAB Desktop Host

You can verify your generated HLS code by using the MATLAB® Desktop Host as the simulation tool. The verification ensures the generated HLS code for the DUT produces same results as the original MATLAB entry point for the same stimulus in the MATLAB test bench. Using MATLAB desktop host based MEX simulation eliminates the dependency on third-party EDA simulation tools for the verification of the generated HLS code. The following Discrete Cosine Transform (DCT) example shows how to generate HLS code and verify it using MATLAB Host.

Simulate the Generated HLS Code using MATLAB Desktop Host

The DCT example uses mldhlc_dct as the MATLAB® Design and mlhdlc_dct_tb as the MATLAB Test Bench to generate and simulate the code.

  • Install the SystemC 2.3.3 library. When installing SystemC on the Windows® platform, use the Release option to build. You can download the SystemC library from accellera.org.

  • Setup the SystemC library path by using hdlsetuphlstoolpath. For example:

hdlsetuphlstoolpath('ToolName','SystemC','SystemCIncludePath', ...
         'C:\Users\systemc-2.3.3\systemc-2.3.3\src','SystemCLibraryPath', ...
                 'C:\Users\systemc-2.3.3\systemc-2.3.3\msvc10\SystemC\x64\Release');

hdlsetuphlstoolpath_output.png

Note: To use MATLAB Host as the simulation tool, the synthesis tool should not be selected.

Command Line Interface

  • Create an hdl configuration object and set the code generation workflow and the test bench name.

cfg = coder.config('hdl');
cfg.Workflow = "High Level Synthesis";
cfg.TestBenchName = "mlhdlc_dct_tb";
cfg.GenerateHDLTestBench = true;
cfg.TreatIOThresholdAs = "None";
  • Enable the option to simulate generated code and specify the simulation tool.

cfg.SimulateGeneratedCode = true;
cfg.SimulationTool = "MATLAB Host";
  • Generate HLS code.

codegen("mlhdlc_dct",'-config',cfg,'-report');

hls_code_generation_log.png

HDL Workflow Advisor

  • Open the HDL Workflow Advisor using this command. A dct_project.prj file is created in the current folder.

coder -hdlcoder -new dct_project
  • Select mlhdlc_dct.m as the MATLAB function and mlhdlc_dct_tb.m as the MATLAB Test Bench.

  • To start the HDL Workflow Advisor, click the Workflow Advisor button.

  • In HDL Workflow Advisor step, specify Code Generation workflow as MATLAB to HLS.

  • In the Verification step, select Generate test bench and Simulate generated test bench. Specify Simulation tool as MATLAB Host.

  • Run all the steps in the HDL Workflow Advisor to generate and simulate HLS code.

verify_with_hls_test_bench.png

MATLAB Host Simulation Report

In the Verify with HLS Test Bench step, you can view the simulation results in mw_MATLAB_Host_simulation_report.log.

HLS simulation report using MATLAB Desktop Host