X-Git-Url: http://plrg.eecs.uci.edu/git/?p=satune.git;a=blobdiff_plain;f=src%2FTuner%2Fsearchtuner.cc;h=a6005802e2cd6f469e8e45e0e11ded5369edbb6e;hp=1aef3fcd566a4adf28e201aac1fe1ec91d19e7af;hb=875bd2edcb1767a727ea40419cc601670091f2ed;hpb=9eb16333c26996a97567f88d0f2e62e72eb9a9e6 diff --git a/src/Tuner/searchtuner.cc b/src/Tuner/searchtuner.cc index 1aef3fc..a600580 100644 --- a/src/Tuner/searchtuner.cc +++ b/src/Tuner/searchtuner.cc @@ -52,16 +52,6 @@ void TunableSetting::print() { model_print("\n"); } -unsigned int tunableSettingHash(TunableSetting *setting) { - return setting->hasVar ^ setting->type1 ^ setting->type2 ^ setting->param; -} - -bool tunableSettingEquals(TunableSetting *setting1, TunableSetting *setting2) { - return setting1->hasVar == setting2->hasVar && - setting1->type1 == setting2->type1 && - setting1->type2 == setting2->type2 && - setting1->param == setting2->param; -} ostream &operator<<(ostream &os, const TunableSetting &ts) { @@ -72,12 +62,11 @@ ostream &operator<<(ostream &os, const TunableSetting &ts) SearchTuner::SearchTuner() { -#ifdef STATICENCGEN - graphEncoding =false; - naiveEncoding = ELEM_UNASSIGNED; -#endif +} + +SearchTuner::SearchTuner(const char *filename, bool addused) { ifstream myfile; - myfile.open (TUNEFILE, ios::in); + myfile.open (filename, ios::in); if (myfile.is_open()) { bool hasVar; VarType type1; @@ -96,10 +85,92 @@ SearchTuner::SearchTuner() { setting = new TunableSetting(param); } setting->setDecision(lowValue, highValue, defaultValue, selectedValue); - usedSettings.add(setting); + settings.add(setting); + if(addused){ + usedSettings.add(setting); + } } myfile.close(); + } else { + model_print("Warning: Tuner %s couldn't be loaded ... Using default tuner instead ....\n", filename); + } +} + +bool SearchTuner::equalUsed(SearchTuner* tuner){ + if(tuner->usedSettings.getSize() != usedSettings.getSize()){ + return false; + } + bool result = true; + SetIteratorTunableSetting *iterator = usedSettings.iterator(); + while(iterator->hasNext()){ + TunableSetting *setting = iterator->next(); + if(!tuner->usedSettings.contains(setting)){ + result = false; + break; + }else{ + TunableSetting *tunerSetting = tuner->usedSettings.get(setting); + if(tunerSetting->selectedValue != setting->selectedValue){ + result = false; + break; + } + } } + delete iterator; + return result; +} + +void SearchTuner::addUsed(const char *filename) { + ifstream myfile; + myfile.open (filename, ios::in); + if (myfile.is_open()) { + bool hasVar; + VarType type1; + VarType type2; + TunableParam param; + int lowValue; + int highValue; + int defaultValue; + int selectedValue; + while (myfile >> hasVar >> type1 >> type2 >> param >> lowValue >> highValue >> defaultValue >> selectedValue) { + TunableSetting *setting; + + if (hasVar) { + setting = new TunableSetting(type1, type2, param); + } else { + setting = new TunableSetting(param); + } + setting->setDecision(lowValue, highValue, defaultValue, selectedValue); + if (!settings.contains(setting)) { + settings.add(setting); + usedSettings.add(setting); + } else { + TunableSetting *tmp = settings.get(setting); + settings.remove(tmp); + usedSettings.remove(tmp); + delete tmp; + settings.add(setting); + usedSettings.add(setting); + } + } + myfile.close(); + } +} + +bool SearchTuner::isSubTunerof(SearchTuner *newTuner){ + SetIteratorTunableSetting *iterator = usedSettings.iterator(); + while (iterator->hasNext()) { + TunableSetting *setting = iterator->next(); + if(!newTuner->settings.contains(setting)){ + return false; + } else{ + TunableSetting *newSetting = newTuner->settings.get(setting); + if(newSetting->selectedValue != setting->selectedValue){ + return false; + } + } + } + delete iterator; + return true; } SearchTuner *SearchTuner::copyUsed() { @@ -110,12 +181,6 @@ SearchTuner *SearchTuner::copyUsed() { TunableSetting *copy = new TunableSetting(setting); tuner->settings.add(copy); } -#ifdef STATICENCGEN - if(naiveEncoding != ELEM_UNASSIGNED){ - tuner->graphEncoding = graphEncoding; - tuner->naiveEncoding = naiveEncoding; - } -#endif delete iterator; return tuner; } @@ -129,6 +194,24 @@ SearchTuner::~SearchTuner() { delete iterator; } +void SearchTuner::setTunable(TunableParam param, TunableDesc *descriptor, uint value) { + TunableSetting *result = new TunableSetting(param); + result->setDecision(descriptor->lowValue, descriptor->highValue, descriptor->defaultValue, value); + settings.add(result); + usedSettings.add(result); +} + +void SearchTuner::setVarTunable(VarType vartype, TunableParam param, TunableDesc *descriptor, uint value) { + setVarTunable(vartype, 0, param, descriptor, value); +} + +void SearchTuner::setVarTunable(VarType vartype1, VarType vartype2, TunableParam param, TunableDesc *descriptor, uint value) { + TunableSetting *result = new TunableSetting(vartype1, vartype2, param); + result->setDecision(descriptor->lowValue, descriptor->highValue, descriptor->defaultValue, value); + settings.add(result); + usedSettings.add(result); +} + int SearchTuner::getTunable(TunableParam param, TunableDesc *descriptor) { TunableSetting setting(param); TunableSetting *result = usedSettings.get(&setting); @@ -179,50 +262,6 @@ void SearchTuner::randomMutate() { model_print("&&&&&&&&&&&&&&&&&&&&&&&\n"); } -#ifdef STATICENCGEN -int SearchTuner::nextStaticTuner() { - if(naiveEncoding == ELEM_UNASSIGNED){ - naiveEncoding = ONEHOT; - SetIteratorTunableSetting *iter = settings.iterator(); - while(iter->hasNext()){ - TunableSetting *setting = iter->next(); - if (setting->param == NAIVEENCODER){ - setting->selectedValue = ONEHOT; - } else if(setting->param == ENCODINGGRAPHOPT){ - setting->selectedValue = false; - } - } - delete iter; - return EXIT_FAILURE; - } - int result=EXIT_FAILURE; - if(naiveEncoding == BINARYINDEX && graphEncoding){ - model_print("Best tuner\n"); - return EXIT_SUCCESS; - }else if (naiveEncoding == BINARYINDEX && !graphEncoding){ - naiveEncoding = ONEHOT; - graphEncoding = true; - }else { - naiveEncoding = (ElementEncodingType)((int)naiveEncoding + 1); - } - SetIteratorTunableSetting *iter = settings.iterator(); - uint count = 0; - while(iter->hasNext()){ - TunableSetting * setting = iter->next(); - if (setting->param == NAIVEENCODER){ - setting->selectedValue = naiveEncoding; - count++; - } else if(setting->param == ENCODINGGRAPHOPT){ - setting->selectedValue = graphEncoding; - count++; - } - } - model_print("Mutating %u settings\n", count); - delete iter; - return result; -} -#endif - void SearchTuner::print() { SetIteratorTunableSetting *iterator = settings.iterator(); while (iterator->hasNext()) { @@ -233,9 +272,9 @@ void SearchTuner::print() { } -void SearchTuner::serialize() { +void SearchTuner::serialize(const char *filename) { ofstream myfile; - myfile.open (TUNEFILE, ios::out | ios::trunc); + myfile.open (filename, ios::out | ios::trunc); SetIteratorTunableSetting *iterator = settings.iterator(); while (iterator->hasNext()) { TunableSetting *setting = iterator->next(); @@ -245,6 +284,18 @@ void SearchTuner::serialize() { delete iterator; } +void SearchTuner::serializeUsed(const char *filename) { + ofstream myfile; + myfile.open (filename, ios::out | ios::trunc); + SetIteratorTunableSetting *iterator = usedSettings.iterator(); + while (iterator->hasNext()) { + TunableSetting *setting = iterator->next(); + myfile << *setting << endl; + } + myfile.close(); + delete iterator; +} + void SearchTuner::printUsed() { SetIteratorTunableSetting *iterator = usedSettings.iterator(); while (iterator->hasNext()) {