Execute hls example with pointers from pynq

The question is how to use a hls function’s input and output variables that are pointers from a Pynq/Jupyter.
I know how to perform the exercise with non-pointers.

I’ve built the xilinx example interface_axi_lite.

#include <stdio.h>
void example(char *a, char *b, char *c)
{
#pragma HLS INTERFACE s_axilite port=a bundle=BUS_A
#pragma HLS INTERFACE s_axilite port=b bundle=BUS_A
#pragma HLS INTERFACE s_axilite port=c bundle=BUS_A
#pragma HLS INTERFACE s_axilite port=return bundle=BUS_A

  *c += *a + *b;
}

In Vivado, I added it to a block design (named it add_to_self, built the bitfile and the .hwh file, uploaded to a PYNQ-Z2

I created a Jupyter book and loaded the bitfile:

Loading the bitfile works, and the registers for the add_to_self function show:

overlay=Overlay("adder.bit")
add_to_self_ip=overlay.add_to_self
add_to_self_ip.register_map

Output:

RegisterMap {
  CTRL = Register(AP_START=0, AP_DONE=0, AP_IDLE=1, AP_READY=0, RESERVED_1=0, AUTO_RESTART=0, RESERVED_2=0),
  GIER = Register(Enable=0, RESERVED=0),
  IP_IER = Register(CHAN0_INT_EN=0, CHAN1_INT_EN=0, RESERVED=0),
  IP_ISR = Register(CHAN0_INT_ST=0, CHAN1_INT_ST=0, RESERVED=0),
  a = Register(a=0, RESERVED=0),
  b = Register(b=0, RESERVED=0),
  c_i = Register(c_i=0, RESERVED=0),
  c_o = Register(c_o=0, RESERVED=0),
  c_o_ctrl = Register(c_o_ap_vld=0, RESERVED=0

Now my question: how do I execute this function where a, b, c_i and c_o are pointers, from python/Jupyther?

1 Like

I realise you may be a beginner and you want to learn, but did you really intend c as both an input and and output? You can do this, but it is awkward with the handshake register (c_o_control)

Could you change your code to something like this?:

int tmp;
tmp = *c + *a + *b;
return tmp;

You have the registers, so you need to write the values to the a and b (and c?) registers.
You then need to write the correct value to the CTRL (Control) register to start the IP. 0x1 will start it once.
You can then readback the value from c when valid. In practice, the delay in Python to read the c register will be longer than the time it takes for c to become available, so you shouldn’t need to check if c is valid.
If you want to calculate another value, you will need to write the start value to the CTRL register.
You can write an autorestart value, but I don’t think it makes sense for this example. You should setup A and B before each iteration.

Cathal

2 Likes

Thank you.

Could you change your code to something like this?:

Yes. The thing is that the code is part of training material. I wanted to use it as a hook for my learning.

I’m going to try it with the tmp instead of the *c. And check the start instruction.

It was the control register. Once I wrote 0x01 to it, the hls executed.

image

Thank you.

1 Like