Considering dependency among Tunable Settings in the search tuner
authorHamed Gorjiara <hgorjiar@uci.edu>
Sat, 6 Oct 2018 00:51:11 +0000 (17:51 -0700)
committerHamed Gorjiara <hgorjiar@uci.edu>
Sat, 6 Oct 2018 00:51:11 +0000 (17:51 -0700)
src/Collections/structs.cc
src/Collections/structs.h
src/Tuner/searchtuner.cc
src/Tuner/searchtuner.h
src/Tuner/tunabledependent.cc [new file with mode: 0644]
src/Tuner/tunabledependent.h [new file with mode: 0644]
src/classlist.h

index 767347456c47a4a372b23afb53bda245ff1cf3b4..7bff7ebae8347b7f6c59c302b0007cb61ecbe417 100644 (file)
@@ -7,6 +7,7 @@
 #include "orderelement.h"
 #include "structs.h"
 #include "decomposeorderresolver.h"
+#include "tunabledependent.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;}
@@ -29,6 +30,14 @@ bool table_entry_equals(TableEntry *key1, TableEntry *key2) {
        return true;
 }
 
+unsigned int tunable_dependent_hash_function(TunableDependent *This){
+       return (uint)This->dependent;
+}
+
+bool tunable_dependent_equals(TunableDependent *key1, TunableDependent *key2){
+       return key1->dependent == key2->dependent;
+}
+
 unsigned int order_node_hash_function(OrderNodeKey *This) {
        return (uint) This->id;
 }
index 9fa23bc2dd13b35216887ffa5a600bf2b27335e7..747d82c6bf8a479851706408958c619c250aa626 100644 (file)
@@ -12,6 +12,8 @@ unsigned int table_entry_hash_function(TableEntry *This);
 bool table_entry_equals(TableEntry *key1, TableEntry *key2);
 unsigned int order_node_hash_function(OrderNodeKey *This);
 bool order_node_equals(OrderNodeKey *key1, OrderNodeKey *key2);
+unsigned int tunable_dependent_hash_function(TunableDependent *This);
+bool tunable_dependent_equals(TunableDependent *key1, TunableDependent *key2);
 unsigned int order_edge_hash_function(OrderEdge *This);
 bool order_edge_equals(OrderEdge *key1, OrderEdge *key2);
 unsigned int order_element_hash_function(OrderElement *This);
@@ -25,6 +27,7 @@ bool doredge_equals(DOREdge *key1, DOREdge *key2);
 
 typedef Hashset<TableEntry *, uintptr_t, PTRSHIFT, table_entry_hash_function, table_entry_equals> HashsetTableEntry;
 typedef Hashset<OrderNodeKey *, uintptr_t, PTRSHIFT, order_node_hash_function, order_node_equals> HashsetOrderNode;
+typedef Hashset<TunableDependent *, uintptr_t, PTRSHIFT, tunable_dependent_hash_function, tunable_dependent_equals> HashsetTunableDep;
 typedef Hashset<OrderEdge *, uintptr_t, PTRSHIFT, order_edge_hash_function, order_edge_equals> HashsetOrderEdge;
 typedef Hashset<OrderElement *, uintptr_t, PTRSHIFT, order_element_hash_function, order_element_equals> HashsetOrderElement;
 typedef Hashset<DOREdge *, uintptr_t, PTRSHIFT, doredge_hash_function, doredge_equals> HashsetDOREdge;
@@ -46,6 +49,7 @@ typedef Hashtable<Set *, EncodingNode *, uintptr_t, PTRSHIFT> HashtableEncoding;
 typedef SetIterator<TableEntry *, uintptr_t, PTRSHIFT, table_entry_hash_function, table_entry_equals> SetIteratorTableEntry;
 typedef SetIterator<OrderEdge *, uintptr_t, PTRSHIFT, order_edge_hash_function, order_edge_equals> SetIteratorOrderEdge;
 typedef SetIterator<OrderNodeKey *, uintptr_t, PTRSHIFT, order_node_hash_function, order_node_equals> SetIteratorOrderNode;
+typedef SetIterator<TunableDependent *, uintptr_t, PTRSHIFT, tunable_dependent_hash_function, tunable_dependent_equals> SetIteratorTunableDep;
 typedef SetIterator<OrderElement *, uintptr_t, PTRSHIFT, order_element_hash_function, order_element_equals> SetIteratorOrderElement;
 typedef SetIterator<DOREdge *, uintptr_t, PTRSHIFT, doredge_hash_function, doredge_equals> SetIteratorDOREdge;
 #endif
index 1aef3fcd566a4adf28e201aac1fe1ec91d19e7af..4e963554bb50c2c4d2991fbda9ddcc3f1f92ef0b 100644 (file)
@@ -1,8 +1,26 @@
 #include "searchtuner.h"
+#include "tunabledependent.h"
 #include <iostream>
 #include <fstream>
+#include <valarray>
 using namespace std;
 
+HashsetTunableDep initializeTunableDependencies()
+{
+  HashsetTunableDep dep;
+  dep.add(new TunableDependent(MUSTREACHGLOBAL, DECOMPOSEORDER));
+  dep.add(new TunableDependent(MUSTREACHLOCAL, DECOMPOSEORDER));
+  dep.add(new TunableDependent(MUSTREACHPRUNE, DECOMPOSEORDER));
+  dep.add(new TunableDependent(MUSTEDGEPRUNE, DECOMPOSEORDER));
+  dep.add(new TunableDependent(NODEENCODING, ENCODINGGRAPHOPT));
+  dep.add(new TunableDependent(EDGEENCODING, ENCODINGGRAPHOPT));
+  dep.add(new TunableDependent(ELEMENTOPTSETS, ELEMENTOPT));
+  return dep;
+}
+
+
+HashsetTunableDep SearchTuner::tunableDependency = initializeTunableDependencies();
+
 TunableSetting::TunableSetting(VarType _type, TunableParam _param) :
        hasVar(true),
        type1(_type),
@@ -166,8 +184,35 @@ int SearchTuner::getVarTunable(VarType vartype1, VarType vartype2, TunableParam
        return result->selectedValue;
 }
 
+bool SearchTuner::validTunableSetting(TunableSetting* setting){
+       TunableDependent tuneDep((Tunables)setting->param);
+       bool result = true;
+       while(tunableDependency.contains(&tuneDep)){
+               TunableDependent *dependent = tunableDependency.get(&tuneDep);
+               TunableSetting p(dependent->parent);
+               if(!settings.contains(&p)){
+                       SetIteratorTunableSetting *iter = settings.iterator();
+                       while(iter->hasNext()){
+                               model_print("*******************\n");
+                               iter->next()->print();
+                       }
+                       delete iter;
+               }
+               ASSERT(settings.contains(&p));
+               TunableSetting *parent = settings.get(&p);
+               if(!(bool)parent->selectedValue){ //Check parent config is already off
+                       return false;
+               }
+               tuneDep.dependent = dependent->parent;
+       }
+       return result;
+}
+
 void SearchTuner::randomMutate() {
-       TunableSetting *randomSetting = settings.getRandomElement();
+       TunableSetting *randomSetting;
+       do{
+               randomSetting= settings.getRandomElement();
+       }while(!validTunableSetting(randomSetting));
        int range = randomSetting->highValue - randomSetting->lowValue;
        int randomchoice = (random() % range) + randomSetting->lowValue;
        if (randomchoice < randomSetting->selectedValue)
index 612f60e174f826b239911d817428d458fb92a223..190bc5ef07b15b6948c33fd3bb1eb9c00c8c4e28 100644 (file)
@@ -53,6 +53,8 @@ public:
 
        CMEMALLOC;
 private:
+        bool validTunableSetting(TunableSetting* setting);
+        static HashsetTunableDep tunableDependency;
        /** Used Settings keeps track of settings that were actually used by
           the example. Mutating settings may cause the Constraint Compiler
           not to query other settings.*/
diff --git a/src/Tuner/tunabledependent.cc b/src/Tuner/tunabledependent.cc
new file mode 100644 (file)
index 0000000..e1b0dba
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+/* 
+ * File:   TunableDependent.cc
+ * Author: hamed
+ * 
+ * Created on October 5, 2018, 11:26 AM
+ */
+
+#include "tunabledependent.h"
+
+TunableDependent::TunableDependent(Tunables dependent, Tunables parent):
+       dependent(dependent),
+       parent(parent)
+{
+}
+
+TunableDependent::TunableDependent(TunableDependent &setting)
+{
+       dependent = setting.dependent;
+       parent = setting.parent;
+}
+
+TunableDependent::~TunableDependent() {
+}
+
diff --git a/src/Tuner/tunabledependent.h b/src/Tuner/tunabledependent.h
new file mode 100644 (file)
index 0000000..241b9eb
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+/* 
+ * File:   TunableDependent.h
+ * Author: hamed
+ *
+ * Created on October 5, 2018, 11:26 AM
+ */
+
+#ifndef TUNABLEDEPENDENT_H
+#define TUNABLEDEPENDENT_H
+
+#include "tunable.h"
+
+class TunableDependent {
+public:
+        TunableDependent(Tunables dependent, Tunables parent = (Tunables) -1);
+        TunableDependent(TunableDependent &setting);
+        virtual ~TunableDependent();
+        Tunables dependent;
+        Tunables parent;
+};
+
+#endif /* TUNABLEDEPENDENT_H */
+
index 3269985504a2da78a90393ecb58a681bec7a19ca..e17ba84280f8cb7f185575c0cbf8d21dd63821e3 100644 (file)
@@ -61,6 +61,7 @@ class SearchTuner;
 class TunableSetting;
 
 class TunableDesc;
+class TunableDependent;
 
 class OrderResolver;
 class DecomposeOrderResolver;