Generate HLS Code for MATLAB Handle Classes and System Objects
This example shows how to generate HLS code for a user-defined System object™ and then view the generated code in the code generation report.
A System object is a subclass of the matlab.System
handle class. To generate code for a general handle class,
follow similar steps as in this example.
In a writable folder, create a System object,
AddOne
, which subclasses frommatlab.System
. Save the code asAddOne.m
.classdef AddOne < matlab.System % ADDONE Compute an output value that increments the input by one methods (Access=protected) % stepImpl method is called by the step method function y = stepImpl(~,x) y = x+1; end end end
Write a function
testAddOne
that uses this System object.function y = testAddOne(x) %#codegen p = AddOne(); y = p.step(x); end
Generate HLS Code for
use_shape
and generate a code generation report.cfg = coder.config("hdl"); cfg.Workflow = "High Level Synthesis"; codegen -config cfg testAddOne -args {0} -report
The
-report
option instructscodegen
to generate a code generation report, even if no errors or warnings occur. The-args
option specifies that thetestAddOne
function takes one scalar double input.Click the View report link.
In the MATLAB Source pane, click
testAddOne
. To see information about the variables intestAddOne
, click the Variables tab.To view the class definition for
addOne
, in the MATLAB Source pane, clickAddOne
.