More of Tuning Framework
authorbdemsky <bdemsky@uci.edu>
Mon, 28 Aug 2017 02:40:55 +0000 (19:40 -0700)
committerbdemsky <bdemsky@uci.edu>
Mon, 28 Aug 2017 02:40:55 +0000 (19:40 -0700)
src/Tuner/searchtuner.cc
src/Tuner/searchtuner.h
src/classlist.h

index 628ec8e..f9873c0 100644 (file)
@@ -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;
 }
index 2d0facd..c136dc1 100644 (file)
@@ -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<TunableSetting *, uintptr_t, 4, tunableSettingHash, tunableSettingEquals> HashSetTunableSetting;
+typedef HSIterator<TunableSetting *, uintptr_t, 4, tunableSettingHash, tunableSettingEquals> 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
index dd97e08..97200ea 100644 (file)
@@ -51,6 +51,8 @@ class OrderNode;
 class OrderEdge;
 
 class AutoTuner;
+class SearchTuner;
+class TunableSetting;
 
 struct IncrementalSolver;
 typedef struct IncrementalSolver IncrementalSolver;