11###########################################################
22## types.py
3- ##
3+ ##
44## defines
55## - collection of features
66## - feature groups
1717COUNTER_FEAUTRES = ["cache_miss" , "cpu_cycles" , "cpu_instructions" ]
1818BPF_FEATURES = ["bpf_cpu_time_ms" , "bpf_page_cache_hit" ]
1919IRQ_FEATURES = ["bpf_block_irq" , "bpf_net_rx_irq" , "bpf_net_tx_irq" ]
20- ACCELERATE_FEATURES = [' accelerator_intel_qat' ]
20+ ACCELERATE_FEATURES = [" accelerator_intel_qat" ]
2121WORKLOAD_FEATURES = COUNTER_FEAUTRES + BPF_FEATURES + IRQ_FEATURES + ACCELERATE_FEATURES
2222BASIC_FEATURES = COUNTER_FEAUTRES + BPF_FEATURES
2323
4040 "cpu_scaling_frequency_hertz" : ["1GHz" , "2GHz" , "3GHz" ],
4141 }
4242
43- no_weight_trainers = [' PolynomialRegressionTrainer' , ' GradientBoostingRegressorTrainer' , ' KNeighborsRegressorTrainer' , ' LinearRegressionTrainer' , ' SVRRegressorTrainer' , ' XgboostFitTrainer' ]
44- weight_support_trainers = [' SGDRegressorTrainer' , ' LogarithmicRegressionTrainer' , ' LogisticRegressionTrainer' , ' ExponentialRegressionTrainer' ]
43+ no_weight_trainers = [" PolynomialRegressionTrainer" , " GradientBoostingRegressorTrainer" , " KNeighborsRegressorTrainer" , " LinearRegressionTrainer" , " SVRRegressorTrainer" , " XgboostFitTrainer" ]
44+ weight_support_trainers = [" SGDRegressorTrainer" , " LogarithmicRegressionTrainer" , " LogisticRegressionTrainer" , " ExponentialRegressionTrainer" ]
4545default_trainer_names = no_weight_trainers + weight_support_trainers
4646default_trainers = "," .join (default_trainer_names )
4747
@@ -59,24 +59,29 @@ class FeatureGroup(enum.Enum):
5959 ThirdParty = 10
6060 Unknown = 99
6161
62+
6263class EnergyComponentLabelGroup (enum .Enum ):
6364 PackageEnergyComponentOnly = 1
6465 DRAMEnergyComponentOnly = 2
6566 CoreEnergyComponentOnly = 3
6667 PackageDRAMEnergyComponents = 4
6768
69+
6870class ModelOutputType (enum .Enum ):
6971 AbsPower = 1
7072 DynPower = 2
7173
72- def is_support_output_type (output_type_name ):
74+
75+ def is_output_type_supported (output_type_name ):
7376 return any (output_type_name == item .name for item in ModelOutputType )
7477
78+
7579def deep_sort (elements ):
7680 sorted_elements = elements .copy ()
7781 sorted_elements .sort ()
7882 return sorted_elements
7983
84+
8085FeatureGroups = {
8186 FeatureGroup .Full : deep_sort (WORKLOAD_FEATURES + SYSTEM_FEATURES ),
8287 FeatureGroup .WorkloadOnly : deep_sort (WORKLOAD_FEATURES ),
@@ -90,9 +95,11 @@ def deep_sort(elements):
9095
9196SingleSourceFeatures = [FeatureGroup .CounterOnly .name , FeatureGroup .BPFOnly .name , FeatureGroup .BPFIRQ .name ]
9297
98+
9399def is_single_source_feature_group (fg ):
94100 return fg .name in SingleSourceFeatures
95101
102+
96103default_main_feature_map = {
97104 FeatureGroup .Full : "cpu_instructions" ,
98105 FeatureGroup .WorkloadOnly : "cpu_instructions" ,
@@ -122,15 +129,17 @@ def main_feature(feature_group_name, energy_component):
122129 feature = default_main_feature_map [feature_group ]
123130 return features .index (feature )
124131
132+
125133# XGBoostRegressionTrainType
126134class XGBoostRegressionTrainType (enum .Enum ):
127135 TrainTestSplitFit = 1
128136 KFoldCrossValidation = 2
129137
138+
130139# XGBoost Model Feature and Label Incompatability Exception
131140class XGBoostModelFeatureOrLabelIncompatabilityException (Exception ):
132- """Exception raised when a saved model's features and label is incompatable with the training data.
133-
141+ """Exception raised when a saved model's features and label is incompatable with the training data.
142+
134143 ...
135144
136145 Attributes
@@ -139,7 +148,7 @@ class XGBoostModelFeatureOrLabelIncompatabilityException(Exception):
139148 expected_labels: the expected model labels
140149 actual_features: the actual model features
141150 actual_labels: the actual model labels
142- features_incompatible: true if expected_features == actual_features else false
151+ features_incompatible: true if expected_features == actual_features else false
143152 labels_incompatible: true if expected_labels == actual_labels else false
144153 """
145154
@@ -150,7 +159,6 @@ class XGBoostModelFeatureOrLabelIncompatabilityException(Exception):
150159 features_incompatible : bool
151160 labels_incompatible : bool
152161
153-
154162 def __init__ (self , expected_features : List [str ], expected_labels : List [str ], received_features : List [str ], received_labels : List [str ], message = "expected features/labels are the not the same as the features/labels of the training data" ) -> None :
155163 self .expected_features = expected_features
156164 self .expected_labels = expected_labels
@@ -188,12 +196,12 @@ def __init__(self, missing_model: bool, missing_model_desc: bool, message="model
188196 EnergyComponentLabelGroup .PackageEnergyComponentOnly : deep_sort (PACKAGE_ENERGY_COMPONENT_LABEL ),
189197 EnergyComponentLabelGroup .DRAMEnergyComponentOnly : deep_sort (DRAM_ENERGY_COMPONENT_LABEL ),
190198 EnergyComponentLabelGroup .CoreEnergyComponentOnly : deep_sort (CORE_ENERGY_COMPONENT_LABEL ),
191- EnergyComponentLabelGroup .PackageDRAMEnergyComponents : deep_sort (PACKAGE_ENERGY_COMPONENT_LABEL + DRAM_ENERGY_COMPONENT_LABEL )
192-
199+ EnergyComponentLabelGroup .PackageDRAMEnergyComponents : deep_sort (PACKAGE_ENERGY_COMPONENT_LABEL + DRAM_ENERGY_COMPONENT_LABEL ),
193200}
194201
195202all_feature_groups = [fg .name for fg in FeatureGroups .keys ()]
196203
204+
197205def get_feature_group (features ):
198206 sorted_features = deep_sort (features )
199207 for g , g_features in FeatureGroups .items ():
@@ -202,6 +210,7 @@ def get_feature_group(features):
202210 return g
203211 return FeatureGroup .Unknown
204212
213+
205214def get_valid_feature_groups (features ):
206215 valid_fgs = []
207216 for fg_key , fg_features in FeatureGroups .items ():
@@ -214,6 +223,7 @@ def get_valid_feature_groups(features):
214223 valid_fgs += [fg_key ]
215224 return valid_fgs
216225
226+
217227def is_weight_output (output_type ):
218228 if output_type == ModelOutputType .AbsModelWeight :
219229 return True
@@ -225,7 +235,8 @@ def is_weight_output(output_type):
225235 return True
226236 return False
227237
228- if __name__ == '__main__' :
238+
239+ if __name__ == "__main__" :
229240 for g , g_features in FeatureGroups .items ():
230241 shuffled_features = g_features .copy ()
231242 random .shuffle (shuffled_features )
0 commit comments