Skip to content

Commit

Permalink
Merge pull request #8 from sgherbst/feature/INICIO_DEV-2322
Browse files Browse the repository at this point in the history
Feature/inicio dev 2322
  • Loading branch information
sgherbst authored Apr 24, 2020
2 parents 0c7c90c + 616f03c commit acec424
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 52 deletions.
7 changes: 6 additions & 1 deletion msdsl/function.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import numpy as np
import cvxpy as cp
from math import ceil, log2
from scipy.sparse import coo_matrix, diags
from .expr.table import RealTable
Expand Down Expand Up @@ -35,6 +34,12 @@ def addr_bits(self):
return int(ceil(log2(self.numel)))

def create_tables(self):
# load cvxpy module
try:
import cvxpy as cp
except:
raise Exception(f'ERROR: module cvxpy could not be loaded, cannot use Function class')

# create list of sample points
lsb = (self.domain[1] - self.domain[0])/(self.numel-1)
x_vec = self.domain[0] + np.arange(self.numel-1)*lsb
Expand Down
73 changes: 30 additions & 43 deletions msdsl/plugin/msdsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
PACK_DIR = Path(__file__).resolve().parent.parent

# TODO: figure out how to remove dependency on anasymod (which itself depends on msdsl)
from anasymod.sources import VerilogHeader, VerilogSource
from anasymod.sources import VerilogHeader, VerilogSource, FunctionalModel
from anasymod.defines import Define
from anasymod.files import mkdir_p, rm_rf, which
from anasymod.util import call
Expand All @@ -17,79 +17,69 @@

class CustomPlugin(Plugin):
def __init__(self, prj_cfg: EmuConfig, cfg_file, prj_root):
super().__init__(cfg_file=cfg_file, prj_root=prj_root, build_root=os.path.join(prj_cfg.build_root_base, 'models'), name='msdsl')
super().__init__(cfg_file=cfg_file, prj_root=prj_root, build_root=prj_cfg.build_root_functional_models, name='msdsl')

self.include_statements += ['`include "msdsl.sv"']

# Parse command line arguments specific to MSDSL
self.args = None
self._parse_args()
# Initialize list of functional models to be generated
self.generator_sources = []

# Initialize Parameters
self.dt = prj_cfg.cfg.dt

# Initialize msdsl config
self.cfg.model_dir = self._build_root

# Update msdsl config with msdsl section in config file
self.cfg.update_config(subsection=self._name)

# Add defines according to command line arguments
if self.args.float:
self.add_define(Define(name='FLOAT_REAL', fileset='sim'))
if self.args.range_assertions:
self.add_define(Define(name='RANGE_ASSERTIONS', fileset='sim'))
if self.args.add_saturation:
self.add_define(Define(name='ADD_SATURATION'))

###############################################################
# Execute actions according to command line arguments
###############################################################

# make models
if self.args.models:
self.models()

##### Functions exposed for user to exercise on Analysis Object
##### Custom functions for actions triggered from command line or by setting an option

def models(self):
"""
Call gen.py to generate analog models.
"""
# make model directory, removing the old one if necessary
rm_rf(self.cfg.model_dir)
mkdir_p(self.cfg.model_dir)
# make model directory, removing the old model directory if necessary
rm_rf(self._build_root)

# run generator script
gen_script = os.path.join(self._prj_root, 'gen.py')

if 'PYTHON_MSDSL' in os.environ:
python_name = os.environ['PYTHON_MSDSL']
else:
python_name = which('python')

call([python_name, gen_script, '-o', self.cfg.model_dir, '--dt', str(self.dt)])
for generator_source in self.generator_sources:
# make model directory if necessary
mkdir_p(os.path.join(self._build_root, generator_source.fileset, generator_source.name))
for file in generator_source.files:
call([python_name, file, '-o', os.path.join(self._build_root, generator_source.fileset, generator_source.name), '--dt', str(self.dt)])

def float(self):
self._add_define(Define(name='FLOAT_REAL', fileset='sim'))

def range_assertions(self):
self._add_define(Define(name='RANGE_ASSERTIONS', fileset='sim'))

def add_saturation(self):
self._add_define(Define(name='ADD_SATURATION'))

##### Utility Functions

def _setup_defines(self):
"""
Add Define objects that are specific to MSDSL
"""
self.add_define(Define(name='DT_MSDSL', value=self.dt))
self.add_define(Define(name='SIMULATION_MODE_MSDSL', fileset='sim'))
self._add_define(Define(name='DT_MSDSL', value=self.dt))
self._add_define(Define(name='SIMULATION_MODE_MSDSL', fileset='sim'))

def _setup_sources(self):
"""
Add Source objects that are specific to MSDSL
"""

# Add MSDSL and SVREAL sources
self.add_source(source=VerilogHeader(files=[PACK_DIR / 'msdsl.sv'], config_path=self._srccfg_path))
self.add_source(source=VerilogHeader(files=[get_svreal_header()], config_path=self._srccfg_path))

# Add model sources
self.add_source(source=VerilogSource(files=os.path.join(self.cfg.model_dir, '*.sv'), config_path=self._srccfg_path))
self._add_source(source=VerilogHeader(files=[PACK_DIR / 'msdsl.sv'],
config_path=self._srccfg_path,
name='msdsl'))
self._add_source(source=VerilogHeader(files=[get_svreal_header()],
config_path=self._srccfg_path,
name='svreal'))

def _parse_args(self):
"""
Expand All @@ -103,13 +93,10 @@ def _parse_args(self):
--add_saturation: Enable saturation feature for fixed-point based simulations. This will prevent overflows.
--models: Generate functional models for selected project.
"""
parser = ArgumentParser()
parser.add_argument('--range_assertions', action='store_true')
parser.add_argument('--float', action='store_true')
parser.add_argument('--add_saturation', action='store_true')
parser.add_argument('--models', action='store_true')

self.args, _ = parser.parse_known_args()
self.args, _ = parser.parse_known_args()
20 changes: 12 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import os
from setuptools import setup, find_packages

name = 'msdsl'
version = '0.2.4'
version = '0.2.5'

DESCRIPTION = '''\
Library for generating synthesizable mixed-signal models for FPGA emulation\
Expand All @@ -10,6 +11,15 @@
with open('README.md', 'r') as fh:
LONG_DESCRIPTION = fh.read()

install_requires = [
'svreal>=0.2.2',
'scipy',
'numpy',
'matplotlib'
]
if os.name != 'nt':
install_requires.append('cvxpy')

setup(
name=name,
version=version,
Expand All @@ -21,13 +31,7 @@
'model', 'models', 'generator', 'verilog', 'system-verilog',
'system verilog', 'synthesizable', 'emulation', 'fpga'],
packages=find_packages(),
install_requires=[
'svreal>=0.2.2',
'scipy',
'numpy',
'matplotlib',
'cvxpy'
],
install_requires=install_requires,
license='MIT',
url=f'https://github.com/sgherbst/{name}',
author='Steven Herbst',
Expand Down
3 changes: 3 additions & 0 deletions tests/func_sim/test_func_sim.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# general imports
from pathlib import Path
import numpy as np
import importlib
import pytest

# AHA imports
import magma as m
Expand Down Expand Up @@ -48,6 +50,7 @@ def gen_model(order=0, numel=512):
# write the model
return model.compile_to_file(VerilogGenerator())

@pytest.mark.skipif(not importlib.util.find_spec("cvxpy"), reason="cvxpy is not available in python distribution")
def test_func_sim(simulator, order, err_lim, numel):
# generate model
model_file = gen_model(order=order, numel=numel)
Expand Down

0 comments on commit acec424

Please sign in to comment.