Array formatting: pynq notebook -> hls kernel

Say we have a notebook:

...

A=np.array(...)
dma0 = ol.axi_dma_0

...

DIM=2
DATA_TYPE = np.uint32
in_buffer_A = allocate(shape=(DIM,DIM), dtype=DATA_TYPE)
np.copyto(in_buffer_A, A)

...

dma0.sendchannel.transfer(in_buffer_A)

...

I am wondering how exactly the data from in_buffer_A is fed to the kernel?

I.e. if it is an array like:

A = [[1,2],[3,4]]

Will the order of the stream in the kernel read: [1,2,3,4] or [1,3,2,4]? Or something else, entirely?

Hi @alienflip,

allocate uses numpy. So, it all comes down to how the buffer are stored in memory. You can answer this question easily with this piece of code.

... load overlay ...

shape = (2, 2)
buf0 = allocate(shape=shape, dtype=np.uint32)
buf1 = allocate(shape=(shape[0]*shape[1], ), dtype=np.uint32)
buf2 = allocate(shape=(shape[0]*shape[1], ), dtype=np.uint32)

buf0[:] = [[1, 2],[3, 4]]
buf1[:] = [1, 2, 3, 4]
buf2[:] = [1, 3, 2, 4]

print("In memory: (buf0==buf1)={} and (buf0==buf2)={}"
      .format(buf0.tobytes() == buf1.tobytes(), buf0.tobytes() == buf2.tobytes()))

.tobytes() returns the bytes as they are stored in memory. After you run the code you will see that the answer is [1, 2, 3 ,4]

Mario

I did some explorations here, too …
[[1,2],[3,4]] is read as [1,2,3,4] :slight_smile:

1 Like