Float data transfer to HW thread

26 views
Skip to first unread message

Umair Riaz

unread,
Feb 8, 2017, 2:39:44 AM2/8/17
to ReconOS
Hello!

I am trying to implement simple mathematical functions on float values through HLS IP. HLS function is simple addition and subtraction. The main application send float data address via mbox. It has a similar structure as sort demo, But i receive strange data probably because the representation is changed along the way due to casting(Same function works with uint).
The underlying data transfer functions in HW reconOS implementation are:
   
     stream_read(hls::stream<uint32> &stream)
     stream_write(hls::stream<uint32> &stream, uint32 data)

Should these function be changed to handle float data transfer? Or what other way is possible to have correct transfer.

Best regards
Umair


Guanwen (Henry) Zhong

unread,
Feb 16, 2017, 5:01:04 AM2/16/17
to ReconOS
Hello Umair,

To support floating calculation, you don't need to modify stream_read() and stream_write(). Instead, you need to modify MEM_READ() and MEM_WRITE() in reconos_calls.h. The key point to support float type is to transferring float data to reconos api, but let reconos "think" this is uint32 data. After you obtain the data via stream_read() or before you write back data via stream_write(), you need to change the type of the pointer WITHOUT changing your data in the memory pointed by this pointer.

For example, in MEM_READ, original code section is
------
...
for (; __len > 0; __len -= 4) {\
  (dst)[__i++] = stream_read(memif_mem2hwt);\
  __addr += 4;\
  __rem -= 4;\
}\
...
------

You need to change it to:
----
uint32 __data;\
...\
for (; __len > 0; __len -= 4) {\
__data = stream_read(memif_mem2hwt);\
(dst)[__i++] = *((float*) (&__data));\ (The content of __data is not modified, we ONLY need to change the type of pointer that points to this location)
  __addr += 4;\
  __rem -= 4;\
}
...
----

You can do the similar thing in MEM_WRITE.

To support this in rdk, you need to modify /lib/calls/reconos_calls_hls.h.

If you want to support transferring both uint32 and float data in the same hw ip core, you need to add one more argument indicating the type of data in MEM_WRITE and MEM_READ. To make rdk support this, you need to modify /lib/calls/reconos_calls_hls.h; build.cfg in your hw project, /tools/_pypack/reconos/runtime/project.py and /tools/_pypack/reconos/scripts/hw/export.py.

Thanks,
Guanwen

Umair Riaz

unread,
Feb 17, 2017, 7:44:36 AM2/17/17
to ReconOS
Hi Henry,

Thank you for your post. I have already tried with pointer reinterpretation in my HLS function. And this construct is not synthesizeable. This is mentioned in HLS user guide and also during synthesis it gives same error that this is not supported for synthesis.

I will try what u suggested and see if it works or not.

Best regards
Umair

Guanwen (Henry) Zhong

unread,
Feb 19, 2017, 2:32:49 AM2/19/17
to ReconOS
Hi Umair,

If your pointer is related to structure or array with fixed size (no malloc and double pointer), HLS generally can handle it.

The approach used to transfer floating data can run on the real board with reconos in my case. I guess it might also work for you.

Umair Riaz

unread,
Feb 22, 2017, 3:28:08 AM2/22/17
to ReconOS
Hi Henry,

It worked! Thank you for your help.

Best regards
Umar

Guanwen (Henry) Zhong

unread,
Feb 22, 2017, 3:47:52 AM2/22/17
to ReconOS
Glad it works for you. :-)
Reply all
Reply to author
Forward
0 new messages