Problems with a simple floating point adder overlay on PYNQZ-2

I have made a simple adder on Vivado HLS with float input and outputs.

float%20adder

On Jupyter Notebooks in PYNQ-Z2, I get the following errors.

How does one fix this problem?

Also, I am thinking of using Python to multiply inputs by some 10^n, write to the IP and dividing the outputs by 10^n. Is this inefficient when working with a larger set of data with a huge decimal place?

As you noticed, MMIO doesn’t support float. You need to manually ‘pack’ your float into something that can be written to the IP, and do the reverse if you need to read back the result.

You can use these types of techniques:
https://stackoverflow.com/questions/23624212/how-to-convert-a-float-into-hex

Cathal

1 Like

I have tried the same thing with my PYNQ-Z2 using v2.7. I didn’t get the MMIO error. Instead, the adder returned simply c = 0, no matter the value that I send as a or c.

I knew, as Cathal mentioned before, that I needed to package the float number as an u32 integer IEEE 754 standard fro expressing floating-point numbers.

I found a solution on the web that allow conversion of floating-point value in Python to integer-type numbver compatible with IEEE 754 standard (I would like to give a reference, but I lost it). Here is the code to send values to a and b, then read the result in c where a, b and c are all floating-point numbers in Python:

add_ip.write(0x10, struct.unpack('I', struct.pack('f', a))[0])
add_ip.write(0x18, struct.unpack('I', struct.pack('f', b))[0])
c = struct.unpack('f', struct.pack('I', add_ip.read(0x20)))[0]

Hope this help!

1 Like

In this post, there is also a solution

Mario