# Send multiple arrays as input argument

**URL:** <https://discuss.pynq.io/t/send-multiple-arrays-as-input-argument/2563>\
**Category:** Support\
**Created:** [April 16, 2021, 10:48pm UTC](https://discuss.pynq.io/t/send-multiple-arrays-as-input-argument/2563 "2021-04-16T22:48:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![arshaan256](https://avatars.discourse-cdn.com/v4/letter/a/8baadc/32.png) [@arshaan256](https://discuss.pynq.io/u/arshaan256)\
**Post date:** [April 16, 2021, 10:48pm UTC](https://discuss.pynq.io/t/send-multiple-arrays-as-input-argument/2563/1 "2021-04-16T22:48:50Z")

</div>

I am trying to create a custom IP using Vivado HLS so as to explore the PYNQ Z2 Board provided by TUL. In this IP, I am trying to send two arrays of the same size, A[N] and B[N], as input to the IP, and then the IP would return an output array, C[N] where,

`C[i] = A[i] + B[i]`

Is it possible to send two input arrays to the board? How can I do it?

Things I have tried:

1. I tried to use the AXI Stream Interface and it works with one input array but I do not how to proceed with two input arrays. Should I use two DMAs? One for each input array? How should the HLS code be altered in that case?

2. [Pynq custom overlay of multidimensional array calculation using vivado hls](https://discuss.pynq.io/t/pynq-custom-overlay-of-multidimensional-array-calculation-using-vivado-hls/1718) – Using the AXILITE Interface as suggested works but it is tedious, is there any better method?

---

<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, 6:42pm UTC](https://discuss.pynq.io/t/send-multiple-arrays-as-input-argument/2563/2 "2021-04-17T18:42:49Z")

</div>

you can intercalate the 2 arrays and send it via 1 axi-stream. Or even easier: encode both arrays in one [2]x[n] (or [n]x[2)]array. In HLS, you then read the stream twice before you work your mathemagics. Another, possibly faster, solution would be to encode the 2 arrays in a double bitwidth array eg.: A and B being arrays of 32b integers or floats or whatever. you encode A in bits 63~32 and B in bits 31~0. AXI HP ports allow for 64b wide transfers. Depending on where you want to do most of the processing, or if a little bit higher latency is a problem you may want to use one or the other solution.

below is an exerpt (probably horribly inefficient) of a convert to grayscale HLS core. 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();  
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;

* * *

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);
