Extend tuning framework
authorbdemsky <bdemsky@uci.edu>
Mon, 11 Sep 2017 21:04:25 +0000 (14:04 -0700)
committerbdemsky <bdemsky@uci.edu>
Mon, 11 Sep 2017 21:04:25 +0000 (14:04 -0700)
src/AST/astops.h
src/ASTAnalyses/Encoding/encodinggraph.cc
src/ASTAnalyses/Encoding/encodinggraph.h
src/Encoders/elementencoding.h
src/Tuner/searchtuner.cc
src/Tuner/searchtuner.h
src/Tuner/tunable.cc
src/Tuner/tunable.h

index cd2beaabd2b056125838b653b78a57f6d5526700..e3c59630b92cc6ab150b70be4efecc197272c24f 100644 (file)
@@ -16,4 +16,11 @@ typedef enum Polarity Polarity;
 enum BooleanValue {BV_UNDEFINED=0, BV_MUSTBETRUE=1, BV_MUSTBEFALSE=2, BV_UNSAT=3};
 typedef enum BooleanValue BooleanValue;
 
+enum ElementEncodingType {
+       ELEM_UNASSIGNED, ONEHOT, UNARY, BINARYINDEX, ONEHOTBINARY, BINARYVAL
+};
+
+typedef enum ElementEncodingType ElementEncodingType;
+
+
 #endif
index 87799756ab0544e87063f76b93b502caa58eb59c..f01958b6cec187b53f29fbbe4280e0c9ace1b313 100644 (file)
@@ -4,6 +4,8 @@
 #include "function.h"
 #include "predicate.h"
 #include "set.h"
+#include "csolver.h"
+#include "tunable.h"
 
 EncodingGraph::EncodingGraph(CSolver * _solver) :
        solver(_solver) {
@@ -106,6 +108,14 @@ uint EncodingNode::getSize() {
        return s->getSize();
 }
 
+VarType EncodingNode::getType() {
+       return s->getType();
+}
+
+//ELEM_UNASSIGNED, ONEHOT, UNARY, BINARYINDEX, ONEHOTBINARY, BINARYVAL
+
+static TunableDesc NodeEncodingType(ELEM_UNASSIGNED, BINARYVAL, ELEM_UNASSIGNED);
+
 EncodingNode * EncodingGraph::createNode(Element *e) {
        if (e->type == ELEMCONST)
                return NULL;
@@ -113,6 +123,7 @@ EncodingNode * EncodingGraph::createNode(Element *e) {
        EncodingNode *n = encodingMap.get(s);
        if (n == NULL) {
                n = new EncodingNode(s);
+               n->setEncoding((ElementEncodingType)solver->getTuner()->getVarTunable(n->getType(), NODEENCODING, &NodeEncodingType));
                encodingMap.put(s, n);
        }
        n->addElement(e);
index 7f7b8b41b6d43f9083c5727a8d57f4793577f118..62e3b8fa92de5b15ddf8c489d7eeb2eaceaf5cdf 100644 (file)
@@ -31,11 +31,15 @@ class EncodingNode {
        EncodingNode(Set *_s);
        void addElement(Element *e);
        uint getSize();
+       VarType getType();
+       void setEncoding(ElementEncodingType e) {encoding=e;}
+       
        CMEMALLOC;
  private:
        Set *s;
        HashsetElement elements;
        uint numElements;
+       ElementEncodingType encoding;
        friend class EncodingGraph;
 };
 
index d7585f4bc0372adfde75579a0c6781f227da455e..6797c66bf530b9024fba0fd3627f43643799ce04 100644 (file)
@@ -4,12 +4,6 @@
 #include "naiveencoder.h"
 #include "constraint.h"
 
-enum ElementEncodingType {
-       ELEM_UNASSIGNED, ONEHOT, UNARY, BINARYINDEX, ONEHOTBINARY, BINARYVAL
-};
-
-typedef enum ElementEncodingType ElementEncodingType;
-
 class ElementEncoding {
 public:
        ElementEncoding(Element *element);
index 52c7a704896d70ea2a4a985db05dfd4ad3ea6cf6..3e9586096e36a1d0121db35b760556c49b6597f2 100644 (file)
@@ -2,19 +2,29 @@
 
 TunableSetting::TunableSetting(VarType _type, TunableParam _param) :
        hasVar(true),
-       type(_type),
+       type1(_type),
+       type2(0),
+       param(_param) {
+}
+
+TunableSetting::TunableSetting(VarType _type1, VarType _type2, TunableParam _param) :
+       hasVar(true),
+       type1(_type1),
+       type2(_type2),
        param(_param) {
 }
 
 TunableSetting::TunableSetting(TunableParam _param) :
        hasVar(false),
-       type(0),
+       type1(0),
+       type2(0),
        param(_param) {
 }
 
 TunableSetting::TunableSetting(TunableSetting *ts) :
        hasVar(ts->hasVar),
-       type(ts->type),
+       type1(ts->type1),
+       type2(ts->type2),
        param(ts->param),
        lowValue(ts->lowValue),
        highValue(ts->highValue),
@@ -32,19 +42,21 @@ void TunableSetting::setDecision(int _low, int _high, int _default, int _selecti
 
 void TunableSetting::print() {
        if (hasVar) {
-               model_print("Type %" PRIu64 ", ", type);
+               model_print("Type1 %" PRIu64 ", ", type1);
+               model_print("Type2 %" PRIu64 ", ", type2);
        }
        model_print("Param %u = %u\n", param, selectedValue);
 }
 
 unsigned int tunableSettingHash(TunableSetting *setting) {
-       return setting->hasVar ^ setting->type ^ setting->param;
+       return setting->hasVar ^ setting->type1 ^ setting->type2 ^ setting->param;
 }
 
 bool tunableSettingEquals(TunableSetting *setting1, TunableSetting *setting2) {
        return setting1->hasVar == setting2->hasVar &&
-                                setting1->type == setting2->type &&
-                                setting1->param == setting2->param;
+               setting1->type1 == setting2->type1 &&
+               setting1->type2 == setting2->type2 &&
+               setting1->param == setting2->param;
 }
 
 SearchTuner::SearchTuner() {
@@ -88,12 +100,17 @@ int SearchTuner::getTunable(TunableParam param, TunableDesc *descriptor) {
 }
 
 int SearchTuner::getVarTunable(VarType vartype, TunableParam param, TunableDesc *descriptor) {
-       TunableSetting setting(vartype, param);
+       return getVarTunable(vartype, 0, param, descriptor);
+}
+
+int SearchTuner::getVarTunable(VarType vartype1, VarType vartype2, TunableParam param, TunableDesc *descriptor) {
+       TunableSetting setting(vartype1, vartype2, param);
        TunableSetting *result = usedSettings.get(&setting);
        if (result == NULL) {
                result = settings.get(&setting);
                if ( result == NULL) {
-                       result = new TunableSetting(vartype, param);
+                       result = new
+                               TunableSetting(vartype1, vartype2, param);
                        uint value = descriptor->lowValue + (random() % (1 + descriptor->highValue - descriptor->lowValue));
                        result->setDecision(descriptor->lowValue, descriptor->highValue, descriptor->defaultValue, value);
                        settings.add(result);
index 20edb7d8537e0a27fc10bb9ae979785ec9fa9a64..1464849e520f2b905a1627071af6760f3f7ea23c 100644 (file)
@@ -7,6 +7,7 @@
 class TunableSetting {
 public:
        TunableSetting(VarType type, TunableParam param);
+       TunableSetting(VarType type1, VarType type2, TunableParam param);
        TunableSetting(TunableParam param);
        TunableSetting(TunableSetting *ts);
        void setDecision(int _low, int _high, int _default, int _selection);
@@ -14,7 +15,8 @@ public:
        CMEMALLOC;
 private:
        bool hasVar;
-       VarType type;
+       VarType type1;
+       VarType type2;
        TunableParam param;
        int lowValue;
        int highValue;
@@ -37,6 +39,7 @@ public:
        ~SearchTuner();
        int getTunable(TunableParam param, TunableDesc *descriptor);
        int getVarTunable(VarType vartype, TunableParam param, TunableDesc *descriptor);
+       int getVarTunable(VarType vartype1, VarType vartype2, TunableParam param, TunableDesc *descriptor);
        SearchTuner *copyUsed();
        void randomMutate();
        uint getSize() { return usedSettings.getSize();}
index 1401b24bbb86ab502e979aeddbc081f5d5eb0f9d..eeba3a29de8ef4b46e4071dd47ef5e0b20f64bd5 100644 (file)
@@ -6,6 +6,11 @@ DefaultTuner::DefaultTuner() {
 int DefaultTuner::getTunable(TunableParam param, TunableDesc *descriptor) {
        return descriptor->defaultValue;
 }
+
 int DefaultTuner::getVarTunable(VarType vartype, TunableParam param, TunableDesc *descriptor) {
        return descriptor->defaultValue;
 }
+
+int DefaultTuner::getVarTunable(VarType vartype1, VarType vartype2, TunableParam param, TunableDesc *descriptor) {
+       return descriptor->defaultValue;
+}
index 660c77db7ab0e64162b510036aaceb0f88c64235..050d46fec78fe6ee766dfd2727b74ee9e0862a41 100644 (file)
@@ -7,6 +7,7 @@ class Tuner {
 public:
        virtual int getTunable(TunableParam param, TunableDesc *descriptor) {ASSERT(0); return 0;}
        virtual int getVarTunable(VarType vartype, TunableParam param, TunableDesc *descriptor) {ASSERT(0); return 0;}
+       virtual int getVarTunable(VarType vartype1, VarType vartype2, TunableParam param, TunableDesc *descriptor) {ASSERT(0); return 0;}
        virtual ~Tuner() {}
        CMEMALLOC;
 };
@@ -16,6 +17,7 @@ public:
        DefaultTuner();
        int getTunable(TunableParam param, TunableDesc *descriptor);
        int getVarTunable(VarType vartype, TunableParam param, TunableDesc *descriptor);
+       int getVarTunable(VarType vartype1, VarType vartype2, TunableParam param, TunableDesc *descriptor);
        CMEMALLOC;
 };
 
@@ -37,6 +39,6 @@ public:
 static TunableDesc onoff(0, 1, 1);
 static TunableDesc offon(0, 1, 0);
 
-enum Tunables {DECOMPOSEORDER, MUSTREACHGLOBAL, MUSTREACHLOCAL, MUSTREACHPRUNE, OPTIMIZEORDERSTRUCTURE, ORDERINTEGERENCODING, PREPROCESS};
+enum Tunables {DECOMPOSEORDER, MUSTREACHGLOBAL, MUSTREACHLOCAL, MUSTREACHPRUNE, OPTIMIZEORDERSTRUCTURE, ORDERINTEGERENCODING, PREPROCESS, NODEENCODING};
 typedef enum Tunables Tunables;
 #endif