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: 
Participant edvinuzas
Participant
427 Views
Registered: ‎11-28-2018

IP outputs 0s instead of a number.

I have been building a float matrix multiplier, which inputs and outputs ap_axiu<> type data and uses an union to reinterpret data. According to the User-Guide (UG902) pg.357 "Vivado HLS does not support access to a union through another variable. Using the same
union as the previous example, the following is not supported," 

for (int i = 0; i < 6; ++i)
if (i<3)
A[i] = intfp.intval.a + B[i];
else
A[i] = intfp.intval.b + B[i];
}

However, it may be explicitly re-coded as:

A[0] = intfp.intval.a + B[0];
A[1] = intfp.intval.a + B[1];
A[2] = intfp.intval.a + B[2];
A[3] = intfp.intval.b + B[3];
A[4] = intfp.intval.b + B[4];
A[5] = intfp.intval.b + B[5];

I understand this rule, therefore I have built a 2x2 matrix multiplier using this logic, which runs and only outputs [0][0], while everything else is left at "0". 

The code for this is shown below:

 

#include "ap_axi_sdata.h"
#include "ap_fixed.h"


typedef union {
	unsigned int as_uint32;
	float as_float32;
} conversion_datatype;

typedef float float32;
typedef unsigned int uint32;
typedef ap_axiu<32,2,5,6> streamdata;

void noloop(streamdata A[2][2], streamdata B[2][2]){
#pragma HLS INTERFACE ap_ctrl_none port=return
#pragma HLS INTERFACE axis port=A
#pragma HLS INTERFACE axis port=B

	conversion_datatype
	temp_in00,
	temp_in01,
	temp_in10,
	temp_in11,
	temp_out00,
	temp_out01,
	temp_out10,
	temp_out11;

	int y, x;

	uint32 inputarray[2][2];
	float32 inputarray_float[2][2];
	float32 temp_array[2][2] = {
			{0, 0},
			{0, 0}
	};
	float32 outputarray[2][2] = {
			{0, 0},
			{0, 0}
	};
	uint32 outputarray_converted[2][2];

	float32 matrix1[2][2] = {
			{0.5, 0.4},
			{1.5, 2.1}
	};

	float32 matrix2[2][2] = {
			{3.5, 0.8},
			{4.1, 3.25}
	};


	//INPUT STAGE
	//INPUT STAGE
	//INPUT STAGE

	//input
	inputarray[0][0] = A[0][0].data;
	inputarray[0][1] = A[0][1].data;
	inputarray[1][0] = A[1][0].data;
	inputarray[1][1] = A[1][1].data;

	//conversion uint32 >> float
	temp_in00.as_uint32 = inputarray[0][0];
	temp_in01.as_uint32 = inputarray[0][1];
	temp_in10.as_uint32 = inputarray[1][0];
	temp_in11.as_uint32 = inputarray[1][1];

	inputarray_float[0][0] = temp_in00.as_float32;
	inputarray_float[0][1] = temp_in01.as_float32;
	inputarray_float[1][0] = temp_in10.as_float32;
	inputarray_float[1][1] = temp_in11.as_float32;



	//TRANSFORMATION STAGE
	//TRANSFORMATION STAGE
	//TRANSFORMATION STAGE

	// multiplication #1

	//line1
	outputarray[0][0] = (matrix1[0][0] * inputarray_float[0][0]) + (matrix1[0][1] * inputarray_float[1][0]);
	outputarray[0][1] = (matrix1[0][0] * inputarray_float[0][1]) + (matrix1[0][1] * inputarray_float[1][1]);
	//line2
	outputarray[1][0] = (matrix1[1][0] * inputarray_float[0][0]) + (matrix1[1][1] * inputarray_float[1][0]);
	outputarray[1][1] = (matrix1[1][0] * inputarray_float[0][1]) + (matrix1[1][1] * inputarray_float[1][1]);



	//OUTPUT STAGE
	//OUTPUT STAGE
	//OUTPUT STAGE


	//conversion float >>> uint32
	temp_out00.as_float32 = outputarray[0][0];
	temp_out01.as_float32 = outputarray[0][1];
	temp_out10.as_float32 = outputarray[1][0];
	temp_out11.as_float32 = outputarray[1][1];
	outputarray_converted[0][0] = temp_out00.as_uint32;
	outputarray_converted[0][1] = temp_out01.as_uint32;
	outputarray_converted[1][0] = temp_out10.as_uint32;
	outputarray_converted[1][1] = temp_out11.as_uint32;

	//output

    B[0][0].data = outputarray_converted[0][0];
    B[0][0].keep = A[0][0].keep;
    B[0][0].strb = A[0][0].strb;
    B[0][0].user = A[0][0].user;
    B[0][0].last = A[0][0].last;
    B[0][0].id = A[0][0].id;
    B[0][0].dest = A[0][0].dest;
    
    B[0][1].data = outputarray_converted[0][1];
    B[0][1].keep = A[0][1].keep;
    B[0][1].strb = A[0][1].strb;
    B[0][1].user = A[0][1].user;
    B[0][1].last = A[0][1].last;
    B[0][1].id = A[0][1].id;
    B[0][1].dest = A[0][1].dest;

    B[1][0].data = outputarray_converted[1][0];
    B[1][0].keep = A[1][0].keep;
    B[1][0].strb = A[1][0].strb;
    B[1][0].user = A[1][0].user;
    B[1][0].last = A[1][0].last;
    B[1][0].id = A[1][0].id;
    B[1][0].dest = A[1][0].dest;
    
    B[1][1].data = outputarray_converted[1][1];
    B[1][1].keep = A[1][1].keep;
    B[1][1].strb = A[1][1].strb;
    B[1][1].user = A[1][1].user;
    B[1][1].last = A[1][1].last;
    B[1][1].id = A[1][1].id;
    B[1][1].dest = A[1][1].dest;

}

By inputting [ 1.1   2.2  ]

                    [ 3.3   4.4  ].

I should receive:

[ 1.87   2.86  ]

[ 8.58  12.54 ]

 

but instead of that I receive:

 

[ 1.87    0  ]

[ 0         0  ]

 

Does anybody know what could be happening here?

0 Kudos
4 Replies
Xilinx Employee
Xilinx Employee
397 Views
Registered: ‎01-09-2008

Re: IP outputs 0s instead of a number.

You should prepare your output in a tmp variable and then assign it as a whole to the output array.

==================================
Olivier Trémois
XILINX EMEA DSP Specialist
0 Kudos
Xilinx Employee
Xilinx Employee
391 Views
Registered: ‎01-09-2008

Re: IP outputs 0s instead of a number.

I mean something like this:

tmp.data = outputarray_converted[0][0];
tmp.keep = A[0][0].keep;
tmp.strb = A[0][0].strb;
tmp.user = A[0][0].user;
tmp.last = A[0][0].last;
tmp.id = A[0][0].id;
tmp.dest = A[0][0].dest;

B[0][0] = tmp;
==================================
Olivier Trémois
XILINX EMEA DSP Specialist
0 Kudos
Participant edvinuzas
Participant
383 Views
Registered: ‎11-28-2018

Re: IP outputs 0s instead of a number.

Thank you, is the variable "tmp" a user-defined structure, union or ap_axiu<> type?

0 Kudos
Highlighted
Xilinx Employee
Xilinx Employee
344 Views
Registered: ‎01-09-2008

Re: IP outputs 0s instead of a number.

tmp is just a "streamdata", the type you defined at the beginning.

 

==================================
Olivier Trémois
XILINX EMEA DSP Specialist
0 Kudos