在gem5模拟器上运行程序是时间开销是十分庞大的,尤其是乱序模拟的时候,时间往往不可接受。
那么如何加快程序运行时间呢?SimPoint工具应运而生。
把程序切成片段,每一个片段有他们的feature,对这些片段进行聚类。SimPoint认为一个cluster里的片段是相似的,用聚类最靠近中心点或者其它指标来选最有代表性的片段。一个cluster有多大,这个片段的权重就多大。
下载SimPoint:https://cseweb.ucsd.edu//~calder/simpoint/simpoint-3-0.htm
解压后进入文件目录,运行make命令。会出现如下错误:
Utilities.h: In member function ‘int Random::randInt()’:
Utilities.h:165:59: error: ‘INT_MAX’ was not declared in this scope
165 | inline int randInt() { return (int)(randFloat() * INT_MAX); }
| ^~~~~~~
Utilities.h:88:1: note: ‘INT_MAX’ is defined in header ‘<climits>’; did you forget to ‘#include ’?
按照提示,在Utilities.h文件中添加头文件:‘#include
CmdLineParser.cpp: In member function ‘bool CmdLineParser::parseCmdLine(int, char**)’:
CmdLineParser.cpp:80:13: error: ‘strlen’ was not declared in this scope
80 | if (strlen(arg) == 0) {
| ^~~~~~
CmdLineParser.cpp:74:1: note: ‘strlen’ is defined in header ‘<cstring>’; did you forget to ‘#include ’?
按照提示,在CmdLineParser.cpp文件中添加头文件:‘#include
Datapoint.h:111:20: error: ‘ostream’ has not been declared
111 | void write(ostream &os) const;
| ^~~~~~~
Datapoint.h:114:19: error: ‘istream’ has not been declared
114 | void read(istream &is);
| ^~~~~~~
Datapoint.h:118:26: error: ‘ostream’ has not been declared
118 | void writeBinary(ostream &os) const;
| ^~~~~~~
Datapoint.h:121:25: error: ‘istream’ has not been declared
121 | void readBinary(istream &is);
| ^~~~~~~
Datapoint.h:127:1: error: ‘ostream’ does not name a type
127 | ostream &operator<<(ostream &os, const Datapoint &dp);
| ^~~~~~~
在Datapoint.h文件中添加头文件:‘#include
FVParser.cpp: In member function ‘bool FVParser::nextLine(std::__cxx11::list<FVParserToken>*)’:
FVParser.cpp:106:29: error: ‘strlen’ was not declared in this scope
106 | } while ((! eof()) && ((strlen(buffer) == 0) || ('T' != buffer[0])));
| ^~~~~~
FVParser.cpp:86:1: note: ‘strlen’ is defined in header ‘<cstring>’; did you forget to ‘#include ’?
85 | #include
+++ |+#include
86 | #else
在FVParser.cpp文件中添加头文件:‘#include
再次运行make命令,会出现如下报错:
Simpoint.cpp: In member function ‘void Simpoint::loadData()’:
Simpoint.cpp:178:34: error: cannot convert ‘std::ifstream’ {aka ‘std::basic_ifstream<char>’} to ‘bool’
178 | Utilities::check(input, "Simpoint::loadData(): could not open file " +
| ^~~~~
| |
| std::ifstream {aka std::basic_ifstream<char>}
In file included from Simpoint.cpp:83:
Utilities.h:129:39: note: initializing argument 1 of ‘static void Utilities::check(bool, const string&)’
129 | static inline void check(bool checkval, const string &msg) {
| ~~~~~^~~~~~~~
这里应该是类型转换的错误。我的解决方法是在Simpoint.cpp文件中,在调用Utilities::check()函数的地方,第一个参数前加强制类型转换bool。
修改前为:
Utilities::check(input, "Simpoint::loadData(): could not open file " + options.loadProjMatrixTxtFmtName);
修改后为:
Utilities::check(bool (input), "Simpoint::loadData(): could not open file " + options.loadProjMatrixTxtFmtName);
编译完成进入bin目录下,执行测试用例:
./simpoint -maxK 30 -loadFVFile ../input/sample.bb -saveSimpoints simpoints -saveSimpointWeights weights
看到新生成simpoints和weights文件即表示安装和运行成功。
运行环境:
操作系统:Ubuntu 20.04 LTS
gcc:9.4.0