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: 
Highlighted
Visitor alondight
Visitor
7,223 Views
Registered: ‎12-28-2012

HLS: how to use memcpy to transfer integers via a 256-bit bus without data loss

I am encountering the following issue. I have a 256-bit AXI4 bus in the platform. I have computed an integer array in the Vivado_hls-synthesized pcore. I want to use memcpy to transfer the array to DRAM via the AXI4 bus at the maximum possible throughput, i.e., 8 integers per clock cycle. Here is how I try to implement it:
void pcore( volatile uint256* bus, volatile int* addr_fifo )
{
#pragma AP interface ap_bus port=bus
#pragma AP resource core = AXI4M variable=bus
#pragma AP interface ap_fifo port=ctrl_fifo
int a[1000];
compute_on( a );
uint256 b[125];
int addr = *ctrl_fifo;
int buf_offset = addr % ( sizeof(uint256) / sizeof(int) );
reorder_data_layout_from_to( a, b, buf_offset );
int length = ( 1000 - buf_offset ) * sizeof(int);
memcpy( bus + (addr / sizeof(int), b + ( buf_offset / sizeof(int) ), length )
}
I did allignment on both the two addresses in memcpy so that there is no shifting. However when "addr" is something like 0xC0000010 which is not alligned on the uint256 boundary, the offset "10" will still get lost. If I don't want to lose anything at the starting address since there are some useful data stored in range 0xC00000000 ~ 0xC0000010 and I want my data to be placed right after that range, what should I do? Thank you very much!

0 Kudos
2 Replies
Participant aitmhof
Participant
6,554 Views
Registered: ‎04-25-2014

Re: HLS: how to use memcpy to transfer integers via a 256-bit bus without data loss

Hi alondight,

 

I know that you might have solved the issue already, but I stumbled upon it right now.

The problem is that your bus is 256-bit

 

so any offset that you add to your bus (bus + offset) gives you the same address/pointer like &(bus[offset]). Adding an integer to a pointer does not add the integer to the adress value it moves the pointer forward to the element representing that value starting at the address defined by the pointer. (Standard C)

The address in your case would be: (unsigned int)bus + (256/8)*offset.

If you have unaligned 256 bit transfers you have to take care of that yourself or use a DMA and FIFO-based approach which can do the realignment for you.

 

Are you on the Zynq? The bus to the DDR is limited to 32/64 bit. (HP). So you can as well take that Bus-Width.

 

Regards,

 

Markus

0 Kudos
Xilinx Employee
Xilinx Employee
6,534 Views
Registered: ‎08-17-2011

Re: HLS: how to use memcpy to transfer integers via a 256-bit bus without data loss

your new reply prompted me to make those comments:
1- (similar to yours) 256bit align means addresses are multiple of 256/8 == 32 bytes == 0x20 , so 0xC0000010 isn't valid.
2- users need to be very careful because sizeof(uint256) isn't necessarily 256!
- assuming that uint256 is ap_uint<256> since ap_(u)int is a class then "sizeof" will return the data storage size of the class (if that makes sense) and this may not be 256.. the last time I checked it was different; i don't know for the last releases.

hoping this helps..
- Hervé

SIGNATURE:
* New Dedicated Vivado HLS forums* http://forums.xilinx.com/t5/High-Level-Synthesis-HLS/bd-p/hls
* Readme/Guidance* http://forums.xilinx.com/t5/New-Users-Forum/README-first-Help-for-new-users/td-p/219369

* Please mark the Answer as "Accept as solution" if information provided is helpful.
* Give Kudos to a post which you think is helpful and reply oriented.
0 Kudos