From 6d9a9cd74c434801985bd5e16c1cdb15085514ef Mon Sep 17 00:00:00 2001 From: Hamed Gorjiara Date: Fri, 30 Nov 2018 17:28:43 -0800 Subject: [PATCH] avoiding repetitive tuner --- src/Collections/structs.cc | 12 +++++++++ src/Collections/structs.h | 11 ++++---- src/Tuner/multituner.cc | 23 +++++++++++++++++ src/Tuner/multituner.h | 3 +++ src/Tuner/searchtuner.cc | 27 ++++++++++++-------- src/Tuner/searchtuner.h | 7 +----- src/analyzer/tunerloganalyzer.py | 43 ++++++++++++++++++++++++++++---- src/runbench.sh | 2 +- 8 files changed, 101 insertions(+), 27 deletions(-) diff --git a/src/Collections/structs.cc b/src/Collections/structs.cc index 7673474..0744a35 100644 --- a/src/Collections/structs.cc +++ b/src/Collections/structs.cc @@ -7,6 +7,7 @@ #include "orderelement.h" #include "structs.h" #include "decomposeorderresolver.h" +#include "searchtuner.h" #define HASHNEXT(hash, newval) {hash += newval; hash += hash << 10; hash ^= hash >> 6;} #define HASHFINAL(hash) {hash += hash << 3; hash ^= hash >> 11; hash += hash << 15;} @@ -81,3 +82,14 @@ bool doredge_equals(DOREdge *key1, DOREdge *key2) { return key1->newfirst == key2->newfirst && key1->newsecond == key2->newsecond; } + +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; +} diff --git a/src/Collections/structs.h b/src/Collections/structs.h index 9fa23bc..6540b5a 100644 --- a/src/Collections/structs.h +++ b/src/Collections/structs.h @@ -18,7 +18,8 @@ unsigned int order_element_hash_function(OrderElement *This); bool order_element_equals(OrderElement *key1, OrderElement *key2); unsigned int order_pair_hash_function(OrderPair *This); bool order_pair_equals(OrderPair *key1, OrderPair *key2); - +unsigned int tunableSettingHash(TunableSetting *setting); +bool tunableSettingEquals(TunableSetting *setting1, TunableSetting *setting2); unsigned int doredge_hash_function(DOREdge *key); bool doredge_equals(DOREdge *key1, DOREdge *key2); @@ -30,16 +31,13 @@ typedef Hashset HashsetDOREdge; typedef Hashset HashsetBoolean; typedef Hashset HashsetElement; -typedef SetIterator SetIteratorBoolean; typedef Hashset Hashset64Int; -typedef SetIterator SetIterator64Int; +typedef Hashset HashsetTunableSetting; typedef Hashtable HashtableNodeToNodeSet; typedef Hashtable HashtableOrderPair; typedef Hashtable CloneMap; - - typedef Hashtable HashtableEncoding; @@ -48,4 +46,7 @@ typedef SetIterator SetIteratorOrderNode; typedef SetIterator SetIteratorOrderElement; typedef SetIterator SetIteratorDOREdge; +typedef SetIterator SetIteratorBoolean; +typedef SetIterator SetIterator64Int; +typedef SetIterator SetIteratorTunableSetting; #endif diff --git a/src/Tuner/multituner.cc b/src/Tuner/multituner.cc index a86b90f..0beab16 100644 --- a/src/Tuner/multituner.cc +++ b/src/Tuner/multituner.cc @@ -29,6 +29,14 @@ void TunerRecord::setTime(Problem *problem, long long time) { timetaken.put(problem, time); } +void TunerRecord::print(){ + model_print("*************TUNER NUMBER=%d***********\n", tunernumber); + tuner->print(); + model_print("&&&&&&&&&&&&&USED SETTINGS &&&&&&&&&&&&\n"); + tuner->printUsed(); + model_print("\n"); +} + long long TunerRecord::getTime(Problem *problem) { if (timetaken.contains(problem)) return timetaken.get(problem); @@ -255,6 +263,7 @@ long long MultiTuner::evaluate(Problem *problem, TunerRecord *tuner) { updateTimeout(problem, metric); snprintf(buffer, sizeof(buffer), "tuner%uused", execnum); tuner->getTuner()->addUsed(buffer); + explored.push(tuner); } //Increment execution count execnum++; @@ -453,10 +462,24 @@ SearchTuner *MultiTuner::mutateTuner(SearchTuner *oldTuner, uint k) { model_print("Mutating %u settings\n", settingsToMutate); while (settingsToMutate-- != 0) { newTuner->randomMutate(); + if(hasExplored(newTuner)){ + model_print("Note:A repetitive tuner has found\n"); + settingsToMutate++; + } } return newTuner; } +bool MultiTuner::hasExplored(SearchTuner *newTuner){ + for (uint i=0; i< explored.getSize(); i++){ + SearchTuner *tuner = explored.get(i)->getTuner(); + if(tuner->isSubTunerof(newTuner)){ + return true; + } + } + return false; +} + TunerRecord *MultiTuner::tune(TunerRecord *tuner) { TunerRecord *bestTuner = NULL; double bestScore = DBL_MAX; diff --git a/src/Tuner/multituner.h b/src/Tuner/multituner.h index 87e8557..0c43785 100644 --- a/src/Tuner/multituner.h +++ b/src/Tuner/multituner.h @@ -28,6 +28,7 @@ public: void updateTuner(SearchTuner *_newtuner) {tuner = _newtuner;} long long getTime(Problem *problem); void setTime(Problem *problem, long long time); + void print(); private: SearchTuner *tuner; Vector problems; @@ -54,10 +55,12 @@ protected: long long evaluate(Problem *problem, TunerRecord *tuner); double evaluateAll(TunerRecord *tuner); SearchTuner *mutateTuner(SearchTuner *oldTuner, uint k); + bool hasExplored(SearchTuner *newTuner); void mapProblemsToTuners(Vector *tunerV); void improveTuners(Vector *tunerV); TunerRecord *tune(TunerRecord *tuner); Vector allTuners; + Vector explored; Vector problems; Vector tuners; uint budget; diff --git a/src/Tuner/searchtuner.cc b/src/Tuner/searchtuner.cc index 0639281..6b17a2a 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) { @@ -141,6 +131,23 @@ void SearchTuner::addUsed(const char *filename) { } } +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() { SearchTuner *tuner = new SearchTuner(); SetIteratorTunableSetting *iterator = usedSettings.iterator(); diff --git a/src/Tuner/searchtuner.h b/src/Tuner/searchtuner.h index 3db0064..c75bfd8 100644 --- a/src/Tuner/searchtuner.h +++ b/src/Tuner/searchtuner.h @@ -31,12 +31,6 @@ private: friend class SerializeTuner; }; -unsigned int tunableSettingHash(TunableSetting *setting); -bool tunableSettingEquals(TunableSetting *setting1, TunableSetting *setting2); - -typedef Hashset HashsetTunableSetting; -typedef SetIterator SetIteratorTunableSetting; - class SearchTuner : public Tuner { public: SearchTuner(); @@ -49,6 +43,7 @@ public: void setVarTunable(VarType vartype, TunableParam param, TunableDesc *descriptor, uint value); void setVarTunable(VarType vartype1, VarType vartype2, TunableParam param, TunableDesc *descriptor, uint value); SearchTuner *copyUsed(); + bool isSubTunerof(SearchTuner *newTuner); void randomMutate(); uint getSize() { return usedSettings.getSize();} void print(); diff --git a/src/analyzer/tunerloganalyzer.py b/src/analyzer/tunerloganalyzer.py index 396e3f6..d4e52cc 100644 --- a/src/analyzer/tunerloganalyzer.py +++ b/src/analyzer/tunerloganalyzer.py @@ -20,7 +20,7 @@ class AutoTunerArgParser: TUNABLEHEADER = ["DECOMPOSEORDER", "MUSTREACHGLOBAL", "MUSTREACHLOCAL", "MUSTREACHPRUNE", "OPTIMIZEORDERSTRUCTURE", "ORDERINTEGERENCODING", "PREPROCESS", "NODEENCODING", "EDGEENCODING", "MUSTEDGEPRUNE", "ELEMENTOPT", "ENCODINGGRAPHOPT", "ELEMENTOPTSETS", "PROXYVARIABLE", "MUSTVALUE", "NAIVEENCODER", "VARIABLEORDER", - "PROBLEM","SATTIME", "EXECTIME"] + "PROBLEM","SATTIME", "EXECTIME","TUNERNUMBER"] configs = {"EXECTIME": "-", "SATTIME":"-", @@ -91,12 +91,14 @@ def loadSolverTime(row, filename): def loadProblemName(row,filename): with open(filename) as f: row["PROBLEM"] = f.readline().replace("\n","") - -def main(): +def loadTunerNumber(row, filename): + with open(filename) as f: + row["TUNERNUMBER"] = f.readline().replace("\n","") +def analyzeLogs(file): global configs argprocess = AutoTunerArgParser() - file = open("tuner.csv", "w") printHeader(file) + rows = [] for i in range(argprocess.getRunNumber()): row = {"DECOMPOSEORDER" : "", "MUSTREACHGLOBAL" : "", @@ -117,12 +119,43 @@ def main(): "VARIABLEORDER" : "", "PROBLEM":"", "SATTIME":"", - "EXECTIME": "" + "EXECTIME": "", + "TUNERNUMBER":"" } + loadTunerNumber(row, argprocess.getFolder() + "/tunernum" + str(i)) loadTunerInfo(row, argprocess.getFolder()+"/tuner"+str(i)+"used") loadSolverTime(row, argprocess.getFolder()+"/log"+str(i)) loadProblemName(row, argprocess.getFolder()+"/problem"+str(i)) dump(file, row) + rows.append(row) + return rows + +def tunerNumberAnalysis(file, rows): + global TUNABLEHEADER + tunercount = {} + tunernumber = {} + for row in rows: + mystr="" + for i in range(18): + mystr+=row[TUNABLEHEADER[i]] + if mystr not in tunercount: + tunercount.update({mystr : 1}) + tunernumber.update({mystr : str(row["TUNERNUMBER"])}) + else : + tunercount[mystr] += 1 + tunernumber[mystr] += "-" + str(row["TUNERNUMBER"]) + + problems = set(map(lambda x: x["PROBLEM"], rows)) + print "Number of repititive tuners" + for key in tunercount: + if tunercount[key] > 1: + print key + "(ids:" + tunernumber[key] + ") = #" + str(tunercount[key]) + + +def main(): + file = open("tuner.csv", "w") + rows = analyzeLogs(file) + tunerNumberAnalysis(file, rows) file.close() return diff --git a/src/runbench.sh b/src/runbench.sh index fd093e4..ed66315 100755 --- a/src/runbench.sh +++ b/src/runbench.sh @@ -18,7 +18,7 @@ cd $BIN for d in $DUMP; do if [[ $d = *$1* ]]; then echo $d - ./run.sh deserializerun "."$d $2 "../"$3 out.out + ./run.sh tunerrun "."$d $2 "../"$3 out.out echo "Best tuner" fi done -- 2.34.1