Axis to uint

Hi everyone,

I’m trying to implement a conversion between axis and uint. I started from this example Tutorial: using a HLS stream IP with DMA (Part 1: HLS design) and I followed all 3 parts.

The starting code, as shown in the link posted is the following:

#include "ap_axi_sdata.h"
#include "hls_stream.h"

void example(hls::stream< ap_axis<32,2,5,6> > &A,
	     hls::stream< ap_axis<32,2,5,6> > &B)
{
#pragma HLS INTERFACE axis port=A
#pragma HLS INTERFACE axis port=B
#pragma HLS INTERFACE s_axilite port=return

	ap_axis<32,2,5,6> tmp;
    while(1)
    {
	A.read(tmp);
	tmp.data = tmp.data.to_int() + 5;
	B.write(tmp);
     if(tmp.last)
     {
         break;
     }
    }
}

This works properly, and if I run it on the board everything works as expected.

My implementation is the following:

#include "ap_axi_sdata.h"
#include "hls_stream.h"

template<unsigned NUM_BITS>
void axis_to_uint(hls::stream<ap_axis<NUM_BITS,0,0,0>> &axis_in, hls::stream<ap_uint<NUM_BITS>> &uint_out){
	ap_axis<NUM_BITS,0,0,0> in_data = axis_in.read();
	uint_out.write(in_data.data);

}

template<unsigned NUM_BITS>
void uint_to_axis(hls::stream<ap_uint<NUM_BITS>> &uint_in, hls::stream<ap_axis<NUM_BITS,0,0,0>> &axis_out){
	ap_uint<NUM_BITS> input_data = uint_in.read();
	ap_axis<NUM_BITS,0,0,0> out_data;
	out_data.data = input_data;
	axis_out.write(out_data);
}


void example(hls::stream< ap_axis<32,0,0,0> > &A,
	     hls::stream< ap_axis<32,0,0,0> > &B)
{
#pragma HLS INTERFACE axis port=A
#pragma HLS INTERFACE axis port=B
#pragma HLS INTERFACE s_axilite port=return

	hls::stream<ap_uint<32>> uint_A;
	hls::stream<ap_uint<32>> uint_B;

	axis_to_uint<32>(A, uint_A);

	ap_uint<32> tmp;

	uint_A.read(tmp);
	tmp = tmp.to_int() + 5;
	uint_B.write(tmp);

	uint_to_axis<32>(uint_B, B);

}

It is really similar, with the only difference that there is an intermediate step to convert to uint and from uint. I’m doing this because I need to test some libraries that uses uint as input.

Has anyone already done this type of conversion? If yes, can you help me? if no, I’m open for other solution that allows me to test the libraries I need without the conversion, so working directly with uint.

Thanks for your help!

If you need further details (just let me know) I can attach some pictures of the Vivado design or directly the .bit and .hwh

Best regards,
Giovanni

Hi @giop98,

Conceptually, you do not need any conversion. It is just a matter of interpreting the bits differently.
Having, said that. Instead of the intermediate step, you can use a different datatype on your IP. For instance:

#include "ap_axi_sdata.h"
#include "hls_stream.h"

void example(hls::stream< ap_axiu<32,2,5,6> > &A,
	     hls::stream< ap_axiu<32,2,5,6> > &B)
{
#pragma HLS INTERFACE axis port=A
#pragma HLS INTERFACE axis port=B
#pragma HLS INTERFACE s_axilite port=return

	ap_axiu<32,2,5,6> tmp;
    while(1)
    {
	A.read(tmp);
	tmp.data = tmp.data.to_int() + 5;
	B.write(tmp);
     if(tmp.last)
     {
         break;
     }
    }
}

Hope this helps.
Mario

1 Like

Thank you very much. In the end I found out that the problem of my design was related to the DMA connection on Vivado. However I confirm that there is no need to execute a conversion. The solution you proposed is perfectly working!

I think you can mark this as solved.

Thanks

1 Like