From 81283a7462a0623cb8b5f603be5fd96117595081 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Sat, 28 Mar 2020 23:10:42 +0000 Subject: [PATCH] set parameters using python style (and auto-detection) --- experiments7/doAlu16.py | 52 ++++++++++++++++++++--------------------- experiments7/utils.py | 34 +++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 27 deletions(-) diff --git a/experiments7/doAlu16.py b/experiments7/doAlu16.py index 724bb9c..1c1b616 100755 --- a/experiments7/doAlu16.py +++ b/experiments7/doAlu16.py @@ -7,7 +7,7 @@ import CRL import Cfg from Hurricane import Box from coriolis2.settings import af -from utils import Module, SessionManager +from utils import Module, SessionManager, Config import symbolic.cmos # do not remove @@ -15,32 +15,30 @@ BIT_WIDTH = 16 def coriolis_setup(): - Cfg.Configuration.pushDefaultPriority(Cfg.Parameter.Priority.UserFile) - Cfg.getParamBool('misc.catchCore').setBool(False) - Cfg.getParamBool('misc.info').setBool(False) - Cfg.getParamBool('misc.paranoid').setBool(False) - Cfg.getParamBool('misc.bug').setBool(False) - Cfg.getParamBool('misc.logMode').setBool(True) - Cfg.getParamBool('misc.verboseLevel1').setBool(True) - Cfg.getParamBool('misc.verboseLevel2').setBool(True) - Cfg.getParamEnumerate('etesian.effort').setInt(2) - Cfg.getParamPercentage('etesian.spaceMargin').setPercentage(20.0) - Cfg.getParamPercentage('etesian.aspectRatio').setPercentage(100.0) - Cfg.getParamBool('etesian.uniformDensity').setBool(True) - Cfg.getParamInt('anabatic.edgeLenght').setInt(24) - Cfg.getParamInt('anabatic.edgeWidth').setInt(8) - Cfg.getParamString('anabatic.topRoutingLayer').setString('METAL5') - Cfg.getParamInt('katana.searchHalo').setInt(30) - Cfg.getParamInt('katana.eventsLimit').setInt(1000000) - Cfg.getParamInt('katana.hTracksReservedLocal').setInt(7) - Cfg.getParamInt('katana.vTracksReservedLocal').setInt(6) - - env = af.getEnvironment() - env.setCLOCK('^clk$|m_clock') - env.setPOWER('vdd') - env.setGROUND('vss') - - Cfg.Configuration.popDefaultPriority() + with Config(Cfg.Parameter.Priority.UserFile) as cfg: + cfg.misc_catchCore = False + cfg.misc_info = False + cfg.misc_paranoid = False + cfg.misc_bug = False + cfg.misc_logMode = True + cfg.misc_verboseLevel1 = True + cfg.misc_verboseLevel2 = True + cfg.etesian_effort = 2 + cfg.etesian_spaceMargin = "20.0%" + cfg.etesian_aspectRatio = "100.0%" + cfg.etesian_uniformDensity = True + cfg.anabatic_edgeLenght = 24 + cfg.anabatic_edgeWidth = 8 + cfg.anabatic_topRoutingLayer = 'METAL5' + cfg.katana_searchHalo = 30 + cfg.katana_eventsLimit = 1000000 + cfg.katana_hTracksReservedLocal = 7 + cfg.katana_vTracksReservedLocal = 6 + + env = af.getEnvironment() + env.setCLOCK('^clk$|m_clock') + env.setPOWER('vdd') + env.setGROUND('vss') class AddSub(Module): diff --git a/experiments7/utils.py b/experiments7/utils.py index 13b7e1b..60057f6 100644 --- a/experiments7/utils.py +++ b/experiments7/utils.py @@ -3,6 +3,7 @@ from __future__ import print_function import Anabatic import CRL +import Cfg import Etesian import Katana from Hurricane import ( @@ -315,3 +316,36 @@ class Module(object): """ Main routine. """ raise NotImplementedError('You need to implement the `build` method.') + +class Config: + + def __init__(self, priority=None): + self._priority = priority + + def __enter__(self): + if self._priority is not None: + Cfg.Configuration.pushDefaultPriority(self._priority) + return self + + def __setattr__(self, attr, val): + if attr.startswith("_"): + self.__dict__[attr] = val + return + attr = attr.replace("_", ".") + if isinstance(val, bool): + Cfg.getParamBool(attr).setBool(val) + elif isinstance(val, int): + p = Cfg.getParamInt(attr) # all params have a type + if p.type == 'Enumerate': + Cfg.getParamEnumerate(attr).setInt(val) + else: + Cfg.getParamInt(attr).setInt(val) + elif '%' in val: + Cfg.getParamPercentage(attr).setPercentage(float(val[:-1])) + else: + Cfg.getParamString(attr).setString(val) + + def __exit__(self, *args): + if self._priority is not None: + Cfg.Configuration.popDefaultPriority() + -- 2.30.2