Commit e2bced6b authored by Jens Korinth's avatar Jens Korinth
Browse files

benchmark: Trap SIGINT and exit cleanly in case of exceptions

parent f274fe25
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <sstream> #include <sstream>
#include <chrono> #include <chrono>
#include <ctime> #include <ctime>
#include <csignal>
#include <vector> #include <vector>
#include <sys/utsname.h> #include <sys/utsname.h>
#include <tapasco_api.hpp> #include <tapasco_api.hpp>
...@@ -60,110 +61,123 @@ struct job_throughput_t { ...@@ -60,110 +61,123 @@ struct job_throughput_t {
}; } }; }
}; };
void signalHandler(int sig) {
cerr << "Signal %d received, aborting." << endl;
endwin();
exit(1);
}
int main(int argc, const char *argv[]) { int main(int argc, const char *argv[]) {
Tapasco tapasco; // trap ctrl-c
TransferSpeed tp { tapasco }; signal(SIGINT, signalHandler);
InterruptLatency il { tapasco }; try {
JobThroughput jt { tapasco }; Tapasco tapasco;
struct utsname uts; TransferSpeed tp { tapasco };
uname(&uts); InterruptLatency il { tapasco };
vector<Json> speed; JobThroughput jt { tapasco };
struct transfer_speed_t ts; struct utsname uts;
vector<Json> latency; uname(&uts);
struct interrupt_latency_t ls; vector<Json> speed;
vector<Json> jobs; struct transfer_speed_t ts;
struct job_throughput_t js; vector<Json> latency;
struct interrupt_latency_t ls;
vector<Json> jobs;
struct job_throughput_t js;
string platform = "vc709"; string platform = "vc709";
if (argc < 2) { if (argc < 2) {
if (getenv("TAPASCO_PLATFORM") == NULL) { if (getenv("TAPASCO_PLATFORM") == NULL) {
char n[256] { "" }; char n[256] { "" };
cout << "Environment variable TAPASCO_PLATFORM is not set, guessing Platform ..." << endl; cout << "Environment variable TAPASCO_PLATFORM is not set, guessing Platform ..." << endl;
if (gethostname(n, 255)) if (gethostname(n, 255))
cerr << "Could not get host name, guessing vc709 Platform" << endl; cerr << "Could not get host name, guessing vc709 Platform" << endl;
else { else {
cout << "Host name: " << n << endl; cout << "Host name: " << n << endl;
platform = n; platform = n;
if (string(n).compare("zed") == 0 || string(n).compare("zedboard") == 0) if (string(n).compare("zed") == 0 || string(n).compare("zedboard") == 0)
platform = "zedboard"; platform = "zedboard";
if (string(n).compare("zc706") == 0) if (string(n).compare("zc706") == 0)
platform = "zc706"; platform = "zc706";
cout << "Guessing " << platform << " Platform" << endl; cout << "Guessing " << platform << " Platform" << endl;
} }
} else platform = getenv("TAPASCO_PLATFORM"); } else platform = getenv("TAPASCO_PLATFORM");
} }
// measure for chunk sizes 2^10 (1KiB) - 2^31 (2GB) bytes // measure for chunk sizes 2^10 (1KiB) - 2^31 (2GB) bytes
for (int i = 10; i < 32; ++i) { for (int i = 10; i < 32; ++i) {
ts.chunk_sz = 1 << i; ts.chunk_sz = 1 << i;
ts.speed_r = tp(ts.chunk_sz, TransferSpeed::OP_COPYFROM); ts.speed_r = tp(ts.chunk_sz, TransferSpeed::OP_COPYFROM);
ts.speed_w = tp(ts.chunk_sz, TransferSpeed::OP_COPYTO); ts.speed_w = tp(ts.chunk_sz, TransferSpeed::OP_COPYTO);
ts.speed_rw = tp(ts.chunk_sz, TransferSpeed::OP_COPYFROM | TransferSpeed::OP_COPYTO); ts.speed_rw = tp(ts.chunk_sz, TransferSpeed::OP_COPYFROM | TransferSpeed::OP_COPYTO);
cout << "Transfer speed @ chunk_sz = " << (ts.chunk_sz/1024) << " KiB:" cout << "Transfer speed @ chunk_sz = " << (ts.chunk_sz/1024) << " KiB:"
<< " read " << ts.speed_r << " MiB/s" << " read " << ts.speed_r << " MiB/s"
<< ", write: " << ts.speed_w << " MiB/s" << ", write: " << ts.speed_w << " MiB/s"
<< ", r/w: " << ts.speed_rw << " MiB/s" << ", r/w: " << ts.speed_rw << " MiB/s"
<< endl; << endl;
if (ts.speed_r > 0.0 || ts.speed_w > 0 || ts.speed_rw > 0) { if (ts.speed_r > 0.0 || ts.speed_w > 0 || ts.speed_rw > 0) {
Json json = ts.to_json(); Json json = ts.to_json();
speed.push_back(json); speed.push_back(json);
} else break; } else break;
} }
// measure average job roundtrip latency for clock cycles counts // measure average job roundtrip latency for clock cycles counts
// between 2^0 and 2^31 // between 2^0 and 2^31
for (size_t i = 0; i < 32; ++i) { for (size_t i = 0; i < 32; ++i) {
ls.cycle_count = 1UL << i; ls.cycle_count = 1UL << i;
ls.latency_us = il.atcycles(ls.cycle_count, 10, &ls.min_latency_us, &ls.max_latency_us); ls.latency_us = il.atcycles(ls.cycle_count, 10, &ls.min_latency_us, &ls.max_latency_us);
cout << "Latency @ " << ls.cycle_count << "cc runtime: " << ls.latency_us << " us" << endl; cout << "Latency @ " << ls.cycle_count << "cc runtime: " << ls.latency_us << " us" << endl;
Json json = ls.to_json(); Json json = ls.to_json();
latency.push_back(json); latency.push_back(json);
} }
size_t i = 1; size_t i = 1;
double prev = -1; double prev = -1;
js.jobs_per_sec = -1; js.jobs_per_sec = -1;
do { do {
prev = js.jobs_per_sec; prev = js.jobs_per_sec;
js.num_threads = i; js.num_threads = i;
js.jobs_per_sec = jt(i); js.jobs_per_sec = jt(i);
++i; ++i;
jobs.push_back(js.to_json()); jobs.push_back(js.to_json());
} while (i <= 128 && (i <= 8 || js.jobs_per_sec > prev)); } while (i <= 128 && (i <= 8 || js.jobs_per_sec > prev));
// record current time // record current time
time_t tt = chrono::system_clock::to_time_t(chrono::system_clock::now()); time_t tt = chrono::system_clock::to_time_t(chrono::system_clock::now());
tm tm = *localtime(&tt); tm tm = *localtime(&tt);
stringstream str; stringstream str;
str << put_time(&tm, "%Y-%m-%d %H:%M:%S"); str << put_time(&tm, "%Y-%m-%d %H:%M:%S");
// build JSON object // build JSON object
Json benchmark = Json::object { Json benchmark = Json::object {
{"Timestamp", str.str()}, {"Timestamp", str.str()},
{"Host", Json::object { {"Host", Json::object {
{"Operating System", uts.sysname}, {"Operating System", uts.sysname},
{"Node", uts.nodename}, {"Node", uts.nodename},
{"Release", uts.release}, {"Release", uts.release},
{"Version", uts.version}, {"Version", uts.version},
{"Machine", uts.machine} {"Machine", uts.machine}
}
},
{"Transfer Speed", speed},
{"Interrupt Latency", latency},
{"Job Throughput", jobs},
{"Library Versions", Json::object {
{"Tapasco API", tapasco::tapasco_version()},
{"Platform API", platform::platform_version()}
}
} }
}, };
{"Transfer Speed", speed},
{"Interrupt Latency", latency},
{"Job Throughput", jobs},
{"Library Versions", Json::object {
{"Tapasco API", tapasco::tapasco_version()},
{"Platform API", platform::platform_version()}
}
}
};
// dump it // dump it
stringstream ss; stringstream ss;
ss << platform << ".benchmark"; ss << platform << ".benchmark";
cout << "Dumping benchmark JSON to " << (argc >= 2 ? argv[1] : ss.str()) << endl; cout << "Dumping benchmark JSON to " << (argc >= 2 ? argv[1] : ss.str()) << endl;
ofstream f(argc >= 2 ? argv[1] : ss.str()); ofstream f(argc >= 2 ? argv[1] : ss.str());
f << benchmark.dump(); f << benchmark.dump();
f.close(); f.close();
} catch (...) {
endwin();
throw;
}
} }
/* vim: set foldmarker=@{,@} foldlevel=0 foldmethod=marker : */ /* vim: set foldmarker=@{,@} foldlevel=0 foldmethod=marker : */
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment