From: bdemsky Date: Mon, 28 Aug 2017 02:40:55 +0000 (-0700) Subject: More of Tuning Framework X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=9ee7a0ccf053aa99f3d639e7a681d739f29e1e13;p=satune.git More of Tuning Framework --- diff --git a/src/Tuner/searchtuner.cc b/src/Tuner/searchtuner.cc index 628ec8e..f9873c0 100644 --- a/src/Tuner/searchtuner.cc +++ b/src/Tuner/searchtuner.cc @@ -1,31 +1,72 @@ #include "searchtuner.h" -SearchTuner::SearchTuner() { -} - -int SearchTuner::getTunable(TunableParam param, TunableDesc *descriptor) { - return 0; -} - -int SearchTuner::getVarTunable(VarType vartype, TunableParam param, TunableDesc *descriptor) { - return 0; -} - -TunableParameter::TunableParameter(VarType _type, TunableParam _param) : +TunableSetting::TunableSetting(VarType _type, TunableParam _param) : hasVar(true), type(_type), param(_param) { } -TunableParameter::TunableParameter(TunableParam _param) : +TunableSetting::TunableSetting(TunableParam _param) : hasVar(false), type(0), param(_param) { } -TunableDecision::TunableDecision(int _low, int _high, int _default, int _selection) : - lowValue(_low), - highValue(_high), - defaultValue(_default), - selectedValue(_selection) { +void TunableSetting::setDecision(int _low, int _high, int _default, int _selection) { + lowValue = _low; + highValue = _high; + defaultValue = _default; + selectedValue = _selection; +} + +unsigned int tunableSettingHash(TunableSetting *setting) { + return setting->hasVar ^ setting->type ^ setting->param; +} + +bool tunableSettingEquals(TunableSetting *setting1, TunableSetting *setting2) { + return setting1->hasVar == setting2->hasVar && + setting1->type == setting2->type && + setting1->param == setting2->param; +} + +SearchTuner::SearchTuner() { +} + +SearchTuner::~SearchTuner() { + HSIteratorTunableSetting *iterator=settings.iterator(); + while(iterator->hasNext()) { + TunableSetting *setting=iterator->next(); + delete setting; + } + delete iterator; +} + +int SearchTuner::getTunable(TunableParam param, TunableDesc *descriptor) { + TunableSetting setting(param); + TunableSetting * result = usedSettings.get(&setting); + if (result == NULL) { + result = settings.get(&setting); + if ( result == NULL) { + result=new TunableSetting(param); + result->setDecision(descriptor->lowValue, descriptor->highValue, descriptor->defaultValue, descriptor->defaultValue); + settings.add(result); + } + usedSettings.add(result); + } + return result->selectedValue; +} + +int SearchTuner::getVarTunable(VarType vartype, TunableParam param, TunableDesc *descriptor) { + TunableSetting setting(vartype, param); + TunableSetting * result = usedSettings.get(&setting); + if (result == NULL) { + result = settings.get(&setting); + if ( result == NULL) { + result=new TunableSetting(vartype, param); + result->setDecision(descriptor->lowValue, descriptor->highValue, descriptor->defaultValue, descriptor->defaultValue); + settings.add(result); + } + usedSettings.add(result); + } + return result->selectedValue; } diff --git a/src/Tuner/searchtuner.h b/src/Tuner/searchtuner.h index 2d0facd..c136dc1 100644 --- a/src/Tuner/searchtuner.h +++ b/src/Tuner/searchtuner.h @@ -2,36 +2,43 @@ #define SEARCHTUNER_H #include "classlist.h" #include "tunable.h" +#include "structs.h" -class SearchTuner : public Tuner { - public: - SearchTuner(); - int getTunable(TunableParam param, TunableDesc *descriptor); - int getVarTunable(VarType vartype, TunableParam param, TunableDesc *descriptor); - MEMALLOC; - private: -}; - -class TunableParameter { +class TunableSetting { public: - TunableParameter(VarType type, TunableParam param); - TunableParameter(TunableParam param); + TunableSetting(VarType type, TunableParam param); + TunableSetting(TunableParam param); + void setDecision(int _low, int _high, int _default, int _selection); MEMALLOC; private: bool hasVar; VarType type; TunableParam param; + int lowValue; + int highValue; + int defaultValue; + int selectedValue; + friend unsigned int tunableSettingHash(TunableSetting *setting); + friend bool tunableSettingEquals(TunableSetting *setting1, TunableSetting *setting2); + friend class SearchTuner; }; -class TunableDecision { +unsigned int tunableSettingHash(TunableSetting *setting); +bool tunableSettingEquals(TunableSetting *setting1, TunableSetting *setting2); + +typedef HashSet HashSetTunableSetting; +typedef HSIterator HSIteratorTunableSetting; + +class SearchTuner : public Tuner { public: - TunableDecision(int _low, int _high, int _default, int _selection); + SearchTuner(); + ~SearchTuner(); + int getTunable(TunableParam param, TunableDesc *descriptor); + int getVarTunable(VarType vartype, TunableParam param, TunableDesc *descriptor); MEMALLOC; private: - int lowValue; - int highValue; - int defaultValue; - int selectedValue; + HashSetTunableSetting usedSettings; + HashSetTunableSetting settings; }; #endif diff --git a/src/classlist.h b/src/classlist.h index dd97e08..97200ea 100644 --- a/src/classlist.h +++ b/src/classlist.h @@ -51,6 +51,8 @@ class OrderNode; class OrderEdge; class AutoTuner; +class SearchTuner; +class TunableSetting; struct IncrementalSolver; typedef struct IncrementalSolver IncrementalSolver;