Repalcement for xlnk.xlnk_reset() in PYNQ v2.7

Hi, I’m updating my program from pynq v2.6.1 to v2.7. But I have a problem.
I use many CMAs in my design, and I call a clean up function to release the whole CMA at startup like this:

def __clean_cma(self):
    xlnk = Xlnk()
    xlnk.xlnk_reset()

It’s just in case the program crashes and I don’t have time to clean it up. Leaked CMA will cause allocate errors at relaunch.
But now Xlnk is removed in v2.7, PynqBuffer.freebuffer() can release CMA but I don’t have any instance to free at startup.

Can someone kindly help me find a way to release leaked CMA?

2 Likes

You can delete the buffers you use:
del buffer

Cathal

Is there a way to delete all the buffers generally without calling del on each buffer used?

I meet the same problem with you.
Have you sloved it?

Hi,

There is no direct replacement for this since pynq 2.7.

You may have to restructure your code to del the buffer after finishing your application, this is the pythonic way.

Mario

1 Like

(post deleted by author)

Thank you very much.

But sorry I haven’t found a python function to free buffer. Could you give me an example?

My memory reduced even after del buffer .

I don’t know why and now I have to use the Linux command echo 1 > /proc/sys/vm/drop_caches on the terminal to free buffer , but it’s not useful all the time.

I have no idea what allocate have done to my ram.It becomes confusing when python plus fpga.

Hi
Thank you ! I solved it !! del needs to company with gc.collect()

import gc

params_w = np.fromfile("yolo.bin", dtype=np.uint32) 
np.copyto(weight_buffer, params_w)

del params_w
gc.collect()
2 Likes

The complete code is as follows

inport allocate  # replace Xlnk
import gc

weight_buffer = allocate(shape=(25470896,), dtype=np.uint32)  # allocate 100M memory
params_w = np.fromfile("yolo.bin", dtype=np.uint32)      # read the file
np.copyto(weight_buffer, params_w)        # load the file to the 100M memory

del params_w        # will not be used again, so delete it to free memory
gc.collect()
4 Likes