From de79393dfc28e085c502dd3b25bfe3dcbd02a309 Mon Sep 17 00:00:00 2001 From: Stefan Holst Date: Tue, 26 Sep 2023 13:58:38 +0900 Subject: [PATCH] fix log limiter, use eng notation --- src/kyupy/__init__.py | 16 ++++++++++++++-- src/kyupy/logic_sim.py | 4 ++-- src/kyupy/sdf.py | 29 +++++++++++++++-------------- src/kyupy/wave_sim.py | 4 ++-- 4 files changed, 33 insertions(+), 20 deletions(-) diff --git a/src/kyupy/__init__.py b/src/kyupy/__init__.py index 123bd03..8c29df1 100644 --- a/src/kyupy/__init__.py +++ b/src/kyupy/__init__.py @@ -57,6 +57,18 @@ def hr_bytes(nbytes): multiplier += 1 return f'{nbytes:.1f}{["", "ki", "Mi", "Gi", "Ti", "Pi"][multiplier]}B' +def eng(number): + """Formats a given number using engineering notation.""" + exponent = 0 + if abs(number) < 1: + while abs(number) >= 1000: + number *= 1000 + exponent -= 3 + else: + while abs(number) >= 1000: + number /= 1000 + exponent += 3 + return f'{number:.0f}' + (f'e{exponent}' if exponent != 0 else '') def hr_time(seconds): """Formats a given time interval for human readability.""" @@ -138,10 +150,10 @@ class Log: self._limit = limit def stop_limit(self): + self._limit = -1 if self.filtered > 0: - log.info(f'{self.filtered} more messages (filtered).') + self.info(f'{self.filtered} more messages (filtered).') self.filtered = 0 - self._limit = -1 def __getstate__(self): return {'elapsed': time.perf_counter() - self.start} diff --git a/src/kyupy/logic_sim.py b/src/kyupy/logic_sim.py index 81ef44b..393beaf 100644 --- a/src/kyupy/logic_sim.py +++ b/src/kyupy/logic_sim.py @@ -10,7 +10,7 @@ import math import numpy as np -from . import numba, logic, hr_bytes, sim +from . import numba, logic, hr_bytes, sim, eng from .circuit import Circuit class LogicSim(sim.SimOps): @@ -44,7 +44,7 @@ class LogicSim(sim.SimOps): self.s[:,:,1,:] = 255 # unassigned def __repr__(self): - return f'{{name: "{self.circuit.name}", sims: {self.sims}, m: {self.m}, c_bytes: {self.c.nbytes}}}' + return f'{{name: "{self.circuit.name}", sims: {self.sims}, m: {self.m}, c_bytes: {eng(self.c.nbytes)}}}' def s_to_c(self): """Copies the values from ``s[0]`` the inputs of the combinational portion. diff --git a/src/kyupy/sdf.py b/src/kyupy/sdf.py index ca9f7ef..0736cd2 100644 --- a/src/kyupy/sdf.py +++ b/src/kyupy/sdf.py @@ -61,20 +61,21 @@ class DelayFile: delays = np.zeros((len(circuit.lines), 2, 2, 3)) # dataset last during construction. - for name, iopaths in self.cells.items(): - name = name.replace('\\', '') - if cell := circuit.cells.get(name, None): - for i_pin_spec, o_pin_spec, *dels in iopaths: - if i_pin_spec.startswith('(posedge '): i_pol_idxs = [0] - elif i_pin_spec.startswith('(negedge '): i_pol_idxs = [1] - else: i_pol_idxs = [0, 1] - i_pin_spec = re.sub(r'\((neg|pos)edge ([^)]+)\)', r'\2', i_pin_spec) - if line := cell.ins[tlib.pin_index(cell.kind, i_pin_spec)]: - delays[line, i_pol_idxs] = [d if len(d) > 0 else [0, 0, 0] for d in dels] - else: - log.warn(f'No line to annotate in circuit: {i_pin_spec} for {cell}') - else: - log.warn(f'Name from SDF not found in circuit: {name}') + with log.limit(50): + for name, iopaths in self.cells.items(): + name = name.replace('\\', '') + if cell := circuit.cells.get(name, None): + for i_pin_spec, o_pin_spec, *dels in iopaths: + if i_pin_spec.startswith('(posedge '): i_pol_idxs = [0] + elif i_pin_spec.startswith('(negedge '): i_pol_idxs = [1] + else: i_pol_idxs = [0, 1] + i_pin_spec = re.sub(r'\((neg|pos)edge ([^)]+)\)', r'\2', i_pin_spec) + if line := cell.ins[tlib.pin_index(cell.kind, i_pin_spec)]: + delays[line, i_pol_idxs] = [d if len(d) > 0 else [0, 0, 0] for d in dels] + else: + log.warn(f'No line to annotate in circuit: {i_pin_spec} for {cell}') + else: + log.warn(f'Name from SDF not found in circuit: {name}') return np.moveaxis(delays, -1, 0) diff --git a/src/kyupy/wave_sim.py b/src/kyupy/wave_sim.py index c87892d..aabb63d 100644 --- a/src/kyupy/wave_sim.py +++ b/src/kyupy/wave_sim.py @@ -16,7 +16,7 @@ import math import numpy as np -from . import numba, cuda, sim, cdiv +from . import numba, cuda, sim, cdiv, eng TMAX = np.float32(2 ** 127) @@ -103,7 +103,7 @@ class WaveSim(sim.SimOps): def __repr__(self): dev = 'GPU' if hasattr(self.c, 'copy_to_host') else 'CPU' return f'{{name: "{self.circuit.name}", device: "{dev}", sims: {self.sims}, ops: {len(self.ops)}, ' + \ - f'levels: {len(self.level_starts)}, nbytes: {self.nbytes}}}' + f'levels: {len(self.level_starts)}, nbytes: {eng(self.nbytes)}}}' def s_to_c(self): """Transfers values of sequential elements and primary inputs to the combinational portion.