-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxml_parser.cc
112 lines (100 loc) · 4.55 KB
/
xml_parser.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// xml_parser.cc
#include "xml_parser.h"
#include <iostream>
#include <cstdlib>
enum op_type op_string_to_enmu(std::string string){
if (string == "s") {
return op_type::SEND;
} else if (string == "r") {
return op_type::RECV;
} else if (string == "re") {
return op_type::REDUCE;
} else if (string == "rrc") {
return op_type::RECV_REDUCE_COPY;
} else if (string == "rrs"){
return op_type::RECV_REDUCE_SEND;
} else if(string == "rcs") {
return op_type::RECV_COPY_SEND;
} else if (string == "rrcs") {
return op_type::RECV_REDUCE_COPY_SEND;
} else if(string == "nop") {
return op_type::NOP;
}
return op_type::OP_UNKNOWN;
}
enum buffer_type buffer_string_to_enmu(std::string string){
if (string == "i") {
return buffer_type::INPUT;
} else if (string == "o") {
return buffer_type::OUTPUT;
} else if (string == "s") {
return buffer_type::SCRATCH;
}
return buffer_type::BUFFER_UNKNOWN;
}
void XMLParser::parseXMLAndFillStructs(const std::string& filename) {
xmlDocPtr doc = xmlReadFile(filename.c_str(), NULL, 0);
if (!doc) {
std::cerr << "Failed to parse XML file " << filename << std::endl;
return;
}
xmlNode* root_element = xmlDocGetRootElement(doc);
this->nchunksperloop = std::atoi((const char*)xmlGetProp(root_element, (const xmlChar*)"nchunksperloop"));
for (xmlNode* node = root_element->children; node; node = node->next) {
if (node->type == XML_ELEMENT_NODE && strcmp((const char*)node->name, "gpu") == 0) {
parseRank(node);
}
}
xmlFreeDoc(doc);
xmlCleanupParser();
}
void XMLParser::parseRank(xmlNode* node) {
auto rank = std::make_shared<Rank>();
rank->id = std::atoi((const char*)xmlGetProp(node, (const xmlChar*)"id"));
rank->i_chunks = std::atoi((const char*)xmlGetProp(node, (const xmlChar*)"i_chunks"));
rank->o_chunks = std::atoi((const char*)xmlGetProp(node, (const xmlChar*)"o_chunks"));
rank->s_chunks = std::atoi((const char*)xmlGetProp(node, (const xmlChar*)"s_chunks"));
ranks.push_back(rank);
for (xmlNode* tb_node = node->children; tb_node; tb_node = tb_node->next) {
if (tb_node->type == XML_ELEMENT_NODE && strcmp((const char*)tb_node->name, "tb") == 0) {
parseThreadBlock(tb_node, rank);
}
}
}
void XMLParser::parseThreadBlock(xmlNode* node, std::shared_ptr<Rank>& rank) {
auto tb = std::make_shared<ThreadBlock>();
tb->id = std::atoi((const char*)xmlGetProp(node, (const xmlChar*)"id"));
tb->send = std::atoi((const char*)xmlGetProp(node, (const xmlChar*)"send"));
tb->recv = std::atoi((const char*)xmlGetProp(node, (const xmlChar*)"recv"));
tb->chan = std::atoi((const char*)xmlGetProp(node, (const xmlChar*)"chan"));
rank->tbs.push_back(tb);
for (xmlNode* step_node = node->children; step_node; step_node = step_node->next) {
if (step_node->type == XML_ELEMENT_NODE && strcmp((const char*)step_node->name, "step") == 0) {
parseStep(step_node, tb);
}
}
}
void XMLParser::parseStep(xmlNode* node, std::shared_ptr<ThreadBlock>& tb) {
auto step = std::make_shared<Step>();
step->s = std::atoi((const char*)xmlGetProp(node, (const xmlChar*)"s"));
step->type = op_string_to_enmu((const char*)xmlGetProp(node, (const xmlChar*)"type"));
step->srcbuf = buffer_string_to_enmu((const char*)xmlGetProp(node, (const xmlChar*)"srcbuf"));
step->srcoff = std::atoi((const char*)xmlGetProp(node, (const xmlChar*)"srcoff"));
step->dstbuf = buffer_string_to_enmu((const char*)xmlGetProp(node, (const xmlChar*)"dstbuf"));
step->dstoff = std::atoi((const char*)xmlGetProp(node, (const xmlChar*)"dstoff"));
step->cnt = std::atoi((const char*)xmlGetProp(node, (const xmlChar*)"cnt"));
step->depid = std::atoi((const char*)xmlGetProp(node, (const xmlChar*)"depid"));
step->deps = std::atoi((const char*)xmlGetProp(node, (const xmlChar*)"deps"));
step->hasdep = std::atoi((const char*)xmlGetProp(node, (const xmlChar*)"hasdep"));
tb->steps.push_back(step);
}
void XMLParser::displayRanks() {
for (const auto& rank : ranks) {
std::cout << "Rank ID: " << rank->id << "\n";
// Display more details as needed
const auto& step = rank->tbs[0]->steps[1];
std::cout << "Step: " << step->s << " " << step->type << " " << step->srcbuf << " "
<< step->srcoff << " " << step->dstbuf << " " << step->dstoff << " " << step->cnt << " "
<< step->depid << " " << step->deps << " " << step->hasdep << std::endl;
}
}