Browse Source

fix log limiter, use eng notation

devel
Stefan Holst 1 year ago
parent
commit
de79393dfc
  1. 16
      src/kyupy/__init__.py
  2. 4
      src/kyupy/logic_sim.py
  3. 29
      src/kyupy/sdf.py
  4. 4
      src/kyupy/wave_sim.py

16
src/kyupy/__init__.py

@ -57,6 +57,18 @@ def hr_bytes(nbytes): @@ -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: @@ -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}

4
src/kyupy/logic_sim.py

@ -10,7 +10,7 @@ import math @@ -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): @@ -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.

29
src/kyupy/sdf.py

@ -61,20 +61,21 @@ class DelayFile: @@ -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)

4
src/kyupy/wave_sim.py

@ -16,7 +16,7 @@ import math @@ -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): @@ -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.

Loading…
Cancel
Save