From 8f955207d3617298cc9e3c6fc7c80deec51966cf Mon Sep 17 00:00:00 2001 From: Bugra Onal Date: Thu, 28 Jul 2022 16:47:29 -0700 Subject: [PATCH] Fixed write_size checks for characterizer --- compiler/characterizer/cacti.py | 2 +- compiler/characterizer/delay.py | 2 +- compiler/characterizer/elmore.py | 2 +- compiler/characterizer/functional.py | 6 +- compiler/characterizer/simulation.py | 4 +- compiler/verilog_template/template.py | 120 -------------------------- 6 files changed, 8 insertions(+), 128 deletions(-) delete mode 100644 compiler/verilog_template/template.py diff --git a/compiler/characterizer/cacti.py b/compiler/characterizer/cacti.py index 0b81535e..3e554d93 100644 --- a/compiler/characterizer/cacti.py +++ b/compiler/characterizer/cacti.py @@ -24,7 +24,7 @@ class cacti(simulation): # self.targ_read_ports = [] # self.targ_write_ports = [] # self.period = 0 - # if self.write_size: + # if self.write_size != self.word_size: # self.num_wmasks = int(math.ceil(self.word_size / self.write_size)) # else: # self.num_wmasks = 0 diff --git a/compiler/characterizer/delay.py b/compiler/characterizer/delay.py index d31e99cd..09a92a28 100644 --- a/compiler/characterizer/delay.py +++ b/compiler/characterizer/delay.py @@ -43,7 +43,7 @@ class delay(simulation): self.targ_read_ports = [] self.targ_write_ports = [] self.period = 0 - if self.write_size: + if self.write_size != self.word_size: self.num_wmasks = int(math.ceil(self.word_size / self.write_size)) else: self.num_wmasks = 0 diff --git a/compiler/characterizer/elmore.py b/compiler/characterizer/elmore.py index 3bc0ce42..c0b8c610 100644 --- a/compiler/characterizer/elmore.py +++ b/compiler/characterizer/elmore.py @@ -21,7 +21,7 @@ class elmore(simulation): # self.targ_read_ports = [] # self.targ_write_ports = [] # self.period = 0 - # if self.write_size: + # if self.write_size != self.word_size: # self.num_wmasks = int(math.ceil(self.word_size / self.write_size)) # else: # self.num_wmasks = 0 diff --git a/compiler/characterizer/functional.py b/compiler/characterizer/functional.py index dab753aa..0aa9ebcd 100644 --- a/compiler/characterizer/functional.py +++ b/compiler/characterizer/functional.py @@ -44,7 +44,7 @@ class functional(simulation): else: self.output_path = output_path - if self.write_size: + if self.write_size != self.word_size: self.num_wmasks = int(math.ceil(self.word_size / self.write_size)) else: self.num_wmasks = 0 @@ -133,7 +133,7 @@ class functional(simulation): def create_random_memory_sequence(self): # Select randomly, but have 3x more reads to increase probability - if self.write_size: + if self.write_size != self.word_size: rw_ops = ["noop", "write", "partial_write", "read", "read"] w_ops = ["noop", "write", "partial_write"] else: @@ -440,7 +440,7 @@ class functional(simulation): # Generate wmask bits for port in self.write_ports: - if self.write_size: + if self.write_size != self.word_size: self.sf.write("\n* Generation of wmask signals\n") for bit in range(self.num_wmasks): sig_name = "WMASK{0}_{1} ".format(port, bit) diff --git a/compiler/characterizer/simulation.py b/compiler/characterizer/simulation.py index f7830881..5649099c 100644 --- a/compiler/characterizer/simulation.py +++ b/compiler/characterizer/simulation.py @@ -39,7 +39,7 @@ class simulation(): self.words_per_row = self.sram.words_per_row self.num_rows = self.sram.num_rows self.num_cols = self.sram.num_cols - if self.write_size: + if self.write_size != self.word_size: self.num_wmasks = int(math.ceil(self.word_size / self.write_size)) else: self.num_wmasks = 0 @@ -464,7 +464,7 @@ class simulation(): for port in range(total_ports): pin_names.append("{0}{1}".format("clk", port)) - if self.write_size: + if self.write_size != self.word_size: for port in write_index: for bit in range(self.num_wmasks): pin_names.append("WMASK{0}_{1}".format(port, bit)) diff --git a/compiler/verilog_template/template.py b/compiler/verilog_template/template.py deleted file mode 100644 index 714833c0..00000000 --- a/compiler/verilog_template/template.py +++ /dev/null @@ -1,120 +0,0 @@ -# See LICENSE for licensing information. -# -# Copyright (c) 2016-2021 Regents of the University of California -# Santa Cruz -# All rights reserved. -# -import re - - -class baseSection: - """ - This is the base section class for other section classes to inherit. - It is also used as the top most section. - """ - def __init__(self): - self.children = [] - - def expand(self, dict, fd): - for c in self.children: - c.expand(dict, fd) - - -class loopSection(baseSection): - """ - This section is for looping elements. It will repeat the children - sections based on the key list. - """ - - def __init__(self, var, key): - baseSection.__init__(self) - self.var = var - self.key = key - - def expand(self, dict, fd): - for ind in dict[self.key]: - dict[self.var] = ind - for c in self.children: - c.expand(dict, fd) - if self.var in dict: - del dict[self.var] - - -class conditionalSection(baseSection): - """ - This class will conditionally print it's children based on the 'cond' - element. - """ - def __init__(self, cond): - baseSection.__init__(self) - self.cond = cond - - def expand(self, dict, fd): - run = eval(self.cond, dict) - if run: - for c in self.children: - c.expand(dict, fd) - - -class textSection(baseSection): - """ - This is plain text section. It can contain parameters that can be - replaced based on the dictionary. - """ - - def __init__(self, text): - self.text = text - - def expand(self, dict, fd): - varRE = re.compile('\{\{ (\S*) \}\}') - vars = varRE.finditer(self.text) - newText = self.text - for var in vars: - newText = newText.replace('{{ ' + var.group(1) + ' }}', str(dict[var.group(1)])) - print(newText, end='', file=fd) - - -class template: - """ - The template class will read a template and generate an output file - based on the template and the given dictionary. - """ - - def __init__(self, template, dict): - self.template = template - self.dict = dict - - def readTemplate(self): - lines = [] - with open(self.template, 'r') as f: - lines = f.readlines() - - self.baseSectionSection = baseSection() - context = [self.baseSectionSection] - forRE = re.compile('\s*\{% for (\S*) in (\S*) %\}') - endforRE = re.compile('\s*\{% endfor %\}') - ifRE = re.compile('\s*{% if (.*) %\}') - endifRE = re.compile('\s*\{% endif %\}') - for line in lines: - m = forRE.match(line) - if m: - section = loopSection(m.group(1), m.group(2)) - context[-1].children.append(section) - context.append(section) - continue - m = ifRE.match(line) - if m: - section = conditionalSection(m.group(1)) - context[-1].children.append(section) - context.append(section) - continue - if endforRE.match(line) or endifRE.match(line): - context.pop() - else: - context[-1].children.append(textSection(line)) - - def write(self, filename): - fd = open(filename, 'w') - self.readTemplate() - self.baseSectionSection.expand(self.dict, fd) - fd.close()