Xilinx / Alveo-PYNQ

Introductory examples for using PYNQ with Alveo
Apache License 2.0
48 stars 17 forks source link

"No active memories in design" error when using Pynq.allocate #13

Closed shashank-agg closed 4 years ago

shashank-agg commented 4 years ago

This is more of a documentation issue than a real 'bug'.

Server: CentOS with two devices: xilinx_u280_xdma_201920_1 xilinx_u200_xdma_201830_2

I am trying to run the vector-addition example on the u200 Minimal reproducible example:

import pynq
import numpy as np

from pynq import Device
ol = pynq.Overlay("intro.xclbin", device=Device.devices[-1])
vadd = ol.vadd_1

# allocate buffers
size = 1024*1024
in1_vadd = pynq.allocate((1024, 1024), np.uint32)

This fails with the error:

RuntimeError                              Traceback (most recent call last)
<ipython-input-5-4da1205c7768> in <module>
     13 # allocate buffers
     14 size = 1024*1024
---> 15 in1_vadd = pynq.allocate((1024, 1024), np.uint32)
     16 # in2_vadd = pynq.allocate((1024, 1024), np.uint32)
     17 # out = pynq.allocate((1024, 1024), np.uint32)

~/pythonvirtualenv/pynq/lib64/python3.6/site-packages/pynq/buffer.py in allocate(shape, dtype, target, **kwargs)
    168     if target is None:
    169         target = Device.active_device
--> 170     return target.allocate(shape, dtype, **kwargs)

~/pythonvirtualenv/pynq/lib64/python3.6/site-packages/pynq/pl_server/device.py in allocate(self, shape, dtype, **kwargs)
    291 
    292         """
--> 293         return self.default_memory.allocate(shape, dtype, **kwargs)
    294 
    295     def reset(self, parser=None, timestamp=None, bitfile_name=None):

~/pythonvirtualenv/pynq/lib64/python3.6/site-packages/pynq/pl_server/xrt_device.py in default_memory(self)
    364                        if m['used'] and not m['streaming']]
    365         if len(active_mems) == 0:
--> 366             raise RuntimeError("No active memories in design")
    367         elif len(active_mems) > 1:
    368             raise RuntimeError("Multiple memories active in design: specify" +

RuntimeError: No active memories in design

However, if instead of using the device argument for the overlay method, if I use the following, it works:

Device.active_device = Device.devices[-1]

Im guessing this is because the allocate method still uses the default device. So either allocate should accept the device as an argument, or we should mention this as a gotcha in the multi-device example.

giunatale commented 4 years ago

This is already there and is documented in our example notebooks multiple times. You will have to use the target keyword and pass wich memory you want to use (from the loaded overlay, so it will automatically reference the target device)

buf = pynq.allocate((1024,1024), 'u4', target=ol.bank0)

e.g.: https://github.com/giunatale/Alveo-PYNQ/blob/master/pynq_alveo_examples/notebooks/2_kernel_optimization/3-memories-and-streams.ipynb

Closing.

giunatale commented 4 years ago

Just for reference. Allocate cannot work without the target kw in two use cases:

EDIT: I understand though that the multi-device scenario is left a bit behind int terms of documentation, so I get why you got to this point.

EDIT2: thanks anyways for reporting this out, we should have better erroring for this use case, so it is good you brought it to our attention. Thanks!!

PeterOgden commented 4 years ago

I agree that we need some better documentation on this. pynq.allocate has a target keyword argument which can be set with either a device or a memory bank so the functionality is there it's just not obvious when things go wrong. There are some more subtle issues that might arise as well with multiple card setups we should probably try and catch as well - namely buffers for one card being used with accelerators on another which right now will not error out and seem to work but ultimately lead to undefined behaviour.