HLS floating point operation does not work

Everything that doesn't fit the other categories

HLS floating point operation does not work

Postby Guest »

I am using xillybus ip core to communicate data between linux running on PS of zedboard with the ipcore on PL.Basically,I want to convert an image into grayscale.As a prototype I am sending a 4*12(48 elements) matrix from linux to PL and after performing averaging of every three pixels per row I get a grayscale value which is read back into a 4*4(16 elements) matrix.Now the problem is the code I use for averaging the pixels does not give correct values.The first column is correct but the rest of the columns are zero.
I extended the HLS demo code that comes with xillybus to write my code for averaging every three elements row wise.I suspect there is either something wrong with the way I am using floating point operations or the way I am reading or writing might be faulty.
Please, have a look at my HLS code and guide me.

#include <math.h>
#include <stdint.h>
#include "xilly_debug.h"
#include "ap_cint.h"
#include "ap_utils.h"

float rgb2gray(float r, float g, float b) {
float gray = (r + g + b)/3;
return gray;
void xillybus_wrapper(int *in, int *out) {
#pragma AP interface ap_fifo port=in
#pragma AP interface ap_fifo port=out
#pragma AP interface ap_ctrl_none port=return

float x1, x2, x3;
uint8_t res;
uint32_t i;
float y1;

for (i = 1; i <= 16 ;i++)
// Handle input data
x1 = *in++;
x2 = *in++;
x3 = *in++;

// Run the calculations
y1 = rgb2gray(x1, x2 ,x3);
res = uint8_t(y1);

// Handle output data
*out++ = res;


Re: HLS floating point operation does not work

Postby support »


How do you pack the data in the host's application? You are aware, I hope, that the types of both input and output FIFOs is int, hence 4 bytes for each read and write...? If so, it's not clear why you convert the result to a uint8_t. The "*out++ = res" produces an int anyhow ("out" is of type "int *").

Posts: 802

Re: HLS floating point operation does not work

Postby Guest »

Actually, on the host application's side I am using "opencv" library to create a matrix to be sent to xillybus and then another application on the host reads from xillybus to display the result in another matrix.The datatype of elements in a matrix is UCHAR which opencv defines to be an 8 bit unsigned integer.That's why I am converting the resulting floating point number after averaging to uint_8 so it acts as an element of an image.

The code works perfectly fine if the three values to be avaraged out do not give a float ,but if they do, I see a high valued integer on the output instead of a float or some truncated int.

And I believe I didn't know that the data type of the input and output of fifo's is int.If so,
1)How does it input or output floats?
2)If my code outputs a float and I want to truncate it into an integer(8 bit for example) should I do it on the PS side on linux or can I do it on the PL too.

Return to Other topics