test: update benchmark configuration to account for access pattern

This commit is contained in:
Jędrzej Boczar 2020-02-05 12:38:05 +01:00
parent 7e0515c477
commit f9f86d507f
2 changed files with 89 additions and 30 deletions

View File

@ -128,6 +128,13 @@ class LiteDRAMBenchmarkSoC(SimSoC):
# Build -------------------------------------------------------------------------------------------- # Build --------------------------------------------------------------------------------------------
def load_access_pattern(filename):
with open(filename, newline='') as f:
reader = csv.reader(f)
pattern_init = [(int(addr, 0), int(data, 0)) for addr, data in reader]
return pattern_init
def main(): def main():
parser = argparse.ArgumentParser(description="LiteDRAM Benchmark SoC Simulation") parser = argparse.ArgumentParser(description="LiteDRAM Benchmark SoC Simulation")
builder_args(parser) builder_args(parser)
@ -159,10 +166,7 @@ def main():
soc_kwargs["bist_random"] = args.bist_random soc_kwargs["bist_random"] = args.bist_random
if args.access_pattern: if args.access_pattern:
with open(args.access_pattern, newline='') as f: soc_kwargs["pattern_init"] = load_access_pattern(args.access_pattern)
reader = csv.reader(f)
pattern_init = [(int(addr, 0), int(data, 0)) for addr, data in reader]
soc_kwargs["pattern_init"] = pattern_init
# SoC ------------------------------------------------------------------------------------------ # SoC ------------------------------------------------------------------------------------------
soc = LiteDRAMBenchmarkSoC(**soc_kwargs) soc = LiteDRAMBenchmarkSoC(**soc_kwargs)

View File

@ -13,9 +13,10 @@ from collections import defaultdict, namedtuple
import yaml import yaml
from litedram.common import Settings from litedram.common import Settings as _Settings
from .benchmark import LiteDRAMBenchmarkSoC from . import benchmark
from .benchmark import LiteDRAMBenchmarkSoC, load_access_pattern
# constructs python regex named group # constructs python regex named group
@ -39,34 +40,88 @@ def human_readable(value):
# Benchmark configuration -------------------------------------------------------------------------- # Benchmark configuration --------------------------------------------------------------------------
class BenchmarkConfiguration(Settings): class Settings(_Settings):
def __init__(self, sdram_module, sdram_data_width, bist_length, bist_random): def as_dict(self):
d = dict()
for attr, value in vars(self).items():
if attr == 'self' or attr.startswith('_'):
continue
if isinstance(value, Settings):
value = value.as_dict()
d[attr] = value
return d
class GeneratedAccess(Settings):
def __init__(self, bist_length, bist_random):
self.set_attributes(locals()) self.set_attributes(locals())
self._settings = {k: v for k, v in locals().items() if k != 'self'}
@property
def length(self):
return self.bist_length
def as_args(self): def as_args(self):
args = [] args = ['--bist-length=%d' % self.bist_length]
for attr, value in self._settings.items(): if self.bist_random:
arg_string = '--%s' % attr.replace('_', '-') args.append('--bist-random')
if isinstance(value, bool): return args
if value:
args.append(arg_string)
else: class CustomAccess(Settings):
args.extend([arg_string, str(value)]) def __init__(self, pattern_file):
self.set_attributes(locals())
@property
def length(self):
# we have to load the file to know pattern length, cache it when requested
if not hasattr(self, '_pattern'):
path = self.pattern_file
if not os.path.isabs(path):
benchmark_dir = os.path.dirname(benchmark.__file__)
path = os.path.join(benchmark_dir, path)
self._pattern = load_access_pattern(path)
return len(self._pattern)
def as_args(self):
return ['--access-pattern=%s' % self.pattern_file]
class BenchmarkConfiguration(Settings):
def __init__(self, name, sdram_module, sdram_data_width, access_pattern):
self.set_attributes(locals())
def as_args(self):
args = [
'--sdram-module=%s' % self.sdram_module,
'--sdram-data-width=%d' % self.sdram_data_width,
]
args += self.access_pattern.as_args()
return args return args
def __eq__(self, other): def __eq__(self, other):
if not isinstance(other, BenchmarkConfiguration): if not isinstance(other, BenchmarkConfiguration):
return NotImplemented return NotImplemented
return all((getattr(self, setting) == getattr(other, setting) return self.as_dict() == other.as_dict()
for setting in self._settings.keys()))
@property
def length(self):
return self.access_pattern.length
@classmethod @classmethod
def load_yaml(cls, yaml_file): def load_yaml(cls, yaml_file):
with open(yaml_file) as f: with open(yaml_file) as f:
description = yaml.safe_load(f) description = yaml.safe_load(f)
configurations = {name: cls(**desc) for name, desc in description.items()} configs = []
return configurations for name, desc in description.items():
if 'access_pattern' in desc:
access = CustomAccess(desc.pop('access_pattern'))
else:
access = GeneratedAccess(desc.pop('bist_length'), desc.pop('bist_random'))
configs.append(cls(name, **desc, access_pattern=access))
return configs
def __repr__(self):
return 'BenchmarkConfiguration(%s)' % self.as_dict()
# Benchmark results -------------------------------------------------------------------------------- # Benchmark results --------------------------------------------------------------------------------
@ -317,15 +372,15 @@ def main(argv=None):
# load and filter configurations # load and filter configurations
configurations = BenchmarkConfiguration.load_yaml(args.config) configurations = BenchmarkConfiguration.load_yaml(args.config)
filters = [] filters = {
if args.regex: 'regex': lambda config: re.search(args.regex, config.name),
filters.append(lambda name_value: re.search(args.regex, name_value[0])) 'not_regex': lambda config: not re.search(args.not_regex, config.name),
if args.not_regex: 'names': lambda config: config.name in args.names,
filters.append(lambda name_value: not re.search(args.not_regex, name_value[0])) }
if args.names: for arg, f in filters.items():
filters.append(lambda name_value: name_value[0] in args.names) if getattr(args, arg):
for f in filters: configurations = filter(f, configurations)
configurations = dict(filter(f, configurations.items())) configurations = list(configurations)
cache_exists = args.results_cache and os.path.isfile(args.results_cache) cache_exists = args.results_cache and os.path.isfile(args.results_cache)