From f0c49462c773613155bb40febb75f807336edb3b Mon Sep 17 00:00:00 2001 From: Mahmoud Date: Tue, 24 Sep 2019 12:43:49 -0400 Subject: adding traces generator --- .../post-traces-processing.cpp | 195 +++++++++++++++++++++ 1 file changed, 195 insertions(+) create mode 100644 src/trace-driven/traces-generator/traces-post-processing/post-traces-processing.cpp (limited to 'src/trace-driven/traces-generator/traces-post-processing/post-traces-processing.cpp') diff --git a/src/trace-driven/traces-generator/traces-post-processing/post-traces-processing.cpp b/src/trace-driven/traces-generator/traces-post-processing/post-traces-processing.cpp new file mode 100644 index 0000000..0dbb4e1 --- /dev/null +++ b/src/trace-driven/traces-generator/traces-post-processing/post-traces-processing.cpp @@ -0,0 +1,195 @@ +#include +#include +#include +#include +#include +#include +#include +using namespace std; + +struct threadblock_info +{ + bool initialized; + unsigned tb_id_x, tb_id_y, tb_id_z; + vector< vector< string > > warp_insts_array; + threadblock_info() { + initialized = false; + tb_id_x = tb_id_y = tb_id_z = 0; + } +}; + +void group_per_block(const char* filepath); +void group_per_core(const char* filepath); + +////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +int main(int argc, char** argv) +{ + + string kernellist_filepath; + bool is_per_core; + if(argc == 1) + { + cout << "File path is missing\n"; + return 0; + } else if(argc == 2) + { + kernellist_filepath = argv[1]; + is_per_core = true; + + } else if(argc == 3) { + kernellist_filepath = argv[1]; + is_per_core = bool(argv[2]); + } + else { + cout << "Too Many Arguemnts!\n"; + return 0; + } + + ifstream ifs; + ofstream ofs; + + ifs.open(kernellist_filepath.c_str()); + ofs.open((string(kernellist_filepath) + ".g").c_str()); + + if (!ifs.is_open()) { + cout << "Unable to open file: " < insts; + unsigned grid_dim_x, grid_dim_y, grid_dim_z, tb_dim_x, tb_dim_y, tb_dim_z; + unsigned tb_id_x, tb_id_y, tb_id_z, tb_id, warpid_tb; + string line; + stringstream ss; + string string1, string2; + bool found_grid_dim = false, found_block_dim = false; + + while(!ifs.eof()) { + getline(ifs, line); + + if (line.length() == 0 || line[0] == '#') { + ofs<>string1>>string2; + if(string1 == "grid" && string2 == "dim") { + sscanf(line.c_str(), "-grid dim = (%d,%d,%d)", &grid_dim_x, &grid_dim_y, &grid_dim_z); + found_grid_dim = true; + } + else if (string1 == "block" && string2 == "dim") { + sscanf(line.c_str(), "-block dim = (%d,%d,%d)", &tb_dim_x, &tb_dim_y, &tb_dim_z); + found_block_dim = true; + } + + if(found_grid_dim && found_block_dim) { + insts.resize(grid_dim_x*grid_dim_y*grid_dim_z); + for(unsigned i = 0; i>tb_id_x>>tb_id_y>>tb_id_z>>warpid_tb; + tb_id = tb_id_z * grid_dim_y * grid_dim_x + tb_id_y * grid_dim_x + tb_id_x; + if(!insts[tb_id].initialized) { + insts[tb_id].tb_id_x = tb_id_x; + insts[tb_id].tb_id_y = tb_id_y; + insts[tb_id].tb_id_z = tb_id_z; + insts[tb_id].initialized = true; + } + insts[tb_id].warp_insts_array[warpid_tb].push_back(line); + } + + } + + + for(unsigned i=0; i 0) { + ofs<