UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Contributor
Contributor
350 Views
Registered: ‎10-17-2019

Efficient way of coding in vivado hls?

Jump to solution

I am new to vivado hls. I need to initialize my 2-d array with zeros. The below code is causing high latency. I would like to know optimum way to implement below code without causing more latency. Thank you.

The array elements are 32 bit size.

for(int l=0;l<65;l++)
{
#pragma HLS PIPELINE
for(int k=0;k<65;k++)
{
SM[l][k]=0;

}

}

0 Kudos
1 Solution

Accepted Solutions
Highlighted
Scholar u4223374
Scholar
313 Views
Registered: ‎04-26-2015

Re: Efficient way of coding in vivado hls?

Jump to solution

There's no really good way to clear a large array. Block RAM can only handle two writes per cycle, so clearing your 4225 elements will take an absolute minimum of 2113 cycles. If the array is accessible over AXI Lite then that occupies one port, so only a single write can be done per cycle inside the block. Partitioning the array allows you to erase it faster, but at a very large resource cost.

 

By far the best solution is to redesign your code so that there is no separate step for clearing the array. Two common examples:

- If the whole array is read (eg. when writing it out to a stream) - then clear it during the read (read each value and set it to zero in the array). This should cause almost no change in resource usage, almost no change in run-time, and it means that the array is empty for the next time you need to use it.

- If the whole array is written (eg. as the result of a matrix multiply) - then set it up so that the first write to every element is a simple write (rather than a read-add-write). Again, a small change in resource usage and run-time, and now you don't care whether the array was cleared before you started using it.

 

 

If that approach isn't possible, you might be able to move the clearing step to after all outputs have been produced. That way, other functions can start working on the outputs while your block clears its arrays in preparation for the next run.

View solution in original post

1 Reply
Highlighted
Scholar u4223374
Scholar
314 Views
Registered: ‎04-26-2015

Re: Efficient way of coding in vivado hls?

Jump to solution

There's no really good way to clear a large array. Block RAM can only handle two writes per cycle, so clearing your 4225 elements will take an absolute minimum of 2113 cycles. If the array is accessible over AXI Lite then that occupies one port, so only a single write can be done per cycle inside the block. Partitioning the array allows you to erase it faster, but at a very large resource cost.

 

By far the best solution is to redesign your code so that there is no separate step for clearing the array. Two common examples:

- If the whole array is read (eg. when writing it out to a stream) - then clear it during the read (read each value and set it to zero in the array). This should cause almost no change in resource usage, almost no change in run-time, and it means that the array is empty for the next time you need to use it.

- If the whole array is written (eg. as the result of a matrix multiply) - then set it up so that the first write to every element is a simple write (rather than a read-add-write). Again, a small change in resource usage and run-time, and now you don't care whether the array was cleared before you started using it.

 

 

If that approach isn't possible, you might be able to move the clearing step to after all outputs have been produced. That way, other functions can start working on the outputs while your block clears its arrays in preparation for the next run.

View solution in original post