tapasco_benchmark.cpp 4.04 KB
Newer Older
1
/**
2
 *  @file	tapasco_benchmark.cpp
3
4
5
6
7
8
9
10
11
12
13
14
15
 *  @brief	Benchmark application that generates a JSON file containing
 *              parameters for design space exploration. Also gives an overview
 *              of system performance.
 *  @author	J. Korinth, TU Darmstadt (jk@esa.cs.tu-darmstadt.de)
 **/
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <chrono>
#include <ctime>
#include <vector>
#include <sys/utsname.h>
16
#include <tapasco_api.hpp>
17
18
19
20
21
22
23
#include <platform_api.h>
#include "CumulativeAverage.hpp"
#include "TransferSpeed.hpp"
#include "InterruptLatency.hpp"
#include "json11.hpp"

using namespace std;
24
using namespace tapasco;
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using namespace json11;

struct transfer_speed_t {
  size_t chunk_sz;
  double speed_r;
  double speed_w;
  double speed_rw;
  Json to_json() const { return Json::object {
      {"Chunk Size", static_cast<int>(chunk_sz)},
      {"Read", speed_r},
      {"Write", speed_w},
      {"ReadWrite", speed_rw}
    }; }
};

Jens Korinth's avatar
Jens Korinth committed
40
41
42
43
44
45
46
47
struct interrupt_latency_t {
  size_t cycle_count;
  double latency_us;
  Json to_json() const { return Json::object {
      {"Cycle Count", static_cast<double>(cycle_count)},
      {"Latency", latency_us}
    }; }
};
48
49

int main(int argc, const char *argv[]) {
50
51
52
  Tapasco tapasco;
  TransferSpeed tp { tapasco };
  InterruptLatency il { tapasco };
53
54
55
  struct utsname uts;
  uname(&uts);
  vector<Json> speed;
Jens Korinth's avatar
Jens Korinth committed
56
57
58
  //struct transfer_speed_t ts;
  vector<Json> latency;
  struct interrupt_latency_t ls;
59
60
61

  string platform = "vc709";
  if (argc < 2) {
62
    if (getenv("TAPASCO_PLATFORM") == NULL) {
63
      char n[256] { "" };
64
      cout << "Environment variable TAPASCO_PLATFORM is not set, guessing Platform ..." << endl;
65
66
67
68
69
70
71
72
73
74
      if (gethostname(n, 255))
        cerr << "Could not get host name, guessing vc709 Platform" << endl;
      else {
        cout << "Host name: " << n << endl;
	if (string(n).compare("zed") == 0 || string(n).compare("zedboard"))
	  platform = "zedboard";
	if (string(n).compare("zc706") == 0)
	  platform = "zc706";
	cout << "Guessing " << platform << " Platform" << endl;
      }
75
    } else platform = getenv("TAPASCO_PLATFORM");
76
77
78
79
  }

  // measure for chunk sizes 2^8 - 2^31 (2GB) bytes
  for (int i = 8; i < 32; ++i) {
Jens Korinth's avatar
Jens Korinth committed
80
    /*ts.chunk_sz = 1 << i;
81
82
83
84
85
86
87
88
89
    ts.speed_r  = tp(ts.chunk_sz, TransferSpeed::OP_COPYFROM);
    ts.speed_w  = tp(ts.chunk_sz, 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:" 
         << " read " << ts.speed_r << " MiB/s" 
         << ", write: " << ts.speed_w << " MiB/s"
	 << ", r/w: " << ts.speed_rw << " MiB/s"
	 << endl;
    Json json = ts.to_json();
Jens Korinth's avatar
Jens Korinth committed
90
    speed.push_back(json);*/
91
92
  }

Jens Korinth's avatar
Jens Korinth committed
93
94
95
96
97
98
99
  // measure average job roundtrip latency for clock cycles counts
  // between 2^0 and 2^31
  for (size_t i = 0; i < 32; ++i) {
    ls.cycle_count = 1UL << i;
    ls.latency_us  = il.atcycles(ls.cycle_count);
    cout << "Latency @ " << ls.cycle_count << "cc runtime: " << ls.latency_us << " us" << endl;
  }
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118

  // record current time
  time_t tt = chrono::system_clock::to_time_t(chrono::system_clock::now());
  tm tm = *localtime(&tt);
  stringstream str;
  str << put_time(&tm, "%Y-%m-%d %H:%M:%S");

  // build JSON object
  Json benchmark = Json::object {
    {"Timestamp", str.str()},
    {"Host", Json::object {
        {"Operating System", uts.sysname},
	{"Node", uts.nodename},
	{"Release", uts.release},
	{"Version", uts.version},
	{"Machine", uts.machine}
      }
    },
    {"Transfer Speed", speed},
Jens Korinth's avatar
Jens Korinth committed
119
    {"Interrupt Latency", latency},
120
    {"Library Versions", Json::object {
Jens Korinth's avatar
Jens Korinth committed
121
        {"Tapasco API",  tapasco::tapasco_version()},
122
123
124
125
126
127
128
        {"Platform API", platform::platform_version()}
      }
    }
  };
  
  // dump it
  stringstream ss;
129
  ss << getenv("TAPASCO_HOME") << "/platform/" << platform << "/" << platform << ".benchmark";
130
131
132
133
134
135
  cout << "Dumping benchmark JSON to " << (argc >= 2 ? argv[1] : ss.str()) << endl;
  ofstream f(argc >= 2 ? argv[1] : ss.str());
  f << benchmark.dump();
  f.close();
}
/* vim: set foldmarker=@{,@} foldlevel=0 foldmethod=marker : */