How to use the DMA

[admin edit: moved to new post]

Thank you so much. I included the .hwh file, and now I am able to load the overlay properly. However, I am having trouble figuring out how to read/write to the FPGA memory and perform the vector addition. I have tried the following Python code which I have modified from the code in this discussion board; however, the code gets stuck in the while loop and never completes.

import numpy as np 
vec_x = np.array([1, 2, 3, 4, 5, 6, 7, 8])
vec_y = np.array([10, 10, 10, 10, 10, 10, 10, 10])
vec_z = np.array([0, 0, 0, 0, 0, 0, 0, 0])

from pynq import Overlay
# Load the overlay
overlay = Overlay('/home/xilinx/pynq/overlays/vector_add/vecAdder.bit')
# IP alias
vecAdd=overlay.vector_add 

# Allocate contiguous buffer for memory transfer
x_buffer = allocate(shape=(N,), dtype=np.int)
y_buffer = allocate(shape=(N,), dtype=np.int)
z_buffer = allocate(shape=(N,), dtype=np.int)
# Copy the DNA string to the in_buffer
np.copyto(x_buffer,vec_x)
np.copyto(y_buffer,vec_y)
np.copyto(z_buffer,vec_z)

# initialize AXI with address and length, 
vecAdd.write(0x10,z_buffer.physical_address)  # vector Z is AXI so need to initialize address
vecAdd.write(0x18,y_buffer.physical_address)  # vector Y is AXI so need to initialize address
vecAdd.write(0x20,x_buffer.physical_address)  # vector X is AXI so need to initialize address
vecAdd.write(0x28,N)                          # initialize N
vecAdd.write(0x00,0x01) # start

while vecAdd.read(0x00 & 0x4)!= 0x04:
    pass

vecAdd.write(0x00,0x00) # stop   
np.copyto(vec_z, z_buffer)

Should I be using DMA to do the reading/writing? Like I mentioned previously. This all is very new to me and I am trying to learn as much as I can. Any advice on how to fix this would be greatly appreciated! Thanks!

1 Like

Hi,

If you mark a reply as solution, please open a new post for future questions. The second question is not related to the first one, hence it will not help other people.

There are detailed tutorials on the use of DMA and DMA + HLS IP. I suggest you have a look, these should answer your questions.

Mario

2 Likes