# Operate on 2D-Array

**URL:** https://discuss.pynq.io/t/operate-on-2d-array/4463
**Category:** Support
**Created:** [July 15, 2022, 12:21pm UTC](https://discuss.pynq.io/t/operate-on-2d-array/4463 "2022-07-15T12:21:13Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![alienflip](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/alienflip/32/3408_2.png) [@alienflip](https://discuss.pynq.io/u/alienflip)
#### Post date: [July 15, 2022, 12:21pm UTC](https://discuss.pynq.io/t/operate-on-2d-array/4463/1 "2022-07-15T12:21:13Z")

</div>

Hey again all 🙂

I am using PYNQ-Z2 v2.7, with Vivado/Vitis 2022.1.

Currently trying to do something on a 2d array - the pseudo code would be:

```auto
for(int ix = 0; ix < size; ix++){
    for(int iy = 0; iy < size; iy++){
        if(ix + iy % 2 == 0){
            OUTPUT[ix][iy] = INPUT[iy][ix];
        }
        else{
            OUTPUT[ix][iy] = 0;
        }
    }
}

```

Ideally, the notebook would look like this:

```auto
import time, random, numpy
from pynq import Overlay, allocate
import pynq.lib.dma

ol = Overlay('./design_1.bit')
ol.download()

dma0 = ol.axi_dma_0
dma1 = ol.axi_dma_1

arr = numpy.random.randint(10, size=(128,128))
zeros = numpy.zeros(arr.shape, dtype=int)

in_buffer = allocate(shape=arr.shape, dtype=numpy.int32) 
out = allocate(shape=zeros.shape, dtype=numpy.int32) 

numpy.copyto(in_buffer, arr)
numpy.copyto(out, zeros)

t_start = time.time()
dma0.sendchannel.transfer(in_buffer)
dma0.recvchannel.transfer(out)
dma0.sendchannel.wait()
dma0.recvchannel.wait()
t_stop = time.time()

in_buffer.close()
out.close()

print("Hardware execution speed: ", t_stop - t_start)
print("Array out: ", out)

```

I am just wondering how to go about reading the buffer here from hls? How would we go about dereferencing particular elements?

I noticed [this post](https://discuss.pynq.io/t/how-to-contribute-project-to-the-list-of-community-projects/1128) mentions [HLS ARRAY\_PARTITION](https://github.com/twaclaw/matmult/blob/d649c0500cee29a26a2633277eb77a579ad84a0e/hls/matmult_accel.cpp#L33) and [HLS PIPELINE](https://github.com/twaclaw/matmult/blob/master/hls/matmult_accel.cpp#L12) … is there some inbuilt hls FPGA functionality here already for array handling?

Could someone help demystify the pragmas?!

I also looked at the [vitis examples](https://github.com/Xilinx/Vitis_Accel_Examples/tree/2021.2/cpp_kernels/array_partition), but they dont reference `hls:stream` … maybe the idea is to combine the approaches?

… anyhow …

Thanks!

🙂

---

<div class="post-metadata">

### Author: ![marioruiz](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/marioruiz/32/2177_2.png) [@marioruiz](https://discuss.pynq.io/u/marioruiz)
#### Post date: [July 15, 2022, 1:56pm UTC](https://discuss.pynq.io/t/operate-on-2d-array/4463/2 "2022-07-15T13:56:38Z")

</div>

Hi @alienflip,

This is not really a PYNQ question. However, there are many posts with similar questions.

Please check out these tutorials

> [@Tutorial: PYNQ DMA (Part 1: Hardware design)](https://discuss.pynq.io/t/tutorial-pynq-dma-part-1-hardware-design/3133):
>
> PYNQ DMA tutorial (Part 1: Hardware design) This tutorial will show you how to use the Xilinx AXI DMA with PYNQ. It will cover adding the AXI DMA to a new Vivado hardware design and show how the DMA can be controlled from PYNQ. This tutorial is based on the v2.6 PYNQ image and will use Vivado 2020.1. If you are using a different PYNQ version you should be able to follow the same steps in this tutorial, but you should make sure you are using the supported version of Vivado for that PYNQ release. …

> [@Tutorial: AXI Master interfaces with HLS IP](https://discuss.pynq.io/t/tutorial-axi-master-interfaces-with-hls-ip/4032):
>
> PYNQ HLS AXI Master tutorial Introduction Previous tutorials show how to build IP with AXI stream interfaces and how they can be connected in a Vivado project to an AXI DMA. The DMA can be controlled from PYNQ to send data to the IP and receive results. AXI stream interfaces are useful if you are connecting multiple IP together in a dataflow type architecture. However, you don’t have to use AXI streams and DMAs with HLS IP. HLS supports AXI master interfaces which can read and write data as r…

Mario

---

<div class="post-metadata">

### Author: ![alienflip](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/alienflip/32/3408_2.png) [@alienflip](https://discuss.pynq.io/u/alienflip)
#### Post date: [July 15, 2022, 4:36pm UTC](https://discuss.pynq.io/t/operate-on-2d-array/4463/3 "2022-07-15T16:36:26Z")

</div>

Ah, ok … where best to ask questions about the pragmas?

---

<div class="post-metadata">

### Author: ![marioruiz](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/marioruiz/32/2177_2.png) [@marioruiz](https://discuss.pynq.io/u/marioruiz)
#### Post date: [July 15, 2022, 4:49pm UTC](https://discuss.pynq.io/t/operate-on-2d-array/4463/4 "2022-07-15T16:49:56Z")

</div>

In the Xilinx forums [https://support.xilinx.com/s/topic/0TO2E000000YKXtWAO/hls?language=en\_US](https://support.xilinx.com/s/topic/0TO2E000000YKXtWAO/hls?language=en_US)

---

<div class="post-metadata">

### Author: ![alienflip](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/alienflip/32/3408_2.png) [@alienflip](https://discuss.pynq.io/u/alienflip)
#### Post date: [July 18, 2022, 12:46am UTC](https://discuss.pynq.io/t/operate-on-2d-array/4463/5 "2022-07-18T00:46:35Z")

</div>

Can follow [here](https://support.xilinx.com/s/question/0D52E00007IPhFSSA1/hls-stalling-on-matrix-multiplication?language=en_US)

---

<div class="post-metadata">

### Author: ![system](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/system/32/2_2.png) [@system](https://discuss.pynq.io/u/system)
#### Post date: [May 3, 2023, 9:39am UTC](https://discuss.pynq.io/t/operate-on-2d-array/4463/6 "2023-05-03T09:39:12Z")

</div>

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.
