Matlab HDL coder error: reptmat is not supported, but in the documentation it is.

2 views (last 30 days)
Hello!
I've been working on a project where I used Matlab and Simulink to generate HDL. Specifically, I have to port an existing Matlab image processing framework using the HDL Coder to an FPGA. So far I just simply did workarounds for functions that I needed but weren't supported by the HDL Coder. I tried to use the repmat function, which is according to this documentation, is supported for HDL code generation. Yet when I want to begin the generation process, it throws an error that it's not supported. Same goes for the fimath function. Does anyone know why does this happen? Again, according to the documentation I am using stuff that should be okay.
Here is the code in my custom Matlab function block that I implemented in Simulink:
function img = fcn(in)
%#codegen
F = fimath('OverflowAction','Saturate','RoundingMethod','Floor',...
'CastBeforeSum',false,'ProductMode','SpecifyPrecision', ProductWordLength=24, ProductFractionLength=16) ;
fixedIn = fi(uint8(in));
z1 = fi((-2 + 3^0.5),1,24,16);
z1 = setfimath(z1,F);
z1row = fi(zeros(1,600),1,24,16);
z1row = setfimath(z1row,F);
for i = 1:600
z1row(i) = z1^(i-1);
end
z1row = repmat(z1row,400,1);
img = sum(fixedIn.*z1row,2);
end
I am using version 2022b of Matlab and Vivado 2022.2.

Answers (2)

Steven Lord
Steven Lord on 2 Mar 2023
There are different implementations of repmat for numeric arrays (the documentation to which you linked) and for fi arrays. Note that both are listed in the output of which but the first one is what will be called for that particular call to repmat.
z1 = fi((-2 + 3^0.5),1,24,16);
which -all repmat(z1, 2, 2)
/MATLAB/toolbox/fixedpoint/fixedpoint/+embedded/@fi/repmat.m % embedded.fi method /MATLAB/toolbox/matlab/elmat/repmat.m
I'm not sure if the implementation of repmat for fi arrays supports HDL code generation.

Ryan Baird
Ryan Baird on 2 Mar 2023
Specifying parameters with the syntax ProductWordLength=24 is not yet supported by HDL Coder. The call to fimath can be changed to:
F = fimath('OverflowAction','Saturate','RoundingMethod','Floor','CastBeforeSum',false,'ProductMode','SpecifyPrecision', 'ProductWordLength', 24, 'ProductFractionLength', 16) ;
Based on the error message you received, it sounds like the architecture is set to Matlab Datapath. Unless you're using features that are only supported by the Matlab Datapath architecture, you might also find for this model that setting the architecture to 'Matlab Function' in the Matlab Function block's HDL Block Properties compiles faster and has better error messages when a line of code is unsupported.
  2 Comments
János Csanád
János Csanád on 6 Mar 2023
Hi Ryan,
Thank you for the answer. I realized that maybe I can make some workarounds so the above mentioned functions are not necessary, but I ran into some different problems.
My architecture is set to Matlab Datapath as I'm trying to implement streaming for my inputs and outputs. If I set the architecture back to Matlab Function, I get an error that my DUT needs to have streamed output ports. However, if I set my architecture back to Matlab Datapath, I get insanely slow model checking and code generation times. In fact, even after an hour my code didn't generate. As this subsystem is only a small part of the image processing algorimth I have to implement, this is not really acceptable. My guess is that because I'm taking the whole image as an input instead of relying on streaming and neighbourhood processing functions it takes a lot of time, however, neighbourhood processing isn't really working for this block as I need separate lines with no padding.
I have to say that I'm quite new to this Matlab HDL Coder ecosystem, so I'm not sure if I'm doing the correct things. I would like to rely on Matlab Function Blocks as these seem to be the best fit to implement existing algorithms easily. I was also thinking on using the Frame-to-Pixels and Pixels-to-Frame blocks but these doesn't seem to fit exactly well with the hdl.npufun functions. I have attached my simulink model, the problems I'm describing are tied to the "B-Spline Filter HDL" subsystem.
Any help is greatly appreciated!
Ryan Baird
Ryan Baird on 6 Mar 2023
It does sound like the Matlab Datapath is required for what you're doing. I agree that you don't want to use both hdl.npufun and the Frame-to-Pixel / Pixel-to-Frame blocks for the same algorithm; hdl.npufun is intended for when you're relying on hdl coder to convert a neighborhood algorithm to a streaming algorithm, and the Frame-to-Pixel and Pixel-to-Frame blocks are intended for if you're modeling a streaming algorithm directly and writing code or a model that operates on one pixel at a time.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!