Upload numpy array on pynq dram

  • board : pynq z1

I have a file “input.npy” which have size of 100x100, and type of np.float32.

this file can be uploaded on dram using buffer write like below.

input_file = np.load('input.npy')
input_dram = allocate(shape=(100, 100), dtype=np.float32)
for i in range(100):
   for j in range(100):
      input_dram[i][j] = input_file[i][j]

However, this way takes a lot of time if data size gets bigger.

I must use attribute “physical_address” in pynq.buffer.

These two ways delete “physical_address” of “input_dram” when executed.

# way 1
input_dram = allocate(shape=(100, 100), dtype=np.float32)
input_dram = np.load('input.npy')
# way 2
input_file = np.load('input.npy')
input_dram = allocate(shape=(100, 100), dtype=np.float32)
input_dram = input_file.copy()

When printing physical address, the error message said AttributeError: ‘numpy.ndarray’ object has no attribute ‘physical_address’

Is there another way directly upload numpy file on pynq dram?

Hi @fkj1196,

It takes a lot of time because you are coping element by element.

Code snipped below will overwrite the whole input_dram array, so avoid doing this (this is why you get the attribute error)

input_dram = input_file.copy()

You can simply do:

input_dram[:] = input_file

This will copy your input_file object contents to the allocated array.

Mario

2 Likes

This works very fast.

Appreciate for your answer.

1 Like