44dcd5c64d6fe2ffce91a2fcdbaa628013f63cea
[satune.git] / src / Tuner / searchtuner.h
1 #ifndef SEARCHTUNER_H
2 #define SEARCHTUNER_H
3 #include "classlist.h"
4 #include "tunable.h"
5 #include "structs.h"
6 #include <ostream>
7 using namespace std;
8
9 class TunableSetting {
10 public:
11         TunableSetting(VarType type, TunableParam param);
12         TunableSetting(VarType type1, VarType type2, TunableParam param);
13         TunableSetting(TunableParam param);
14         TunableSetting(TunableSetting *ts);
15         void setDecision(int _low, int _high, int _default, int _selection);
16         void print();
17         friend std ::ostream &operator<< (std::ostream &stream, const TunableSetting &matrix);
18         CMEMALLOC;
19 private:
20         bool hasVar;
21         VarType type1;
22         VarType type2;
23         TunableParam param;
24         int lowValue;
25         int highValue;
26         int defaultValue;
27         int selectedValue;
28         friend unsigned int tunableSettingHash(TunableSetting *setting);
29         friend bool tunableSettingEquals(TunableSetting *setting1, TunableSetting *setting2);
30         friend class SearchTuner;
31         friend class StaticSearchTuner;
32 };
33
34 unsigned int tunableSettingHash(TunableSetting *setting);
35 bool tunableSettingEquals(TunableSetting *setting1, TunableSetting *setting2);
36
37 typedef Hashset<TunableSetting *, uintptr_t, 4, tunableSettingHash, tunableSettingEquals> HashsetTunableSetting;
38 typedef SetIterator<TunableSetting *, uintptr_t, 4, tunableSettingHash, tunableSettingEquals> SetIteratorTunableSetting;
39
40 class SearchTuner : public Tuner {
41 public:
42         SearchTuner();
43         SearchTuner(const char *filename);
44         ~SearchTuner();
45         int getTunable(TunableParam param, TunableDesc *descriptor);
46         int getVarTunable(VarType vartype, TunableParam param, TunableDesc *descriptor);
47         int getVarTunable(VarType vartype1, VarType vartype2, TunableParam param, TunableDesc *descriptor);
48         void setTunable(TunableParam param, TunableDesc *descriptor, uint value);
49         void setVarTunable(VarType vartype, TunableParam param, TunableDesc *descriptor, uint value);
50         void setVarTunable(VarType vartype1, VarType vartype2, TunableParam param, TunableDesc *descriptor, uint value);
51         SearchTuner *copyUsed();
52         void randomMutate();
53         uint getSize() { return usedSettings.getSize();}
54         void print();
55         void printUsed();
56         void serialize(const char *file);
57
58         CMEMALLOC;
59 protected:
60         /** Used Settings keeps track of settings that were actually used by
61            the example. Mutating settings may cause the Constraint Compiler
62            not to query other settings.*/
63         HashsetTunableSetting usedSettings;
64         /** Settings contains all settings. */
65         HashsetTunableSetting settings;
66 };
67
68 #endif