myhdl with cython?
David Belohrad <[email protected]> Tue, 26 Jan 2016 09:13:16 +0100
| Newsgroups | gmane.comp.python.myhdl |
|---|---|
| Message-ID | <[email protected]> |
Dear All,
i've been fiddling with myhdl for about a week or so. I've tried to do some real stuff I do at work using myhdl. As a part of the project involves FIR filtering, I have used the example found on Christopher Felton's page (https://bitbucket.org/cfelton/examples) and hacked away m_firfilt entity using my own coefficients. Now, my filter has 891 taps and I've tried to simulate using a testbench how it reacts on unit-amplitude (it is a bandpass) input signal.
It works great, at the same time it takes 'ages'. Simulation of such filter with roughly 5000 clock cycles takes almost 2 minutes. 4 times longer than I do with modelsim (from mentor).
So I wanted to check, whether it is feasible to use cython for these things. Following http://docs.cython.org/src/tutorial/cython_tutorial.html I hae created the setup and compiled in-the module using build_ext --inplace.
All that works OK, but then I tried to import the compiled module in python, and I get:
--------------------------------------------------------------------------------
>>> import FIR_tb
Working
Loaded 891 coefficients
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "FIR_tb.pyx", line 46, in init FIR_tb (FIR_tb.c:2580)
tbm = traceSignals(tb)
File "/usr/local/lib/python2.7/dist-packages/myhdl-1.0dev-py2.7.egg/myhdl/_traceSignals.py", line 85, in __call__
h = _HierExtr(name, dut, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/myhdl-1.0dev-py2.7.egg/myhdl/_extractHierarchy.py", line 238, in __init__
_top = dut(*args, **kwargs)
File "FIR_tb.pyx", line 19, in FIR_tb.tb (FIR_tb.c:1720)
@always(delay(10))
File "/usr/local/lib/python2.7/dist-packages/myhdl-1.0dev-py2.7.egg/myhdl/_always.py", line 54, in _always_decorator
raise AlwaysError(_error.ArgType)
myhdl.AlwaysError: decorated object should be a classic (non-generator) function
--------------------------------------------------------------------------------
for a testbench, which works OK when ran as a python module (non-compiled). For the sake of completeness here is the testbench (the entity itself is the same as in Christopher's examples)
--------------------------------------------------------------------------------
from myhdl import *
from FIR import *
print "Working"
def tb():
# read FIR coeffs
coeffs = map(int, open("/home/belohrad/git/didt/Python/firfilter/filter_coefficients_newline.txt", "rt").readlines())
print "Loaded ", len(coeffs), " coefficients"
DxD, QxD = [Signal(intbv(0)[32:0].signed()) for x in xrange(2)]
ResetxRN = ResetSignal(0, active = 0, async=True)
ClkxC = Signal(bool(0))
i_fir = m_firfilt (ClkxC, ResetxRN, DxD, QxD, coeffs)
@always(delay(10))
def driveClk():
ClkxC.next = not ClkxC
@instance
def tbi():
ResetxRN.next = 0
DxD.next = 0
yield(delay(150))
yield (ClkxC.posedge)
ResetxRN.next = 1
yield (ClkxC.posedge)
# test unity but this is a band-pass filter
for i in xrange(4906):
DxD.next = 1
yield (ClkxC.posedge)
DxD.next = 0
yield (ClkxC.posedge)
DxD.next = -1
yield (ClkxC.posedge)
DxD.next = 0
yield (ClkxC.posedge)
raise StopSimulation()
return tbi, driveClk, i_fir
tbm = traceSignals(tb)
sim = Simulation(tbm).run()
print "Done"
--------------------------------------------------------------------------------
Now, the error message is very cryptic to me. Is there anyone who tried to use cython for simulation? Is this error fatal and I cannot use cython at all due to some technical restrictions?
Thanks
.david.
------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140