Define which loops are streamed in HDL coder

1 回表示 (過去 30 日間)
Roland
Roland 2016 年 8 月 18 日
コメント済み: Roland 2016 年 9 月 5 日
Hallo,
I am using the HDLcoder in Matlab2016a to implement a neural network on an FPGA. To control the resource consumption it would be perfect to individually control which loops are streamed and which ones are unrolled. Here is a short example:
function [ out ] = Layer( in, fak, neurons )
F = fimath('RoundingMethod','Floor','OverflowAction','Wrap','ProductMode','KeepMSB');
temp = fi(zeros(neurons,1),0,in.WordLength,in.WordLength/2,F);
for jj = 1:neurons
for ii = 1:length(in)
temp(jj) = fi(temp(jj)+in(ii)*fak(ii),0,in.WordLength,in.WordLength/2,F);
end
end
out = temp;
end
Is it possible to stream the inner loop(index ii) and unroll the outer loop(index jj) in order to end up with 3 DSPs working parallel generating the output? Or is it possible to influence the arrangement of the hardware implementation in any way?
Thanks Roland

採用された回答

Chun-Yu
Chun-Yu 2016 年 8 月 24 日
Hi Roland,
Yes, this is possible by using Coder pragmas. By using the coder.hdl.loopspec() pragma, you can control which loop(s) get streamed. You can combine it with the coder.unroll() pragma to get the desired results:
function [ out ] = Layer( in, fak, neurons )
F = fimath('RoundingMethod','Floor','OverflowAction','Wrap','ProductMode','KeepMSB');
temp = fi(zeros(neurons,1),0,in.WordLength,in.WordLength/2,F);
for jj = coder.unroll(1:neurons)
coder.hdl.loopspec('stream');
for ii = 1:length(in)
temp(jj) = fi(temp(jj)+in(ii)*fak(ii),0,in.WordLength,in.WordLength/2,F);
end
end
out = temp;
end
Hope that helps,
Chun-Yu
  1 件のコメント
Roland
Roland 2016 年 9 月 5 日
Thank you very much, this is exactly what I was looking for. It works very well.
I was using the old documentation for HDLcoder2014 and these pragmas are not included there but I found them in the 2016 one.
Thanks,
Roland

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCode Generation についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by