ImportError: cannot import name 'Xlnk' from 'pynq'

Hi, I am using Pynq- Z2 with image v2.7.
I want to rebuild some projects from pynq community. But, most of them were deployed on older versions where Xlnk was there. But, now I cannot use their codes.
I got to know that now we have allocate() in place of Xlnk.
But, not sure exact syntax. Can anyone help how can I change the older code to get it working now.

e.g.

  • def cleanup(self):
    xlnk = Xlnk()
    xlnk.xlnk_reset()

  • self.library = library
    self.xlnk = Xlnk()
    self.xlnk.set_allocator_library(self.library)

  • def copy_array(self, x, dtype=np.int32):
    “”“Copy numpy array to contiguous memory.
    Parameters
    ----------
    x: np.array
    Input numpy array, not necessarily in contiguous memory.
    dtype : type
    Data type for the give numpy array.
    Returns
    -------
    xlnk.cma_array
    Physically contiguous memory.
    “””
    size = x.shape
    data_buffer = self.xlnk.cma_array(shape=size, dtype=dtype, cacheable=self.cacheable)
    np.copyto(data_buffer, x.astype(dtype), casting=“unsafe”)
    return data_buffer

I have the same issue, but I found that V2.7 has removed Xlnk. The info is from Releases · Xilinx/PYNQ · GitHub

Removed Xlnk allocator and libraries for edge devices (replaced by XRT allocation)
However, I don’t know how to use XRT to replace Xlnk.

Hi, You can find information about how to use allocate in the v2.7 manual:

https://pynq.readthedocs.io/en/v2.7.0/pynq_libraries/allocate.html

Kind regards

There are some Allocate examples here:
https://github.com/Xilinx/PYNQ_Workshop/tree/master/Session_4

Cathal