Pynq & maximum allocatable memory (CMA)

Hello,

I have some limitations when using a DMA on a ZCU111. I can’t allocate all the memory I need in my buffers when I use “allocate” function.
After some research, I find this : " This buffer is allocated inside the kernel space using xlnk driver. The maximum allocatable memory is defined at kernel build time using the CMA memory parameters. For Pynq-Z1 kernel, it is specified as 128MB. " (pynq.xlnk — Python productivity for Zynq (Pynq) v1.0).

I think it is necessary to configure the Linux Kernel : Failed to allocate Memory when i use the fuction 'cma_alloc'
But I have no more information.

Someone can help me ?

Thanks :slight_smile:

Damien

1 Like

I forgot to specify : I try to build a new image (PYNQ SD Card — Python productivity for Zynq (Pynq)), but I don’t find any parameters to modify to increase this maximum allocatable memory.

Thanks :slight_smile:

Damien

1 Like

Check under Petalinux Kernel Config. There was a tutorial here a while ago by Peter showing how to port to a new board. If I recall correctly is under the same settings as DMA APF.

Device Drivers->Generic Driver Options->Size in Mega Bytes(1024)
Device Drivers->Staging drivers (ON)->Xilinx APF Accelerator driver (ON)->Xilinx APF DMA engines support (ON)

Hi :slight_smile:
Thank you so much for your answers

You’re talking about this guide : Deploying PYNQ and Jupyter with Petalinux ?

Damien

Yep, that’s it.

Hello again.

I’m testing the guide, and it’s probably going to work.
Nevertheless, I lost the current configuration of ZCU111 v2.5, myrootfs… :frowning:

Do you know if I can:

  • just copy the new build kernel to my ZCU111 SD card?
  • or maybe just specify the kernel option when I use this guide: PYNQ SD Card — Python productivity for Zynq (Pynq) ? Because I can’t configure the kernel with it (or I don’t know how to do this)
  • maybe something else?

Thank you very much, again

Damien

Hello,

I found a “temporary” solution. You need to follow this guide : PYNQ SD Card — Python productivity for Zynq (Pynq) and launch the kernel compilation. In an other terminal look for kernel configuration file and stop the compilation. Edit the file and start again the compilation.
WHen It’s finish you can copy the kernel file in your sd card.

It’s not “clean”, but I don’t know how to configure the kernel when you are using Pynq. If someone know, I’m very interested.

Damien

1 Like

After you have the boot_files built (run make boot_files or run make), the petalinux_project folder should appear in your sdbuild/build/ folder, you can go inside and run petalinux-config -c kernel.

I’m having similar issues with the ZC702 board. For once I can’t set CMA to anything higher than 256MB when building petalinux and even when setting CMA to 256MB I still can only allocate 128MB with ‘allocate’.

I’ve used pynq_z1_v2.6.0 to build the SD image and then swapped the BOOT.BIN, boot.scr and image.ub that were built using 2020.1 version of Vitis, petalinux for ZC702 BSP. After enabling Xilinx APF DMA engines under Device Drivers I changed the CMA size to 1024 (ZC702 has 1GB DDR) under Library Routines->Size in Mega Bytes. When built I can see that it fails to reserve CMA of more than 256MB when booting up. Tried 1024MB, 512MB etc and nothing works above 256MB. Am I getting it right that since ZC702 has 4 separate DDR chips, each 256Mx8bit, you cannot reserve more than 256MB for CMA?

Another issue is when kernel has been configured to 256MB of CMA I cannot use more than 128MB when using ‘allocate’.

I’ve tried (~152MB)
buffer = allocate(shape=(40000000,), dtype=np.uint32)

which fails and the max I can allocate is around 33500000 (~128MB i.e. (33500000*4) / 2^20).

When running
mem=Xlnk()
print(mem.cma_mem_size())
print(mem.cma_stats())

I can see
268435456
{‘CMA Memory Available’: 239321088, ‘CMA Memory Usage’: 0, ‘Buffer Count’: 0}

Any suggestions will be much appreciated.

1 Like

I do not have any idea, but your comments shed light on my issue.

Thanks!

I decided to run this down after working on https://discuss.pynq.io/t/how-to-allocate-pl-ddr4-on-rfsoc4x2-in-pynq-3-0-1/5586/8 given that they’re notionally related.

This patch Add hook for EmbeddedDevice XRT devices to allow moving the PSDDR memory region by ld-cd · Pull Request #1424 · Xilinx/PYNQ · GitHub allows you to put the default allocator in a reserved memory region. Alternatively you can add an .xclbin file alongside your bitstream which has both the PSDDR region at 0 and another region pointing to your reserved region and whenever you want to allocate something in your reserved region specify it manually as a target.

4 Likes

Hello,

Thank you for your feedback :slight_smile: