# Understanding how to use custom overlay

**URL:** <https://discuss.pynq.io/t/understanding-how-to-use-custom-overlay/2162>\
**Category:** Support\
**Created:** [December 21, 2020, 7:19am UTC](https://discuss.pynq.io/t/understanding-how-to-use-custom-overlay/2162 "2020-12-21T07:19:06Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Souyu](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/souyu/32/1419_2.png) [@Souyu](https://discuss.pynq.io/u/Souyu)\
**Post date:** [December 21, 2020, 7:19am UTC](https://discuss.pynq.io/t/understanding-how-to-use-custom-overlay/2162/1 "2020-12-21T07:19:06Z")

</div>

So I’ve made a overlay, now I have a simple question, how do I use the overlay and access the accelerated functions in jupyter notebook? I’ve uploaded a image of what my overlay looks like:

 ![vivado_giRtLaVAp6](https://us1.discourse-cdn.com/flex019/uploads/pynq1/original/2X/1/1aab4e98c18bbff6a12cc41985afb9c05ee6948b.png)

I’m trying to use the HOG descriptor accel, but I’m not sure how to feed data to it, or read the output. Any help would be appreciated.

---

<div class="post-metadata">

**Author:** ![momo\_flyer](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/momo_flyer/32/874_2.png) [@momo\_flyer](https://discuss.pynq.io/u/momo_flyer)\
**Post date:** [December 21, 2020, 2:11pm UTC](https://discuss.pynq.io/t/understanding-how-to-use-custom-overlay/2162/2 "2020-12-21T14:11:34Z")

</div>

[https://pynq.readthedocs.io/en/v2.0/overlay\_design\_methodology/overlay\_tutorial.html](https://pynq.readthedocs.io/en/v2.0/overlay_design_methodology/overlay_tutorial.html)  
https://www.youtube.com/embed/Dupyek4NUoI?feature=oembed&wmode=opaque&list=PLIs1b8ziMXQZeg06pmqSquK70ydQLA4y5  
instead of the .tcl file however, you need to copy the .hwh file along with your bitfile.  
Both have to be named the same (except for the file extension).

Best of luck

---

<div class="post-metadata">

**Author:** ![AllenChenChao](https://avatars.discourse-cdn.com/v4/letter/a/7bcc69/32.png) [@AllenChenChao](https://discuss.pynq.io/u/AllenChenChao)\
**Post date:** [December 28, 2020, 1:46am UTC](https://discuss.pynq.io/t/understanding-how-to-use-custom-overlay/2162/3 "2020-12-28T01:46:09Z")

</div>

downlad .bit, .tcl , .hwh files on jupyter, and use it.

---

<div class="post-metadata">

**Author:** ![Souyu](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/souyu/32/1419_2.png) [@Souyu](https://discuss.pynq.io/u/Souyu)\
**Post date:** [April 16, 2021, 9:50pm UTC](https://discuss.pynq.io/t/understanding-how-to-use-custom-overlay/2162/4 "2021-04-16T21:50:24Z")

</div>

Picked up this project again now that I have time, but I’m still stuck on this part. How do I write the image into the register? I’m not sure how to convert it into byte array so it can write into the register.

 ![image](https://us1.discourse-cdn.com/flex019/uploads/pynq1/original/2X/e/e7b377964938f10ce173ceecc8c26d2c347e993f.png)

---

<div class="post-metadata">

**Author:** ![momo\_flyer](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/momo_flyer/32/874_2.png) [@momo\_flyer](https://discuss.pynq.io/u/momo_flyer)\
**Post date:** [April 17, 2021, 9:51am UTC](https://discuss.pynq.io/t/understanding-how-to-use-custom-overlay/2162/5 "2021-04-17T09:51:26Z")

</div>

your video section is currently a black box so it’s not really possible to see how everything is wired in there. Also if it’s a video processing module, it may be easier to use an AXI-DMA. Both python and DMA should allow for 64b wide transfers using the AXI-HP ports. using it is then fairly straightforward: you free some space in DDR RAM using 2 XINK buffers (1 for tx,1 for rx), you copy your image to the buffer and start the DMA. after it’s done you can open the new image. you just need to make sure everything is correctly formatted so both python and hardware can interpret the data. Naturally for this to work, you need AXI-stream interfaces instead of full or lite interfaces.

---

<div class="post-metadata">

**Author:** ![Souyu](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/souyu/32/1419_2.png) [@Souyu](https://discuss.pynq.io/u/Souyu)\
**Post date:** [April 18, 2021, 8:05am UTC](https://discuss.pynq.io/t/understanding-how-to-use-custom-overlay/2162/6 "2021-04-18T08:05:08Z")

</div>

The video section I just ripped out from the original base overlay, but here’s a picture of what’s inside:

 ![image](https://us1.discourse-cdn.com/flex019/uploads/pynq1/original/2X/f/f3a4a701330625ebd1254e1eb2241318a9bb195e.png)

I’m not sure with how to setup or access the AXI-DMA. I 'd assume I’ll have to link it to the custom ip, but I don’t know how to get started with that…

---

<div class="post-metadata">

**Author:** ![momo\_flyer](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/momo_flyer/32/874_2.png) [@momo\_flyer](https://discuss.pynq.io/u/momo_flyer)\
**Post date:** [April 18, 2021, 10:12am UTC](https://discuss.pynq.io/t/understanding-how-to-use-custom-overlay/2162/7 "2021-04-18T10:12:09Z")

</div>

watch these 3 videos:  
the first is how to make, implement and access an HLS IP  
2nd is how to make and implement an HLS AXI-stream IP with AXI-DMA  
3rd is how to use it in python on the PS

[![]( " - YouTube") ](https://www.youtube.com/watch?v=Dupyek4NUoI)

[![](https://us1.discourse-cdn.com/flex019/uploads/pynq1/original/2X/b/b9a552115ab9fdb90161c8d7c02e6b945f935ada.jpeg "VIVADO HLS Training AXI Stream interface #07") ](https://www.youtube.com/watch?v=3So1DPe2_4s)

[![]( " - YouTube") ](https://www.youtube.com/watch?v=LoLCtSzj9BU)

before calling the DMA.wait() functions, be sure to start the IP by writing 0x01 to adress 0x00 of the IP core (HOG\_accel.write(0x00,0x01) )

---

<div class="post-metadata">

**Author:** ![Souyu](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/souyu/32/1419_2.png) [@Souyu](https://discuss.pynq.io/u/Souyu)\
**Post date:** [April 19, 2021, 11:23pm UTC](https://discuss.pynq.io/t/understanding-how-to-use-custom-overlay/2162/8 "2021-04-19T23:23:28Z")

</div>

I’m trying to connect to the input and output of the DMA from the accel, but it seems the ports are incompatible? Not sure where to go from there.

 ![image](https://us1.discourse-cdn.com/flex019/uploads/pynq1/original/2X/3/3f598cf542e3d5e07d7a5bb48368edfc42900456.png)

---

<div class="post-metadata">

**Author:** ![momo\_flyer](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/momo_flyer/32/874_2.png) [@momo\_flyer](https://discuss.pynq.io/u/momo_flyer)\
**Post date:** [April 19, 2021, 11:46pm UTC](https://discuss.pynq.io/t/understanding-how-to-use-custom-overlay/2162/9 "2021-04-19T23:46:46Z")

</div>

1st you need to write your IP so it has AXI-stream interfaces. this is explained and shown in the 2nd video. you will have 1 or 2 axi stream ins and outs? and your ctrl signals.  
2nd a normal DMA is easier to use to begin with, the VDMA is a bit weird in its use of control signals of the axi stream interface.

maybe stupidly enough, reproduce the tutorial given in the 2nd video, and implement it first? then you’ll get how axi stream interfaces work on the most basic level and then you can go from there.

below is an exerpt (probably horribly inefficient) of a convert to grayscale HLS core using normal DMA. On the PS, you just open an image, put it in a [n]x[m]x[3] array and stream it to PL.

* * *

#include “cvt2gray.h”

void cvtgray(int xres, int yres,axi\_stream& img\_in, axi\_stream& img\_out){

#pragma HLS PIPELINE II=2  
#pragma HLS INTERFACE s\_axilite port=yres  
#pragma HLS INTERFACE s\_axilite port=xres  
#pragma HLS INTERFACE axis port=img\_in  
#pragma HLS INTERFACE axis port=img\_out  
#pragma HLS interface s\_axilite port=return

axi\_pixel pix\_in1\_r,pix\_in1\_g,pix\_in1\_b;  
axi\_pixel pix\_out\_r,pix\_out\_g,pix\_out\_b;  
uint8\_t r1,g1,b1,gray1;

for(int i=0;i\<yres;i++){  
#pragma HLS LOOP\_TRIPCOUNT min=1 max=4000

```
for (int j=0;j<xres;j++){

```

#pragma HLS LOOP\_TRIPCOUNT min=1 max=4000  
pix\_in1\_r=img\_in.read(); //you read the 3 color values  
pix\_in1\_g=img\_in.read();  
pix\_in1\_b=img\_in.read();

```
    **insert mathemagic here**
	r1=pix_in1_r.data*0.11;
	g1=pix_in1_g.data*0.59;
	b1=pix_in1_b.data*0.30;

    
	gray1=r1+g1+b1;

    **manually set the control signals**
	pix_out_r.data=gray1;
	pix_out_r.dest=pix_in1_r.dest;
	pix_out_r.id=pix_in1_r.id;
	pix_out_r.keep=pix_in1_r.keep;
	pix_out_r.last=pix_in1_r.last;
	pix_out_r.strb=pix_in1_r.strb;
	pix_out_r.user=pix_in1_r.user;
	pix_out_g.data=gray1;
	pix_out_g.dest=pix_in1_g.dest;
	pix_out_g.id=pix_in1_g.id;
	pix_out_g.keep=pix_in1_g.keep;
	pix_out_g.last=pix_in1_g.last;
	pix_out_g.strb=pix_in1_g.strb;
	pix_out_g.user=pix_in1_g.user;
	pix_out_b.data=gray1;
	pix_out_b.dest=pix_in1_b.dest;
	pix_out_b.id=pix_in1_b.id;
	pix_out_b.keep=pix_in1_b.keep;
	pix_out_b.last=pix_in1_b.last;
	pix_out_b.strb=pix_in1_b.strb;
	pix_out_b.user=pix_in1_b.user;

 **write it to the output stream**
	img_out.write(pix_out_r);
	img_out.write(pix_out_g);
	img_out.write(pix_out_b);

}

```

}

* * *

the .h file:

#include \<stdio.h\>  
#include \<stdint.h\>  
#include “hls\_stream.h”  
#include “hls\_video.h”  
#include “ap\_utils.h”  
#include “ap\_fixed.h”  
#include “ap\_int.h”

#define max\_width 1920  
#define max\_height 1200  
typedef ap\_axiu\<8,2,5,6\> axi\_pixel;  
typedef hls::stream\<axi\_pixel\> axi\_stream;  
void cvtgray(int xres, int yres,axi\_stream& img\_in, axi\_stream& img\_out);
