Skip to content

Commit

Permalink
Simulation: automatic fast simulation if no conversion required. close
Browse files Browse the repository at this point in the history
  • Loading branch information
gasparka committed Jul 8, 2018
1 parent 7e84ba1 commit 763796a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions pyha/common/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ class PyhaFunc:
""" All functions of a Pyha class will be wrapped in this object, calls to original function are done with 'profiler hack' in
order to save the local variables. """

# if true, just call the function.. 10 x faster (but VHDL generation not supported)
bypass = False

class TraceManager:
""" Enables nested functions calls, thanks to ref counting """
last_call_locals = {}
Expand Down Expand Up @@ -140,6 +143,9 @@ def update_output_types(self, ret):
self.output_types[i] = v

def __call__(self, *args, **kwargs):
if PyhaFunc.bypass:
return self.func(*args, **kwargs)

self.update_input_types(args, kwargs)
self.calls += 1

Expand Down
10 changes: 9 additions & 1 deletion pyha/simulation/simulation_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from pyha import Hardware
from pyha.common.complex import default_complex
from pyha.common.context_managers import RegisterBehaviour, SimulationRunning, SimPath, AutoResize
from pyha.common.core import PyhaFunc
from pyha.common.fixed_point import Sfix, default_sfix
from pyha.common.stream import packetize, Stream, unpacketize
from pyha.common.util import get_iterable, np_to_py
Expand Down Expand Up @@ -51,7 +52,7 @@ def is_list(x):
for i, arg in enumerate(args):
arg = get_iterable(arg)

if to_types is not None and not is_list(arg[0]):
if to_types is not None and not is_list(arg[0]):
args[i] = convert_arg(None, arg, i)
elif any(isinstance(x, float) for x in arg):
args[i] = convert_arg(default_sfix, arg, i)
Expand Down Expand Up @@ -221,6 +222,13 @@ def types_from_pyha_to_python(pyha_types):
if 'MODEL_PYHA' in simulations:
model_pyha = deepcopy(model) # used for MODEL_PYHA (need to copy before SimulationRunning starts)

# Speed up simulation if VHDL conversion is not required!
if 'RTL' not in simulations and 'GATE' not in simulations:
PyhaFunc.bypass = True
logger.info(f'Enabled fast simulation')
else:
PyhaFunc.bypass = False

with SimulationRunning.enable():
if 'MODEL' in simulations:
logger.info(f'Running "MODEL" simulation...')
Expand Down

0 comments on commit 763796a

Please sign in to comment.