Skip to content

Commit 5e75a29

Browse files
Latency modeling
1 parent 5c87e96 commit 5e75a29

2 files changed

Lines changed: 56 additions & 56 deletions

File tree

hwcomponents_neurosim/main.py

Lines changed: 52 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import os
66
from typing import Dict
77
from textwrap import dedent
8-
from hwcomponents import EnergyAreaModel, actionDynamicEnergy
8+
from hwcomponents import ComponentModel, action
99
import hwcomponents_neurosim.neurointerface as neurointerface
1010

1111
# ==================================================================================================
@@ -197,7 +197,7 @@
197197
}
198198

199199

200-
class _NeurosimPlugInComponent(EnergyAreaModel):
200+
class _NeurosimPlugInComponent(ComponentModel):
201201
"""
202202
A base class for Neurosim plug-in components.
203203
@@ -549,32 +549,34 @@ def _get_component_name(self):
549549
else:
550550
return self.component_name[0]
551551

552-
@actionDynamicEnergy
553-
def read(self) -> float:
554-
return self.query_neurosim(self._get_component_name(), self.logger)[
552+
@action
553+
def read(self) -> tuple[float, float]:
554+
energy = self.query_neurosim(self._get_component_name(), self.logger)[
555555
"Read Energy"
556556
]
557+
return energy, 0.0
557558

558-
@actionDynamicEnergy
559-
def compute(self) -> float:
559+
@action
560+
def compute(self) -> tuple[float, float]:
560561
return self.read()
561562

562-
@actionDynamicEnergy
563-
def add(self) -> float:
563+
@action
564+
def add(self) -> tuple[float, float]:
564565
return self.read()
565566

566-
@actionDynamicEnergy
567-
def convert(self) -> float:
567+
@action
568+
def convert(self) -> tuple[float, float]:
568569
return self.read()
569570

570-
@actionDynamicEnergy
571-
def write(self) -> float:
572-
return self.query_neurosim(self._get_component_name(), self.logger)[
571+
@action
572+
def write(self) -> tuple[float, float]:
573+
energy = self.query_neurosim(self._get_component_name(), self.logger)[
573574
"Write Energy"
574575
]
576+
return energy, 0.0
575577

576-
@actionDynamicEnergy
577-
def update(self) -> float:
578+
@action
579+
def update(self) -> tuple[float, float]:
578580
return self.write()
579581

580582

@@ -607,15 +609,14 @@ def __init__(self, tech_node: float, cycle_period: float):
607609
cycle_period=cycle_period,
608610
)
609611

610-
@actionDynamicEnergy
611-
def read(self) -> float:
612+
@action
613+
def read(self) -> tuple[float, float]:
612614
"""
613615
Returns the energy for one NOR operation in Joules.
614616
615617
Returns
616618
-------
617-
float
618-
The energy for one NOR operation in Joules.
619+
(energy, latency): Tuple in (Joules, seconds).
619620
"""
620621
return super().read()
621622

@@ -649,10 +650,10 @@ def __init__(self, tech_node: float, cycle_period: float):
649650
cycle_period=cycle_period,
650651
)
651652

652-
@actionDynamicEnergy
653-
def read(self) -> float:
653+
@action
654+
def read(self) -> tuple[float, float]:
654655
"""
655-
Returns the energy for one NAND operation in Joules.
656+
Returns the energy and latency for one NAND operation.
656657
"""
657658
return super().read()
658659

@@ -686,10 +687,10 @@ def __init__(self, tech_node: float, cycle_period: float):
686687
cycle_period=cycle_period,
687688
)
688689

689-
@actionDynamicEnergy
690-
def read(self) -> float:
690+
@action
691+
def read(self) -> tuple[float, float]:
691692
"""
692-
Returns the energy for one NOT operation in Joules.
693+
Returns the energy and latency for one NOT operation.
693694
"""
694695
return super().read()
695696

@@ -728,15 +729,15 @@ def __init__(self, tech_node: float, cycle_period: float, n_bits: int):
728729
n_bits=n_bits,
729730
)
730731

731-
def read(self):
732+
def read(self) -> tuple[float, float]:
732733
"""
733-
Returns the energy for one flip-flop read operation in Joules.
734+
Returns the energy and latency for one flip-flop read operation.
734735
"""
735736
return super().read()
736737

737-
def write(self):
738+
def write(self) -> tuple[float, float]:
738739
"""
739-
Returns the energy for one flip-flop write operation in Joules.
740+
Returns the energy and latency for one flip-flop write operation.
740741
"""
741742
return super().write()
742743

@@ -786,9 +787,9 @@ def __init__(
786787
n_mux_inputs=n_mux_inputs,
787788
)
788789

789-
def read(self):
790+
def read(self) -> tuple[float, float]:
790791
"""
791-
Returns the energy for one muxing operation in Joules.
792+
Returns the energy and latency for one muxing operation.
792793
"""
793794
return super().read()
794795

@@ -827,25 +828,23 @@ def __init__(self, tech_node: float, cycle_period: float, n_bits: int):
827828
n_bits=n_bits,
828829
)
829830

830-
def add(self):
831+
def add(self) -> tuple[float, float]:
831832
"""
832833
Returns the energy for one addition operation in Joules.
833834
834835
Returns
835836
-------
836-
float
837-
The energy for one addition operation in Joules.
837+
(energy, latency): Tuple in (Joules, seconds).
838838
"""
839839
return super().add()
840840

841-
def read(self):
841+
def read(self) -> tuple[float, float]:
842842
"""
843843
Returns the energy for one addition operation in Joules.
844844
845845
Returns
846846
-------
847-
float
848-
The energy for one addition operation in Joules.
847+
(energy, latency): Tuple in (Joules, seconds).
849848
"""
850849
return super().read()
851850

@@ -895,27 +894,25 @@ def __init__(
895894
n_adder_tree_inputs=n_adder_tree_inputs,
896895
)
897896

898-
@actionDynamicEnergy
899-
def add(self) -> float:
897+
@action
898+
def add(self) -> tuple[float, float]:
900899
"""
901900
Returns the energy for one addition operation in Joules.
902901
903902
Returns
904903
-------
905-
float
906-
The energy for one addition operation in Joules.
904+
(energy, latency): Tuple in (Joules, seconds).
907905
"""
908906
return super().add()
909907

910-
@actionDynamicEnergy
911-
def read(self) -> float:
908+
@action
909+
def read(self) -> tuple[float, float]:
912910
"""
913911
Returns the energy for one addition operation in Joules.
914912
915913
Returns
916914
-------
917-
float
918-
The energy for one addition operation in Joules.
915+
(energy, latency): Tuple in (Joules, seconds).
919916
"""
920917
return super().read()
921918

@@ -1009,24 +1006,24 @@ def __init__(
10091006
shift_register_n_bits=shift_register_n_bits,
10101007
)
10111008

1012-
@actionDynamicEnergy
1013-
def read(self) -> float:
1009+
@action
1010+
def read(self) -> tuple[float, float]:
10141011
"""
1015-
Returns the energy to read the shift-and-add unit's output in Joules.
1012+
Returns the energy and latency to read the shift-and-add unit's output.
10161013
"""
10171014
return super().read()
10181015

1019-
@actionDynamicEnergy
1020-
def write(self) -> float:
1016+
@action
1017+
def write(self) -> tuple[float, float]:
10211018
"""
1022-
Returns the energy to shift-and-add in Joules.
1019+
Returns the energy and latency to shift-and-add.
10231020
"""
10241021
return super().shift_add()
10251022

1026-
@actionDynamicEnergy
1027-
def shift_add(self) -> float:
1023+
@action
1024+
def shift_add(self) -> tuple[float, float]:
10281025
"""
1029-
Returns the energy to shift-and-add in Joules.
1026+
Returns the energy and latency to shift-and-add.
10301027
"""
10311028
return super().shift_add()
10321029

setup.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Setup.py to ensure hwcomponents._version_scheme is importable during build."""
2+
23
import sys
34
import os
45
from pathlib import Path
@@ -25,7 +26,9 @@ class CustomBuildCommand(build):
2526
def run(self):
2627
try:
2728
print("Running 'make build'...")
28-
subprocess.check_call(["make", "build"], cwd=os.path.dirname(os.path.realpath(__file__)))
29+
subprocess.check_call(
30+
["make", "build"], cwd=os.path.dirname(os.path.realpath(__file__))
31+
)
2932
print("'make build' completed successfully")
3033
except subprocess.CalledProcessError as e:
3134
print(f"Error running 'make build': {e}")

0 commit comments

Comments
 (0)