Skip to content

Commit 53edee8

Browse files
author
Tobias Gysi
committed
added additional parameters
1 parent f842aa9 commit 53edee8

File tree

5 files changed

+69
-30
lines changed

5 files changed

+69
-30
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Makefile.in
1212
/.libs
1313
/src/.deps
1414
/src/.libs
15+
.vscode
1516

1617
# http://www.gnu.org/software/autoconf
1718

src/Access.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ std::vector<long> Access::countCapacityMisses(std::vector<long> CacheSizes) {
165165
// (the bounds were computed for the maximal cache size)
166166
if (*std::max_element(MachineModel_.CacheSizes.begin(), MachineModel_.CacheSizes.end()) <
167167
*std::max_element(CacheSizes.begin(), CacheSizes.end())) {
168-
printf("\n\n-> exit(-1) cache size exceeds maximum cache size of the machine\n");
168+
printf("-> exit(-1) cache size exceeds maximum cache size of the machine\n");
169169
exit(-1);
170170
}
171171
#endif

src/HayStack.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ void HayStack::initModel(std::vector<NamedLong> Parameters) {
3333
Parameters_ = Program_.getSchedule().params();
3434
int NumberOfParameters = Parameters_.dim(isl::dim::param);
3535
if (Parameters.size() < NumberOfParameters) {
36-
printf("\n\n-> exit(-1) not enough parameters\n");
36+
printf("-> exit(-1) not enough parameters\n");
3737
exit(-1);
3838
}
3939
std::map<int, NamedLong> SortedParameters;
4040
for (auto &Parameter : Parameters) {
4141
int Position = Parameters_.find_dim_by_name(isl::dim::param, Parameter.first);
4242
if (Position < 0 || Position >= NumberOfParameters) {
43-
printf("\n\n-> exit(-1) cannot find parameter %s\n", Parameter.first.c_str());
43+
printf("-> exit(-1) cannot find parameter %s\n", Parameter.first.c_str());
4444
exit(-1);
4545
}
4646
Parameters_ = Parameters_.fix_si(isl::dim::param, Position, Parameter.second);

src/Program.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
void Program::extractScop(std::string SourceFile) {
88
pet_scop *PetScop = pet_scop_extract_from_C_source(Context_.get(), SourceFile.c_str(), NULL);
99
if (PetScop == nullptr) {
10-
printf("\n\n-> exit(-1) cannot extract scope\n");
10+
printf("-> exit(-1) cannot extract scope\n");
1111
exit(-1);
1212
}
1313

src/main.cpp

Lines changed: 64 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <chrono>
66
#include <iomanip>
77
#include <iostream>
8+
#include <fstream>
89
#include <string>
910
#include <vector>
1011

@@ -17,28 +18,32 @@ namespace po = boost::program_options;
1718

1819
const int CACHE_LINE_SIZE = 64;
1920

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;
2424

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+
{
3027
std::string Name;
3128
int Current;
3229
int Start;
3330
int Stop;
3431
int Increment;
3532
};
3633

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+
{
3842
// define the program options
3943
po::options_description Descriptor("Program options");
4044
Descriptor.add_options() //
4145
("help,h", "print the program options") //
46+
("cache-sizes,c", po::value<std::vector<long>>()->multitoken(), "specify the cache sizes") //
4247
("input-file,f", po::value<std::string>(), "specify the source file [file name]") //
4348
("include-path,I", po::value<std::vector<std::string>>(), "specify the include path [include path]") //
4449
("verbose,v", po::value<bool>()->default_value(false), "print additional information");
@@ -47,22 +52,44 @@ int main(int argc, const char **args) {
4752
po::variables_map Variables;
4853
po::store(po::parse_command_line(argc, args, Descriptor), Variables);
4954
po::notify(Variables);
50-
if (Variables.count("help") || Variables.count("input-file") == 0) {
55+
if (Variables.count("help") || Variables.count("input-file") == 0)
56+
{
5157
std::cout << Descriptor << std::endl;
5258
return 0;
5359
}
5460

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+
5586
// allocate the context outside of the cache model
5687
std::vector<std::string> IncludePaths;
5788
if (Variables.count("include-path") > 0)
5889
IncludePaths = Variables["include-path"].as<std::vector<std::string>>();
5990
isl::ctx Context = allocateContextWithIncludePaths(IncludePaths);
6091
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-
6392
{
64-
// allocate the machine model
65-
machine_model MachineModel = {CACHE_LINE_SIZE, {CACHE_SIZE1, CACHE_SIZE2}};
6693
// compute the total time
6794
auto StartExecution = std::chrono::high_resolution_clock::now();
6895
// allocate the cache model and compile the program
@@ -85,18 +112,21 @@ int main(int argc, const char **args) {
85112
long TotalAccesses = 0;
86113
long TotalCompulsory = 0;
87114
std::vector<long> TotalCapacity(MachineModel.CacheSizes.size(), 0);
88-
for (auto &CacheMiss : CacheMisses) {
115+
for (auto &CacheMiss : CacheMisses)
116+
{
89117
TotalAccesses += CacheMiss.second.Total;
90118
TotalCompulsory += CacheMiss.second.CompulsoryMisses;
91119
std::transform(TotalCapacity.begin(), TotalCapacity.end(), CacheMiss.second.CapacityMisses.begin(),
92120
TotalCapacity.begin(), std::plus<long>());
93121
// print intermediate results if verbose is true
94-
if (Variables["verbose"].as<bool>()) {
122+
if (Variables["verbose"].as<bool>())
123+
{
95124
std::cout << std::fixed;
96125
std::cout << std::setprecision(2);
97126
std::cout << " -> " << CacheMiss.first << " counted ";
98127
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+
{
100130
std::cout << CacheMiss.second.CapacityMisses[i] << "/";
101131
}
102132
std::cout << CacheMiss.second.Total << " (CO/";
@@ -105,7 +135,8 @@ int main(int argc, const char **args) {
105135
std::cout << "TO) ";
106136
#ifdef PREFETCHING
107137
std::cout << "using ";
108-
for (int i = 0; i < MachineModel.CacheSizes.size(); ++i) {
138+
for (int i = 0; i < MachineModel.CacheSizes.size(); ++i)
139+
{
109140
int Streams = 0;
110141
if (CacheMiss.second.PrefetchInfo.Prefetched[i])
111142
Streams = CacheMiss.second.PrefetchInfo.PrefetchStreams[i];
@@ -143,27 +174,34 @@ int main(int argc, const char **args) {
143174
Timer::printClocks();
144175
// print the affinity info
145176
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+
{
148181
Affinity[Aff.first] += Aff.second;
149182
}
150183
}
151-
if (Affinity.size() > 0) {
184+
if (Affinity.size() > 0)
185+
{
152186
std::cout << "==================================================" << std::endl;
153187
// print the affinity
154-
for (auto Aff : Affinity) {
188+
for (auto Aff : Affinity)
189+
{
155190
std::cout << " - NonAffine " << Aff.first[0] << " Affine " << Aff.first[1] << " : " << Aff.second << std::endl;
156191
}
157192
std::cout << "==================================================" << std::endl;
158193
}
159194

160195
// print the conflicts
161196
auto Conflicts = Model.getConflicts();
162-
if (Conflicts.size() > 0) {
197+
if (Conflicts.size() > 0)
198+
{
163199
std::cout << "==================================================" << std::endl;
164-
for (auto Conflict : Conflicts) {
200+
for (auto Conflict : Conflicts)
201+
{
165202
std::cout << " - " << Conflict.first << ": ";
166-
for (auto Name : Conflict.second) {
203+
for (auto Name : Conflict.second)
204+
{
167205
std::cout << Name << " ";
168206
}
169207
std::cout << std::endl;

0 commit comments

Comments
 (0)