# AttributeError: Could not find IP or hierarchy fir\_filter in overlay

**URL:** <https://discuss.pynq.io/t/attributeerror-could-not-find-ip-or-hierarchy-fir-filter-in-overlay/2497>\
**Category:** Support\
**Created:** [April 1, 2021, 7:59am UTC](https://discuss.pynq.io/t/attributeerror-could-not-find-ip-or-hierarchy-fir-filter-in-overlay/2497 "2021-04-01T07:59:40Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![VLHS](https://avatars.discourse-cdn.com/v4/letter/v/c67d28/32.png) [@VLHS](https://discuss.pynq.io/u/VLHS)\
**Post date:** [April 1, 2021, 7:59am UTC](https://discuss.pynq.io/t/attributeerror-could-not-find-ip-or-hierarchy-fir-filter-in-overlay/2497/1 "2021-04-01T07:59:40Z")

</div>

Hi,

I am new to PYNQ environment and trying out this online example using PYNQ-Z2 board  
[How to accelerate a Python function with PYNQ - FPGA Developer](https://www.fpgadeveloper.com/2018/03/how-to-accelerate-a-python-function-with-pynq.html/)  
Except for folder and design names, I have followed the tutorial closely and below is my overlay diagram and notebook. I have placed the .tcl, .bit and .hwh files in the overlay folder.  
[FIR\_Accel.pdf](https://discuss.pynq.io/uploads/short-url/gVoxgOonsHrqxFnzjtlC3nZ9oZB.pdf) (80.3 KB)  
[FIR\_Acceleration.ipynb](https://discuss.pynq.io/uploads/short-url/7fhqz2tZuRT5ggLCNXmMRZeQxRo.ipynb) (434.2 KB)

I am able to run the codes until the part where it tries to address the FIR filter and got the error below:

 ![image](https://us1.discourse-cdn.com/flex019/uploads/pynq1/original/2X/b/bdc9b05bcdd7d7db14b4c82c38dbea50832b90df.png)

On trying to debug the issue, I noticed there is no “fir\_filter” in the block design and I don’t understand why the tutorial is able to run this line without issue. I tried changing it to overlay.filter.fir but still getting the error.

Can someone kindly point to me where I might have done wrong?

---

<div class="post-metadata">

**Author:** ![marioruiz](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/marioruiz/32/2177_2.png) [@marioruiz](https://discuss.pynq.io/u/marioruiz)\
**Post date:** [April 1, 2021, 8:30am UTC](https://discuss.pynq.io/t/attributeerror-could-not-find-ip-or-hierarchy-fir-filter-in-overlay/2497/2 "2021-04-01T08:30:01Z")

</div>

Hi @VLHS,

You are missing the custom driver that is being created to handle the FIR. `.fir_filter` does not refer to an IP, but rather is a method of the FirDriver class. This is cell 8 in the notebook.

Mario

---

<div class="post-metadata">

**Author:** ![VLHS](https://avatars.discourse-cdn.com/v4/letter/v/c67d28/32.png) [@VLHS](https://discuss.pynq.io/u/VLHS)\
**Post date:** [April 1, 2021, 9:37am UTC](https://discuss.pynq.io/t/attributeerror-could-not-find-ip-or-hierarchy-fir-filter-in-overlay/2497/4 "2021-04-01T09:37:34Z")

</div>

Hi Mario,

Thank you for pointing out my misunderstanding bur I will like to seek further clarity. I ran cell 8 so shouldn’t the function “fir\_filter” be recognized by my environment? Or am I missing some file on my PYNQ board? In the usual Python sense, I should invoke it using FirDriver.fir\_filter isn’t it?

---

<div class="post-metadata">

**Author:** ![marioruiz](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/marioruiz/32/2177_2.png) [@marioruiz](https://discuss.pynq.io/u/marioruiz)\
**Post date:** [April 1, 2021, 10:37am UTC](https://discuss.pynq.io/t/attributeerror-could-not-find-ip-or-hierarchy-fir-filter-in-overlay/2497/5 "2021-04-01T10:37:35Z")

</div>

You need to run cell 8 before using the Overlay class. Have you done that?

When you call Overlay, pynq assigns defaultHierarchy by default unless there is a class that inherits from defaultHierarchy in the environment. In such case, pynq will assign the corresponding class

---

<div class="post-metadata">

**Author:** ![VLHS](https://avatars.discourse-cdn.com/v4/letter/v/c67d28/32.png) [@VLHS](https://discuss.pynq.io/u/VLHS)\
**Post date:** [April 1, 2021, 11:12am UTC](https://discuss.pynq.io/t/attributeerror-could-not-find-ip-or-hierarchy-fir-filter-in-overlay/2497/6 "2021-04-01T11:12:57Z")

</div>

Yes, I ran cell 8. The call to overlay.filter.fir\_filter in my original post is in cell 9. After running cell 9 with error, I did a print out of the overlay details and copped out the following:

 ![image](https://us1.discourse-cdn.com/flex019/uploads/pynq1/original/2X/d/da6af957c110e76350f43c0f05ee7f0c548c2f4b.png)  
Am I supposed to see pynq.overlay.FirDriver instead of pynq.overlay.DefaultHierarchy?

---

<div class="post-metadata">

**Author:** ![marioruiz](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/marioruiz/32/2177_2.png) [@marioruiz](https://discuss.pynq.io/u/marioruiz)\
**Post date:** [April 1, 2021, 7:39pm UTC](https://discuss.pynq.io/t/attributeerror-could-not-find-ip-or-hierarchy-fir-filter-in-overlay/2497/7 "2021-04-01T19:39:23Z")

</div>

@VLHS,

The tutorial was create with an older version of pynq. In the latest version, the `fir` is not part of the `.ip_dict`, so the hierarchy class needs updating. Note, that I also update to `allocate`, Xlnk is deprecated.

```python
from pynq import DefaultHierarchy
from pynq import allocate

class FirDriver(DefaultHierarchy):
    def __init__ (self, description):
        super(). __init__ (description)
        
    def fir_filter(self, data):
         with allocate(shape=(len(data),), dtype=np.int32) as in_buffer,\
              allocate(shape=(len(data),), dtype=np.int32) as out_buffer:
             np.copyto(in_buffer,data)
             self.fir_dma.sendchannel.transfer(in_buffer)
             self.fir_dma.recvchannel.transfer(out_buffer)
             self.fir_dma.sendchannel.wait()
             self.fir_dma.recvchannel.wait()
             result = out_buffer.copy()
         return result
    
    # use @staticmethod... Can't change class state, just as a utility function
    # remove check for FIR in the desc because somehow it's not there.
    @staticmethod
    def checkhierarchy(description):
        if 'fir_dma' in description['ip']:
            return True
        else:
            return False

```

I checked, and it is working for me.

```auto
Hierarchies
-----------
filter : __main__.FirDriver

```

Mario

---

<div class="post-metadata">

**Author:** ![VLHS](https://avatars.discourse-cdn.com/v4/letter/v/c67d28/32.png) [@VLHS](https://discuss.pynq.io/u/VLHS)\
**Post date:** [April 2, 2021, 6:16am UTC](https://discuss.pynq.io/t/attributeerror-could-not-find-ip-or-hierarchy-fir-filter-in-overlay/2497/8 "2021-04-02T06:16:01Z")

</div>

I am able to overcome the issue with your inputs and obtain the output as you have shown. However, my issue persists with my environment complaining of ‘PynqBuffer’ object has no attribute ‘free\_buffer’ on exiting the driver call when the function **exit** was invoked.

 ![image](https://us1.discourse-cdn.com/flex019/uploads/pynq1/original/2X/4/468f3f18e3af99ae4b2e55f05e86bfbfefade8d5.png)

---

<div class="post-metadata">

**Author:** ![marioruiz](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/marioruiz/32/2177_2.png) [@marioruiz](https://discuss.pynq.io/u/marioruiz)\
**Post date:** [April 2, 2021, 8:11am UTC](https://discuss.pynq.io/t/attributeerror-could-not-find-ip-or-hierarchy-fir-filter-in-overlay/2497/9 "2021-04-02T08:11:52Z")

</div>

What `pynq` version are you using? If you go back to Xlnk, does this happen?

---

<div class="post-metadata">

**Author:** ![VLHS](https://avatars.discourse-cdn.com/v4/letter/v/c67d28/32.png) [@VLHS](https://discuss.pynq.io/u/VLHS)\
**Post date:** [April 2, 2021, 12:49pm UTC](https://discuss.pynq.io/t/attributeerror-could-not-find-ip-or-hierarchy-fir-filter-in-overlay/2497/10 "2021-04-02T12:49:21Z")

</div>

The PYNQ version I am using is Release 2019\_10\_03. When I reverted the two “allocate” call to “xlnk.cma\_array”, I am still getting no free\_buffer attribute error.

---

<div class="post-metadata">

**Author:** ![marioruiz](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/marioruiz/32/2177_2.png) [@marioruiz](https://discuss.pynq.io/u/marioruiz)\
**Post date:** [April 2, 2021, 1:20pm UTC](https://discuss.pynq.io/t/attributeerror-could-not-find-ip-or-hierarchy-fir-filter-in-overlay/2497/11 "2021-04-02T13:20:48Z")

</div>

Please install download the latest sdcard (2.6.0) image and try with that version, [http://www.pynq.io/board.html](http://www.pynq.io/board.html)

Mario

![image001.jpg](https://us1.discourse-cdn.com/flex019/uploads/pynq1/original/1X/2485d26919316b1d80aa60f5ca8e2cb5bc0275fe.jpeg)

---

<div class="post-metadata">

**Author:** ![VLHS](https://avatars.discourse-cdn.com/v4/letter/v/c67d28/32.png) [@VLHS](https://discuss.pynq.io/u/VLHS)\
**Post date:** [April 4, 2021, 12:50pm UTC](https://discuss.pynq.io/t/attributeerror-could-not-find-ip-or-hierarchy-fir-filter-in-overlay/2497/12 "2021-04-04T12:50:17Z")

</div>

I refreshed my image to PYNQ 2.6.0 and now able to run the code successfully on my PYNQ-Z2. Thank you for guiding me to resolve my issue.

---

<div class="post-metadata">

**Author:** ![jcollier](https://avatars.discourse-cdn.com/v4/letter/j/9dc877/32.png) [@jcollier](https://discuss.pynq.io/u/jcollier)\
**Post date:** [January 26, 2022, 4:53pm UTC](https://discuss.pynq.io/t/attributeerror-could-not-find-ip-or-hierarchy-fir-filter-in-overlay/2497/13 "2022-01-26T16:53:52Z")

</div>

Thanks much. This works in PYNQ 2.7 also.

John

---

<div class="post-metadata">

**Author:** ![jcollier](https://avatars.discourse-cdn.com/v4/letter/j/9dc877/32.png) [@jcollier](https://discuss.pynq.io/u/jcollier)\
**Post date:** [January 26, 2022, 5:01pm UTC](https://discuss.pynq.io/t/attributeerror-could-not-find-ip-or-hierarchy-fir-filter-in-overlay/2497/14 "2022-01-26T17:01:48Z")

</div>

On my ZCU104, I get the following times:  
Software FIR execution time: 0.0432887077331543  
Hardware FIR execution time: 0.003331422805786133  
Hardware FIR execution time (with driver): 0.07016849517822266

So using the the driver slows it down to much slower than just doing it in the CPU. Is this expected or does anyone have suggestions on how to optimize the driver code?

I am new to this and will update if I figure something out.

Thanks,  
John

---

<div class="post-metadata">

**Author:** ![jcollier](https://avatars.discourse-cdn.com/v4/letter/j/9dc877/32.png) [@jcollier](https://discuss.pynq.io/u/jcollier)\
**Post date:** [January 26, 2022, 5:09pm UTC](https://discuss.pynq.io/t/attributeerror-could-not-find-ip-or-hierarchy-fir-filter-in-overlay/2497/15 "2022-01-26T17:09:00Z")

</div>

Answering my own question - Comparing apples to oranges.

The Hardware FIR execution time doesn’t include buffer allocation or the numpy copy while the Hardware FIR execution time (with driver) does.

John

---

<div class="post-metadata">

**Author:** ![Ghani](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/ghani/32/2540_2.png) [@Ghani](https://discuss.pynq.io/u/Ghani)\
**Post date:** [February 9, 2022, 11:12am UTC](https://discuss.pynq.io/t/attributeerror-could-not-find-ip-or-hierarchy-fir-filter-in-overlay/2497/16 "2022-02-09T11:12:28Z")

</div>

Thank u for the insights John  
[Abdelghani](https://www.linkedin.com/in/abdelghani-bourenane-67475516b/)

---

<div class="post-metadata">

**Author:** ![Matthew\_Arnold](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/matthew_arnold/32/5770_2.png) [@Matthew\_Arnold](https://discuss.pynq.io/u/Matthew_Arnold)\
**Post date:** [March 27, 2024, 6:22am UTC](https://discuss.pynq.io/t/attributeerror-could-not-find-ip-or-hierarchy-fir-filter-in-overlay/2497/17 "2024-03-27T06:22:47Z")

</div>

As alternative to upgrading to 2.6 as suggested, as a temporary workaround the notebook can be modified. The error is due to a bug in Pynq v2.5, specifically in buffer.py where PynqBuffer calls “free\_buffer” at exit, but the implemented method is actually called “freebuffer”. This is triggered by the use of the with block (regardless of the status of the buffers), so a solution is to make the driver method look more like the code in the earlier cell, just with a result = out\_buffer.copy() instead of plotting.
