|
5 | 5 | import os |
6 | 6 | from typing import Dict |
7 | 7 | from textwrap import dedent |
8 | | -from hwcomponents import EnergyAreaModel, actionDynamicEnergy |
| 8 | +from hwcomponents import ComponentModel, action |
9 | 9 | import hwcomponents_neurosim.neurointerface as neurointerface |
10 | 10 |
|
11 | 11 | # ================================================================================================== |
|
197 | 197 | } |
198 | 198 |
|
199 | 199 |
|
200 | | -class _NeurosimPlugInComponent(EnergyAreaModel): |
| 200 | +class _NeurosimPlugInComponent(ComponentModel): |
201 | 201 | """ |
202 | 202 | A base class for Neurosim plug-in components. |
203 | 203 |
|
@@ -549,32 +549,34 @@ def _get_component_name(self): |
549 | 549 | else: |
550 | 550 | return self.component_name[0] |
551 | 551 |
|
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)[ |
555 | 555 | "Read Energy" |
556 | 556 | ] |
| 557 | + return energy, 0.0 |
557 | 558 |
|
558 | | - @actionDynamicEnergy |
559 | | - def compute(self) -> float: |
| 559 | + @action |
| 560 | + def compute(self) -> tuple[float, float]: |
560 | 561 | return self.read() |
561 | 562 |
|
562 | | - @actionDynamicEnergy |
563 | | - def add(self) -> float: |
| 563 | + @action |
| 564 | + def add(self) -> tuple[float, float]: |
564 | 565 | return self.read() |
565 | 566 |
|
566 | | - @actionDynamicEnergy |
567 | | - def convert(self) -> float: |
| 567 | + @action |
| 568 | + def convert(self) -> tuple[float, float]: |
568 | 569 | return self.read() |
569 | 570 |
|
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)[ |
573 | 574 | "Write Energy" |
574 | 575 | ] |
| 576 | + return energy, 0.0 |
575 | 577 |
|
576 | | - @actionDynamicEnergy |
577 | | - def update(self) -> float: |
| 578 | + @action |
| 579 | + def update(self) -> tuple[float, float]: |
578 | 580 | return self.write() |
579 | 581 |
|
580 | 582 |
|
@@ -607,15 +609,14 @@ def __init__(self, tech_node: float, cycle_period: float): |
607 | 609 | cycle_period=cycle_period, |
608 | 610 | ) |
609 | 611 |
|
610 | | - @actionDynamicEnergy |
611 | | - def read(self) -> float: |
| 612 | + @action |
| 613 | + def read(self) -> tuple[float, float]: |
612 | 614 | """ |
613 | 615 | Returns the energy for one NOR operation in Joules. |
614 | 616 |
|
615 | 617 | Returns |
616 | 618 | ------- |
617 | | - float |
618 | | - The energy for one NOR operation in Joules. |
| 619 | + (energy, latency): Tuple in (Joules, seconds). |
619 | 620 | """ |
620 | 621 | return super().read() |
621 | 622 |
|
@@ -649,10 +650,10 @@ def __init__(self, tech_node: float, cycle_period: float): |
649 | 650 | cycle_period=cycle_period, |
650 | 651 | ) |
651 | 652 |
|
652 | | - @actionDynamicEnergy |
653 | | - def read(self) -> float: |
| 653 | + @action |
| 654 | + def read(self) -> tuple[float, float]: |
654 | 655 | """ |
655 | | - Returns the energy for one NAND operation in Joules. |
| 656 | + Returns the energy and latency for one NAND operation. |
656 | 657 | """ |
657 | 658 | return super().read() |
658 | 659 |
|
@@ -686,10 +687,10 @@ def __init__(self, tech_node: float, cycle_period: float): |
686 | 687 | cycle_period=cycle_period, |
687 | 688 | ) |
688 | 689 |
|
689 | | - @actionDynamicEnergy |
690 | | - def read(self) -> float: |
| 690 | + @action |
| 691 | + def read(self) -> tuple[float, float]: |
691 | 692 | """ |
692 | | - Returns the energy for one NOT operation in Joules. |
| 693 | + Returns the energy and latency for one NOT operation. |
693 | 694 | """ |
694 | 695 | return super().read() |
695 | 696 |
|
@@ -728,15 +729,15 @@ def __init__(self, tech_node: float, cycle_period: float, n_bits: int): |
728 | 729 | n_bits=n_bits, |
729 | 730 | ) |
730 | 731 |
|
731 | | - def read(self): |
| 732 | + def read(self) -> tuple[float, float]: |
732 | 733 | """ |
733 | | - Returns the energy for one flip-flop read operation in Joules. |
| 734 | + Returns the energy and latency for one flip-flop read operation. |
734 | 735 | """ |
735 | 736 | return super().read() |
736 | 737 |
|
737 | | - def write(self): |
| 738 | + def write(self) -> tuple[float, float]: |
738 | 739 | """ |
739 | | - Returns the energy for one flip-flop write operation in Joules. |
| 740 | + Returns the energy and latency for one flip-flop write operation. |
740 | 741 | """ |
741 | 742 | return super().write() |
742 | 743 |
|
@@ -786,9 +787,9 @@ def __init__( |
786 | 787 | n_mux_inputs=n_mux_inputs, |
787 | 788 | ) |
788 | 789 |
|
789 | | - def read(self): |
| 790 | + def read(self) -> tuple[float, float]: |
790 | 791 | """ |
791 | | - Returns the energy for one muxing operation in Joules. |
| 792 | + Returns the energy and latency for one muxing operation. |
792 | 793 | """ |
793 | 794 | return super().read() |
794 | 795 |
|
@@ -827,25 +828,23 @@ def __init__(self, tech_node: float, cycle_period: float, n_bits: int): |
827 | 828 | n_bits=n_bits, |
828 | 829 | ) |
829 | 830 |
|
830 | | - def add(self): |
| 831 | + def add(self) -> tuple[float, float]: |
831 | 832 | """ |
832 | 833 | Returns the energy for one addition operation in Joules. |
833 | 834 |
|
834 | 835 | Returns |
835 | 836 | ------- |
836 | | - float |
837 | | - The energy for one addition operation in Joules. |
| 837 | + (energy, latency): Tuple in (Joules, seconds). |
838 | 838 | """ |
839 | 839 | return super().add() |
840 | 840 |
|
841 | | - def read(self): |
| 841 | + def read(self) -> tuple[float, float]: |
842 | 842 | """ |
843 | 843 | Returns the energy for one addition operation in Joules. |
844 | 844 |
|
845 | 845 | Returns |
846 | 846 | ------- |
847 | | - float |
848 | | - The energy for one addition operation in Joules. |
| 847 | + (energy, latency): Tuple in (Joules, seconds). |
849 | 848 | """ |
850 | 849 | return super().read() |
851 | 850 |
|
@@ -895,27 +894,25 @@ def __init__( |
895 | 894 | n_adder_tree_inputs=n_adder_tree_inputs, |
896 | 895 | ) |
897 | 896 |
|
898 | | - @actionDynamicEnergy |
899 | | - def add(self) -> float: |
| 897 | + @action |
| 898 | + def add(self) -> tuple[float, float]: |
900 | 899 | """ |
901 | 900 | Returns the energy for one addition operation in Joules. |
902 | 901 |
|
903 | 902 | Returns |
904 | 903 | ------- |
905 | | - float |
906 | | - The energy for one addition operation in Joules. |
| 904 | + (energy, latency): Tuple in (Joules, seconds). |
907 | 905 | """ |
908 | 906 | return super().add() |
909 | 907 |
|
910 | | - @actionDynamicEnergy |
911 | | - def read(self) -> float: |
| 908 | + @action |
| 909 | + def read(self) -> tuple[float, float]: |
912 | 910 | """ |
913 | 911 | Returns the energy for one addition operation in Joules. |
914 | 912 |
|
915 | 913 | Returns |
916 | 914 | ------- |
917 | | - float |
918 | | - The energy for one addition operation in Joules. |
| 915 | + (energy, latency): Tuple in (Joules, seconds). |
919 | 916 | """ |
920 | 917 | return super().read() |
921 | 918 |
|
@@ -1009,24 +1006,24 @@ def __init__( |
1009 | 1006 | shift_register_n_bits=shift_register_n_bits, |
1010 | 1007 | ) |
1011 | 1008 |
|
1012 | | - @actionDynamicEnergy |
1013 | | - def read(self) -> float: |
| 1009 | + @action |
| 1010 | + def read(self) -> tuple[float, float]: |
1014 | 1011 | """ |
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. |
1016 | 1013 | """ |
1017 | 1014 | return super().read() |
1018 | 1015 |
|
1019 | | - @actionDynamicEnergy |
1020 | | - def write(self) -> float: |
| 1016 | + @action |
| 1017 | + def write(self) -> tuple[float, float]: |
1021 | 1018 | """ |
1022 | | - Returns the energy to shift-and-add in Joules. |
| 1019 | + Returns the energy and latency to shift-and-add. |
1023 | 1020 | """ |
1024 | 1021 | return super().shift_add() |
1025 | 1022 |
|
1026 | | - @actionDynamicEnergy |
1027 | | - def shift_add(self) -> float: |
| 1023 | + @action |
| 1024 | + def shift_add(self) -> tuple[float, float]: |
1028 | 1025 | """ |
1029 | | - Returns the energy to shift-and-add in Joules. |
| 1026 | + Returns the energy and latency to shift-and-add. |
1030 | 1027 | """ |
1031 | 1028 | return super().shift_add() |
1032 | 1029 |
|
|
0 commit comments