5
5
#include < chrono>
6
6
#include < iomanip>
7
7
#include < iostream>
8
+ #include < fstream>
8
9
#include < string>
9
10
#include < vector>
10
11
@@ -17,28 +18,32 @@ namespace po = boost::program_options;
17
18
18
19
const int CACHE_LINE_SIZE = 64 ;
19
20
20
- // Xeon Gold 6150
21
- const int CACHE_SIZE1 = 32 * 1024 ; // 8-way
22
- const int CACHE_SIZE2 = 1024 * 1024 ; // 16-way (non-inclusive which is close to inclusive)
23
- const int CACHE_SIZE3 = 1408 * 1024 ; // 11-way (non-inclusive which is close to inclusive)
21
+ // default
22
+ const int CACHE_SIZE1 = 32 * 1024 ;
23
+ const int CACHE_SIZE2 = 512 * 1024 ;
24
24
25
- // polycache
26
- // const int CACHE_SIZE1 = 32 * 1024; // 4-way
27
- // const int CACHE_SIZE2 = 256 * 1024; // 4-way
28
-
29
- struct range {
25
+ struct range
26
+ {
30
27
std::string Name;
31
28
int Current;
32
29
int Start;
33
30
int Stop;
34
31
int Increment;
35
32
};
36
33
37
- int main (int argc, const char **args) {
34
+ bool check_path (std::string path)
35
+ {
36
+ std::ifstream f (path.c_str ());
37
+ return f.good ();
38
+ }
39
+
40
+ int main (int argc, const char **args)
41
+ {
38
42
// define the program options
39
43
po::options_description Descriptor (" Program options" );
40
44
Descriptor.add_options () //
41
45
(" help,h" , " print the program options" ) //
46
+ (" cache-sizes,c" , po::value<std::vector<long >>()->multitoken (), " specify the cache sizes" ) //
42
47
(" input-file,f" , po::value<std::string>(), " specify the source file [file name]" ) //
43
48
(" include-path,I" , po::value<std::vector<std::string>>(), " specify the include path [include path]" ) //
44
49
(" verbose,v" , po::value<bool >()->default_value (false ), " print additional information" );
@@ -47,22 +52,44 @@ int main(int argc, const char **args) {
47
52
po::variables_map Variables;
48
53
po::store (po::parse_command_line (argc, args, Descriptor), Variables);
49
54
po::notify (Variables);
50
- if (Variables.count (" help" ) || Variables.count (" input-file" ) == 0 ) {
55
+ if (Variables.count (" help" ) || Variables.count (" input-file" ) == 0 )
56
+ {
51
57
std::cout << Descriptor << std::endl;
52
58
return 0 ;
53
59
}
54
60
61
+ // check if the include paths are valid
62
+ for (int i = 0 ; i < Variables.count (" include-path" ); ++i)
63
+ {
64
+ if (!check_path (Variables[" include-path" ].as <std::vector<std::string>>()[i]))
65
+ {
66
+ printf (" -> exit(-1) include path %s not valid\n " ,
67
+ Variables[" include-path" ].as <std::vector<std::string>>()[i].c_str ());
68
+ exit (-1 );
69
+ }
70
+ }
71
+ // check if the source file is valid
72
+ if (!check_path (Variables[" input-file" ].as <std::string>()))
73
+ {
74
+ printf (" -> exit(-1) input file %s not found\n " ,
75
+ Variables[" input-file" ].as <std::string>().c_str ());
76
+ exit (-1 );
77
+ }
78
+
79
+ // allocate the machine model with default values
80
+ machine_model MachineModel = {CACHE_LINE_SIZE, {CACHE_SIZE1, CACHE_SIZE2}};
81
+ if (Variables.count (" cache-sizes" ) > 0 )
82
+ {
83
+ MachineModel.CacheSizes = Variables[" cache-sizes" ].as <std::vector<long >>();
84
+ }
85
+
55
86
// allocate the context outside of the cache model
56
87
std::vector<std::string> IncludePaths;
57
88
if (Variables.count (" include-path" ) > 0 )
58
89
IncludePaths = Variables[" include-path" ].as <std::vector<std::string>>();
59
90
isl::ctx Context = allocateContextWithIncludePaths (IncludePaths);
60
91
isl_options_set_on_error (Context.get (), ISL_ON_ERROR_ABORT);
61
- // TODO test if BV_CHAMBERS_ISL or BV_CHAMBERS_POLYLIB is more efficient
62
-
63
92
{
64
- // allocate the machine model
65
- machine_model MachineModel = {CACHE_LINE_SIZE, {CACHE_SIZE1, CACHE_SIZE2}};
66
93
// compute the total time
67
94
auto StartExecution = std::chrono::high_resolution_clock::now ();
68
95
// allocate the cache model and compile the program
@@ -85,18 +112,21 @@ int main(int argc, const char **args) {
85
112
long TotalAccesses = 0 ;
86
113
long TotalCompulsory = 0 ;
87
114
std::vector<long > TotalCapacity (MachineModel.CacheSizes .size (), 0 );
88
- for (auto &CacheMiss : CacheMisses) {
115
+ for (auto &CacheMiss : CacheMisses)
116
+ {
89
117
TotalAccesses += CacheMiss.second .Total ;
90
118
TotalCompulsory += CacheMiss.second .CompulsoryMisses ;
91
119
std::transform (TotalCapacity.begin (), TotalCapacity.end (), CacheMiss.second .CapacityMisses .begin (),
92
120
TotalCapacity.begin (), std::plus<long >());
93
121
// print intermediate results if verbose is true
94
- if (Variables[" verbose" ].as <bool >()) {
122
+ if (Variables[" verbose" ].as <bool >())
123
+ {
95
124
std::cout << std::fixed;
96
125
std::cout << std::setprecision (2 );
97
126
std::cout << " -> " << CacheMiss.first << " counted " ;
98
127
std::cout << CacheMiss.second .CompulsoryMisses << " /" ;
99
- for (int i = 0 ; i < MachineModel.CacheSizes .size (); ++i) {
128
+ for (int i = 0 ; i < MachineModel.CacheSizes .size (); ++i)
129
+ {
100
130
std::cout << CacheMiss.second .CapacityMisses [i] << " /" ;
101
131
}
102
132
std::cout << CacheMiss.second .Total << " (CO/" ;
@@ -105,7 +135,8 @@ int main(int argc, const char **args) {
105
135
std::cout << " TO) " ;
106
136
#ifdef PREFETCHING
107
137
std::cout << " using " ;
108
- for (int i = 0 ; i < MachineModel.CacheSizes .size (); ++i) {
138
+ for (int i = 0 ; i < MachineModel.CacheSizes .size (); ++i)
139
+ {
109
140
int Streams = 0 ;
110
141
if (CacheMiss.second .PrefetchInfo .Prefetched [i])
111
142
Streams = CacheMiss.second .PrefetchInfo .PrefetchStreams [i];
@@ -143,27 +174,34 @@ int main(int argc, const char **args) {
143
174
Timer::printClocks ();
144
175
// print the affinity info
145
176
std::map<std::vector<int >, int > Affinity;
146
- for (auto &CacheMiss : CacheMisses) {
147
- for (auto Aff : CacheMiss.second .Affinity ) {
177
+ for (auto &CacheMiss : CacheMisses)
178
+ {
179
+ for (auto Aff : CacheMiss.second .Affinity )
180
+ {
148
181
Affinity[Aff.first ] += Aff.second ;
149
182
}
150
183
}
151
- if (Affinity.size () > 0 ) {
184
+ if (Affinity.size () > 0 )
185
+ {
152
186
std::cout << " ==================================================" << std::endl;
153
187
// print the affinity
154
- for (auto Aff : Affinity) {
188
+ for (auto Aff : Affinity)
189
+ {
155
190
std::cout << " - NonAffine " << Aff.first [0 ] << " Affine " << Aff.first [1 ] << " : " << Aff.second << std::endl;
156
191
}
157
192
std::cout << " ==================================================" << std::endl;
158
193
}
159
194
160
195
// print the conflicts
161
196
auto Conflicts = Model.getConflicts ();
162
- if (Conflicts.size () > 0 ) {
197
+ if (Conflicts.size () > 0 )
198
+ {
163
199
std::cout << " ==================================================" << std::endl;
164
- for (auto Conflict : Conflicts) {
200
+ for (auto Conflict : Conflicts)
201
+ {
165
202
std::cout << " - " << Conflict.first << " : " ;
166
- for (auto Name : Conflict.second ) {
203
+ for (auto Name : Conflict.second )
204
+ {
167
205
std::cout << Name << " " ;
168
206
}
169
207
std::cout << std::endl;
0 commit comments