Hello! I am working with a block that looks for character matches. I would like to pass a text file through the dma so that it looks for matches, I tried using the data object type np.str but I get the following error, any suggestions? Thank you!
The numpy str
type is a dynamically allocated type and therefore not supported by PYNQ for data transfer. The easiest way to get something you can pass to an accelerator is to create an array of bytes and assign the string to it. Note you may also need to do some unicode encoding if you start with a regular Python string rather than a byte string. You will also need to manually add the null terminator if that’s required by your accelerator
teststring = "Incoming Data"
encoded = teststring.encode()
buf = xlnk.cma_array(shape=(32,), dtype=np.uint8)
buf[0:len(encoded)] = memoryview(encoded)
# Add Null terminator if necessary
buf[len(encoded)] = 0
If your source data is a file it might be worth looking at the numpy mmap functionality which will let you get a numpy array of 8-bit ints directly from a file which you can then copy into your hardware buffer
source_data = np.memmap(file_path, dtype=np.uint8)
input_buffer = xlnk.cma_array(shape=source_data.shape, dtype=source_data.dtype)
input_buffer[:] = source_data
Hopefully this is sufficient to get started with
Peter
It works!!! Thanks a lot!!!
Hi @rsan would you please share the working example for passing text file for PS-PL to DMA and IP?
I also experienced the same error, and I couldn’t figured it out how to passing correctly.
Appreciated, thank you.
@PeterOgden is there any working example for file data transfer with numpy mmap to DMA and IP on Pynq?
I couldn’t resolve with your example:
source_data = np.memmap(file_path, dtype=np.uint8)
input_buffer = xlnk.cma_array(shape=source_data.shape, dtype=source_data.dtype)
input_buffer[:] = source_data
Thank you.
Hey @rsan could you please share with us your whole example?