PYNQ-Helloworld issue with Allocate function Call

Hello world.

I’m trying to get the example notebook ‘resizer_pl.pynb’ working but I’m having trouble around where the allocate() function call occurs.

For reference, I am using Ubuntu 22.04 on the KR260 with the FW 1.04. I did see that 22.04 should use 1.02 to get DP working, but I don’t think that this is related.

I flashed 22.04 on my SD card and updated it using the instructions here, and then using the install.sh file in the git repo according to the instructions here.

After restarting, I logged into Jupyter notebooks and tried to run the code in the notebook and got the following output, shown below:

resize_factor = 2

new_width = int(old_width/resize_factor)

new_height = int(old_height/resize_factor)

We now allocate memory to process data on PL. Data is provided as contiguous memory blocks. The size of the buffer depends on the size of the input or output data. The image dimensions extracted from the read image are used to allocate contiguous memory blocks.
We will call allocate() to perform the allocation.

in_buffer = allocate(shape=(old_height, old_width, 3), 

                           dtype=np.uint8, cacheable=1)

out_buffer = allocate(shape=(new_height, new_width, 3), 

                            dtype=np.uint8, cacheable=1)

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [7], in <cell line: 1>()
----> 1 in_buffer = allocate(shape=(old_height, old_width, 3), 
      2                            dtype=np.uint8, cacheable=1)
      3 out_buffer = allocate(shape=(new_height, new_width, 3), 
      4                             dtype=np.uint8, cacheable=1)

File /usr/local/share/pynq-venv/lib/python3.10/site-packages/pynq/buffer.py:158, in allocate(shape, dtype, target, **kwargs)
    156 if target is None:
    157     target = Device.active_device
--> 158 return target.allocate(shape, dtype, **kwargs)

File /usr/local/share/pynq-venv/lib/python3.10/site-packages/pynq/pl_server/device.py:145, in Device.allocate(self, shape, dtype, **kwargs)
    127 def allocate(self, shape, dtype, **kwargs):
    128     """Allocate an array on the device
    129 
    130     Returns a buffer on memory accessible to the device
   (...)
    143 
    144     """
--> 145     return self.default_memory.allocate(shape, dtype, **kwargs)

File /usr/local/share/pynq-venv/lib/python3.10/site-packages/pynq/pl_server/xrt_device.py:156, in XrtMemory.allocate(self, shape, dtype, **kwargs)
    145 def allocate(self, shape, dtype, **kwargs):
    146     """Create a new  buffer in the memory bank
    147 
    148     Parameters
   (...)
    154 
    155     """
--> 156     buf = _xrt_allocate(shape, dtype, self.device, self.idx, **kwargs)
    157     buf.memory = self
    158     return buf

File /usr/local/share/pynq-venv/lib/python3.10/site-packages/pynq/pl_server/xrt_device.py:107, in _xrt_allocate(shape, dtype, device, memidx, cacheable, pointer, cache)
    105     buf = device.map_bo(bo)
    106     device_address = device.get_device_address(bo)
--> 107 ar = PynqBuffer(
    108     shape,
    109     dtype,
    110     bo=bo,
    111     device=device,
    112     buffer=buf,
    113     device_address=device_address,
    114     coherent=False,
    115 )
    116 if pointer is not None:
    117     weakref.finalize(buf, _free_bo, device, bo, ar.virtual_address, ar.nbytes)

File /usr/local/share/pynq-venv/lib/python3.10/site-packages/pynq/buffer.py:45, in PynqBuffer.__new__(cls, device, device_address, bo, coherent, *args, **kwargs)
     43 self.coherent = coherent
     44 self.bo = bo
---> 45 self.device = device
     46 self.offset = 0
     47 self.freed = False

AttributeError: attribute 'device' of 'numpy.ndarray' objects is not writable

All of this was after trying to follow the instructions perfectly the second time around; The first time I got the same output but thought that I may have modified something accidentally when I was trying to get something else unrelated to work.

I don’t know if it helps, but I did also notice that the scripts appear to install and uninstall different versions of numpy.

Thanks in advance for your help.

Hi @Mark_Ivey,

Welcome to the PYNQ community.

What is the numpy version that is installed on that environment? If it is 2 or newer, can you please force a reinstallation of numpy older than 2.0? For this, run the following command inside a terminal within JupyterLab.

python3 pip install --force-reinstall "numpy<2"

Mario

Thanks for the fast reply!.
I had numpy 2.26 installed. I guess like i said earlier I saw this jump from 1.xx to 2.xx and back a couple of times when it was installing.

I will note that I got the following error after forcing 1.xx to install:

Installing collected packages: numpy
  Attempting uninstall: numpy
    Found existing installation: numpy 2.2.6
    Uninstalling numpy-2.2.6:
      Successfully uninstalled numpy-2.2.6
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
opencv-python 4.12.0.88 requires numpy<2.3.0,>=2; python_version >= "3.9", but you have numpy 1.26.4 which is incompatible.
Successfully installed numpy-1.26.4

I didn’t see any issues from this when I ran the example, but I thought I’d post it here as a possible root cause for why numpy was upgraded to 2.26 despite apparent efforts in the scripts to use 1.xx.

Putting this into the google chatbot, it recommended:

pip install opencv-python==4.5.5.64

Do you agree w/ that?
Thanks again for the help.

1 Like

Can you open an issue on the repo so we can check this in details?

1 Like

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