Example Design Methodology Const Multiply DMA not working

Dear @PeterOgden

I’ve tried to follow your tutorial on:

Overlay Tutorial — Python productivity for Zynq (Pynq)

and

GitHub - PeterOgden/overlay_tutorial: Premade bitstreams and block designs to complemented the PYNQ overlay tutorial

but it seems that DMA is passing 0 values to IP

from pynq import allocate
import numpy as np

in_buffer = allocate(shape=(5,), dtype=np.uint32)
out_buffer = allocate(shape=(5,), dtype=np.uint32)

for i in range(5):
    in_buffer[i] = i

multiply.constant = 3
dma.sendchannel.transfer(in_buffer)
dma.recvchannel.transfer(out_buffer)
dma.sendchannel.wait()
dma.recvchannel.wait()

out_buffer

result:

PynqBuffer([0, 0, 0, 0, 0], dtype=uint32)

It is the same when I run driver:
from pynq import DefaultHierarchy

class StreamMultiplyDriver(DefaultHierarchy):
    def __init__(self, description):
        super().__init__(description)

def stream_multiply(self, stream, constant):
    self.multiply.constant = constant
    with allocate(shape=(len(stream),), \
                  dtype=np.uint32) as in_buffer,\
         allocate(shape=(len(stream),), \
                  dtype=np.uint32) as out_buffer:
        for i, v, in enumerate(stream):
            in_buffer[i] = v
        self.multiply_dma.sendchannel.transfer(in_buffer)
        self.multiply_dma.recvchannel.transfer(out_buffer)
        self.multiply_dma.sendchannel.wait()
        self.multiply_dma.recvchannel.wait()
        result = out_buffer.copy()
    return result

@staticmethod
def checkhierarchy(description):
    if 'multiply_dma' in description['ip'] \
       and 'multiply' in description['ip']:
        return True
    return False

overlay.const_multiply.stream_multiply([1,2,3,4,5], 5)
result:
PynqBuffer([0, 0, 0, 0, 0], dtype=uint32)

Another issue, when running:

class TestOverlay(Overlay):
    def __init__(self, bitfile, **kwargs):
        super().__init__(bitfile, **kwargs)

    def multiply(self, stream, constant):
        return self.const_multiply.stream_multiply(stream, constant)

next

overlay = TestOverlay('tutorial_2.bit')
overlay.multiply([2,3,4,5,6], 4)

it generates error:

    ---------------------------------------------------------------------------
    AttributeError                            Traceback (most recent call last)
    <ipython-input-30-16d1ba4263de> in stream_multiply(self, stream, constant)
         14             self.multiply_dma.recvchannel.wait()
    ---> 15             result = out_buffer.copy()
         16         return result

/usr/local/lib/python3.6/dist-packages/pynq/buffer.py in __exit__(self, exc_type, exc_value, traceback)
    126     def __exit__(self, exc_type, exc_value, traceback):
--> 127         self.freebuffer()
    128         return 0

AttributeError: 'PynqBuffer' object has no attribute 'free_buffer'

During handling of the above exception, another exception occurred:

AttributeError                            Traceback (most recent call last)
<ipython-input-35-694e2ce2dfe4> in <module>()
      1 overlay = TestOverlay('tutorial_3.bit')
----> 2 overlay.multiply([2,3,4,5,6], 4)

<ipython-input-34-c467dd7f5306> in multiply(self, stream, constant)
      4 
      5     def multiply(self, stream, constant):
----> 6         return self.const_multiply.stream_multiply(stream, constant)

<ipython-input-30-16d1ba4263de> in stream_multiply(self, stream, constant)
     13             self.multiply_dma.sendchannel.wait()
     14             self.multiply_dma.recvchannel.wait()
---> 15             result = out_buffer.copy()
     16         return result
     17 

/usr/local/lib/python3.6/dist-packages/pynq/buffer.py in __exit__(self, exc_type, exc_value, traceback)
    125 
    126     def __exit__(self, exc_type, exc_value, traceback):
--> 127         self.freebuffer()
    128         return 0
    129 

AttributeError: 'PynqBuffer' object has no attribute 'free_buffer'

Some suggest to modify

pynq/buffer.py

then

change self.free_buffer() to self.freebuffer()

Any idea?

Thanks

Hendar

The free_buffer is a know issue that will be fixed in an upcoming release - the suggested fix is correct but that’s unrelated to the rest of the issues.

Are you running the hotebook directly or have you copied the code from the documentation into a new document? I’d try copying the above file directly into your notebooks folder and executing it without modification. That’s how I test that the designs are working.

Peter

Thanks @PeterOgden for your answer, really appreciate it. I think so, it is unrelated, because even after I change it it has the same error.

I made 2 projects from the tutorial : 1. just copying directly into notebook folder and running without modification. 2. I made modification for board and vivado version.

I used vivado 2019.2 and Pynq Z2.
Is it because you’ve made it for Pynq Z1 (which result in error for Z2 even though both has xc7z020clg400-1 type)?

Thanks

Hendar