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
Did you mean:
Observer
275 Views
Registered: ‎01-14-2019

## Need help with Floating point data stream & arithmetic

Hello all, I need help with using Floating point data with HLS.

I've designed a IP that reads in (signed) float data, does a convolution of float data input, and write the result as float data. But it turns out I can't normally do floating point arithmetic in HLS. It's suggested that I use fixed point data, but I'm having trouble understanding how to use it for my case.

So far I was able to write the testbench to send float data in uint32_t format using these definitions :

```typedef ap_axis <32,1,1,1> AXIS;      // hls::stream
typedef hls::stream<AXIS> STREAM_T;   //
typedef union {   // float32<->int32 convert
int u;
float f;
} uni;```

Now I'm guessing that I should convert uint32_t format to fixed point, and do the convolution using fixed point variables. But I'm completely new to using fixed point data types. I've looked into ug902 manual, but still not sure how I should use it.

What I want to do would look like this :

```output = input1 * input 2
// input1 (-1,1), input2 (-1,1)```

Are there examples of converting float data input to fixed point and doing arithmetics?

1 Solution

Accepted Solutions
Highlighted
Xilinx Employee
241 Views
Registered: ‎09-05-2018

## Re: Need help with Floating point data stream & arithmetic

Hey @mh9840 ,

Olivier has posted a nice simple example of how to pass data as an integer and then interpret it as a float here:

I think something like the following is what you're looking for:

```typedef hls::stream<int> STREAM_T;

typedef union {   // float32<->int32 convert
int u;
float f;
} uni;

void top( STREAM_T& in1, STREAM_T& in2, STREAM_T& out) {
uni input1, input2, output;
in1 >> input1.u;
in2 >> input2.u;
output.f = input1 * output2;
out << output.u;
}```

Let me know if that helps,

Nicholas Moellers

Xilinx Worldwide Technical Support
Highlighted
Xilinx Employee
242 Views
Registered: ‎09-05-2018

## Re: Need help with Floating point data stream & arithmetic

Hey @mh9840 ,

Olivier has posted a nice simple example of how to pass data as an integer and then interpret it as a float here:

I think something like the following is what you're looking for:

```typedef hls::stream<int> STREAM_T;

typedef union {   // float32<->int32 convert
int u;
float f;
} uni;

void top( STREAM_T& in1, STREAM_T& in2, STREAM_T& out) {
uni input1, input2, output;
in1 >> input1.u;
in2 >> input2.u;
output.f = input1 * output2;
out << output.u;
}```

Let me know if that helps,

Nicholas Moellers

Xilinx Worldwide Technical Support