# HLS works/But not taking result in python

**URL:** <https://discuss.pynq.io/t/hls-works-but-not-taking-result-in-python/2029>\
**Category:** Support\
**Created:** [November 17, 2020, 8:09pm UTC](https://discuss.pynq.io/t/hls-works-but-not-taking-result-in-python/2029 "2020-11-17T20:09:36Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kwstis](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/kwstis/32/779_2.png) [@Kwstis](https://discuss.pynq.io/u/Kwstis)\
**Post date:** [November 17, 2020, 8:09pm UTC](https://discuss.pynq.io/t/hls-works-but-not-taking-result-in-python/2029/1 "2020-11-17T20:09:36Z")

</div>

Hello everyone,  
I have writen an HLS code where C simulation and Cosimulation works fine. Also my vivado project i think works as i have tested it with other IP and works fine. HLS—\> [chachaCore.cpp](https://discuss.pynq.io/uploads/short-url/aOqNCB6Wgm6sIGwLloxglJuZZRM.cpp) (4.2 KB) [my\_chacha\_hls.cpp](https://discuss.pynq.io/uploads/short-url/ujyFGRPXXXZntALgeHynPgzUsNK.cpp) (538 Bytes) [my\_chacha\_hls.hpp](https://discuss.pynq.io/uploads/short-url/iI2CbmPc7T0Nh6w61Ajhi0fJiDl.hpp) (935 Bytes) [ps2chacha.cpp](https://discuss.pynq.io/uploads/short-url/dKbk9Ce65g9fqTmaPds0IdAt3Xc.cpp) (507 Bytes)  
The small functions QR,LITTLE\_INT and MOD\_OV are very small and only do mathematic. I had QR declaration like (uint32&a,uint32&b…) in order not to use struct but i am not sure if i can do that in hardware so i changed it.  
Vivado →

 ![Screenshot_1](https://us1.discourse-cdn.com/flex019/uploads/pynq1/original/2X/d/daa5670865bd47c17f524ab37a3344d1b8a77a8b.jpeg)  
Python →   
input\_buffer = allocate(shape=(1,), dtype=‘S64’)  
output\_buffer = allocate(shape=(endoff+1,), dtype=‘S64’)

input\_buffer[:] = np.array(buffer)  
print(input\_buffer)

dma.sendchannel.transfer(input\_buffer)  
dma.recvchannel.transfer(output\_buffer)

result.extend(list(output\_buffer.copy()))

print(len(result))  
print(result)

del input\_buffer,output\_buffer

RESULT–\>  
[b’00000000\xbc`t\xbc\xf1\xcf\x8e\t\xda\xb8G\x85\xde\x0cy\xab\xb1\xfdw\x94dd\xf7\xe2T\x05\xfb\xcf\xc95l|\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x05’]  
6  
[b’‘, b’‘, b’‘, b’‘, b’‘, b’']—NOT ANY INFORMATION AND IF I RERUN IT ERROR DMA channel not idle occur. Also if i put .recvchannel.wait() hanges there forever.

Any idea please???

---

<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:** [November 21, 2020, 9:02am UTC](https://discuss.pynq.io/t/hls-works-but-not-taking-result-in-python/2029/2 "2020-11-21T09:02:25Z")

</div>

@Kwstis,

What is the data width of the HP interface?  
What is the address width and stream data width of the DMA?

Maybe you can insert an System ILA and check if the input stream to the HLS module matches what you are sending from python.

Mario

---

<div class="post-metadata">

**Author:** ![Kwstis](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/kwstis/32/779_2.png) [@Kwstis](https://discuss.pynq.io/u/Kwstis)\
**Post date:** [November 21, 2020, 12:27pm UTC](https://discuss.pynq.io/t/hls-works-but-not-taking-result-in-python/2029/3 "2020-11-21T12:27:51Z")

</div>

I feel a bit silly as i found that i was sending wrong bytes from python. Now it works but my problem is that i can run it only once. If I want to rerun it i have to close the ipynb and redownload the bit file.In case not do that a wrong occur like the dma is not start. Also despite the fact that simulation and cosimulation shows correct results when i run my bit file from python the results are wrong. Maybe i will try to see with ILA in order to understand better what is happening. Thank you very much for taking time to look at it!!!

---

<div class="post-metadata">

**Author:** ![cathalmccabe](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/cathalmccabe/32/3348_2.png) [@cathalmccabe](https://discuss.pynq.io/u/cathalmccabe)\
**Post date:** [November 23, 2020, 9:28am UTC](https://discuss.pynq.io/t/hls-works-but-not-taking-result-in-python/2029/4 "2020-11-23T09:28:27Z")

</div>

You are probably not sending/received the right amount of data through the DMA.  
E.g. if you send 100 samples, and expect to get back 100 samples, but you only get 99, the DMA will still be waiting for the last sample.  
If the DMA is not idle, try reading more data from it and see if you can get it back to IDLE, and it might give you a better idea about what the problem may be.

Are you setting TLAST in your HLS design? This will signal the end of a packet.

Cathal

---

<div class="post-metadata">

**Author:** ![Kwstis](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/kwstis/32/779_2.png) [@Kwstis](https://discuss.pynq.io/u/Kwstis)\
**Post date:** [November 23, 2020, 5:30pm UTC](https://discuss.pynq.io/t/hls-works-but-not-taking-result-in-python/2029/5 "2020-11-23T17:30:27Z")

</div>

Despite setting Tlast siganl in my HLS for some reason you are right and DMA don’t stop . I tried to change my logic so i send one thing at time and receive one output. Both simulation and co-simulation shows correct output but in python i take something else. **Can someone explain how to use ILA with pynq** (I have not use it until now) cause i cannot think of another way to debug it?  
Thanks very much !

---

<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:** [November 24, 2020, 8:21am UTC](https://discuss.pynq.io/t/hls-works-but-not-taking-result-in-python/2029/6 "2020-11-24T08:21:47Z")

</div>

System ILA is independent from pynq. You need to generate your overlay with the ILA, download the overlay to the board from pynq and connect to the ILA from Vivado.

---

<div class="post-metadata">

**Author:** ![Kwstis](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/kwstis/32/779_2.png) [@Kwstis](https://discuss.pynq.io/u/Kwstis)\
**Post date:** [November 24, 2020, 11:52am UTC](https://discuss.pynq.io/t/hls-works-but-not-taking-result-in-python/2029/7 "2020-11-24T11:52:21Z")

</div>

I 'll try to use ILA then thanks. Although i think that my problem is that i concat bytes from python lets say buf = va1+var2+var3 until buf is 64 byte. Inside my HLS code i take this ap\_uint\<512\> and do things like  
x1=buf.range(256,0) etc but i don’t think that bit goes there as i send them from python.(meaning if var3 is 32byte then does this will go to x1 in HLS code or the bits are not transferred in this order?

---

<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:** [November 24, 2020, 12:30pm UTC](https://discuss.pynq.io/t/hls-works-but-not-taking-result-in-python/2029/8 "2020-11-24T12:30:44Z")

</div>

You can try creating an array of 32-bit elements instead

`input_buffer = allocate(shape=(16,), dtype='np.int32')`

---

<div class="post-metadata">

**Author:** ![Kwstis](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/kwstis/32/779_2.png) [@Kwstis](https://discuss.pynq.io/u/Kwstis)\
**Post date:** [November 24, 2020, 1:40pm UTC](https://discuss.pynq.io/t/hls-works-but-not-taking-result-in-python/2029/9 "2020-11-24T13:40:59Z")

</div>

unfortunately same thing occur. I tried ILA but could not make it work. Can i run my software from jupyter either terminal or not and see the results with open hardware manager and wait for trigger or i have too insert something more at my python code?

---

<div class="post-metadata">

**Author:** ![cathalmccabe](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/cathalmccabe/32/3348_2.png) [@cathalmccabe](https://discuss.pynq.io/u/cathalmccabe)\
**Post date:** [November 24, 2020, 2:24pm UTC](https://discuss.pynq.io/t/hls-works-but-not-taking-result-in-python/2029/10 "2020-11-24T14:24:01Z")

</div>

The ILA will operate independently of your Python code.  
Make sure you download the correct bitstream, and don’t overwrite it from Python using the Overlay() class. (or if you are loading it from Python, make sure it is the new one with ILA).  
Once the design is running, open HW manager, and setup your trigger.  
Then run your Python code. The Python code needs to do something which makes your trigger condition happen.  
Once the ILA sees the trigger it will capture.

Cathal

---

<div class="post-metadata">

**Author:** ![Kwstis](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/kwstis/32/779_2.png) [@Kwstis](https://discuss.pynq.io/u/Kwstis)\
**Post date:** [November 24, 2020, 2:34pm UTC](https://discuss.pynq.io/t/hls-works-but-not-taking-result-in-python/2029/11 "2020-11-24T14:34:18Z")

</div>

I wiil try again more carefully. I really appreciate your time and thanks for every answer until now. Although I am a bit closer to the answer as something is happening on how the data are read and write(like big/little endian from DMA to my ip).  
My mind has really stack. I have this if i put as input to my HLS code x then we will have y. If we put x’ where x’ is x in little-endian we will have y’.  
Now from python i send x and receive z where z’ is the same with y’. What don’t I understand?

---

<div class="post-metadata">

**Author:** ![Kwstis](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/kwstis/32/779_2.png) [@Kwstis](https://discuss.pynq.io/u/Kwstis)\
**Post date:** [November 26, 2020, 2:54pm UTC](https://discuss.pynq.io/t/hls-works-but-not-taking-result-in-python/2029/12 "2020-11-26T14:54:01Z")

</div>

I found that when i am sending  
x = b’\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\xbc`t\xbc\xf1\xcf\x8e\t\xda\xb8G\x85\xde\x0cy\xab\xb1\xfdw\x94dd\xf7\xe2T\x05\xfb\xcf\xc95l|' and in mh HLS i am doing x = x+1 for 6 times i take back in python this y = b'\x06\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\xbc`t\xbc\xf1\xcf\x8e\t\xda\xb8G\x85\xde\x0cy\xab\xb1\xfdw\x94dd\xf7\xe2T\x05\xfb\xcf\xc95l|’  
.That’s why my initial code does not work. But how can i resolve this???  
Also i tried reverse at the beggining and at the end of my hls but i got  
b’\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\xbc`t\xbc\xf1\xcf\x8e\t\xda\xb8G\x85\xde\x0cy\xab\xb1\xfdw\x94dd\xf7\xe2T\x05\xfb\xcf\xc95l" ’ which again is not what we want.

---

<div class="post-metadata">

**Author:** ![Kwstis](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/kwstis/32/779_2.png) [@Kwstis](https://discuss.pynq.io/u/Kwstis)\
**Post date:** [November 27, 2020, 2:31pm UTC](https://discuss.pynq.io/t/hls-works-but-not-taking-result-in-python/2029/13 "2020-11-27T14:31:05Z")

</div>

Finally i found that my IP in HLS takes what i send in little endian and also send me back in little endian. So if i want to take correct results from python i have to do  
‘’’  
buffi = initial+endoffset+startoffset+nonce+key  
bufnew = (int.from\_bytes(buffi,“little”)).to\_bytes(64,“big”)

input\_buffer = allocate(shape=(1,), dtype=‘S64’)  
output\_buffer = allocate(shape=(endoff+1,), dtype=‘S64’)  
input\_buffer[:] = np.array(bufnew)  
dma.sendchannel.transfer(input\_buffer)  
dma.recvchannel.transfer(output\_buffer)  
dma.sendchannel.wait()  
dma.recvchannel.wait()

result.extend(list(output\_buffer.copy()))  
bufnew = list()  
for i in result:  
bufnew.append((int.from\_bytes(i,“little”)).to\_bytes(64,“big”))

print(bufnew)  
‘’’  
Is it due to the ARM cores/due to the AXI4 protocol i don’t know. Also recently i upgrade my version from 2.5 to 2.6 but from terminal. May something changed when i upgraded???

---

<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:** [November 27, 2020, 2:46pm UTC](https://discuss.pynq.io/t/hls-works-but-not-taking-result-in-python/2029/14 "2020-11-27T14:46:37Z")

</div>

> Is it due to the ARM cores/due to the AXI4 protocol i don’t know. Also recently i upgrade my version from 2.5 to 2.6 but from terminal. May something changed when i upgraded???

The ARM architecture is little endian. Therefore, DMA moves the data using little endian.
