-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig_reader.cpp
More file actions
137 lines (131 loc) · 5.55 KB
/
Copy pathconfig_reader.cpp
File metadata and controls
137 lines (131 loc) · 5.55 KB
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
//
// Created by 徐向荣 on 2022/6/2.
//
#include "config_reader.h"
#include <iostream>
#include <fstream>
#include <cassert>
#include <algorithm>
#include <queue>
#include <sstream>
void gpu_config::read_config(const std::string &file_s) {
std::ifstream file(file_s);
std::string single_line;
std::string comments = "//";
std::string tmp_s = "##";
std::string end_config = "####";
while (std::getline(file, single_line)) {
if (single_line.compare(0, comments.size(), comments) == 0) {
continue;
}
std::string key, value;
config_split(single_line, ":", key, value);
if (key == "##pipeline_units") {
std::getline(file, single_line);
config_split(single_line, ":", key, value);
while (single_line.compare(0, tmp_s.size(), tmp_s) != 0) {
m_sm_pipeline_units.insert(std::pair<std::string, int>(key, stoi(value)));
// std::cout << key << " " << value << std::endl;
std::getline(file, single_line);
config_split(single_line, ":", key, value);
}
}
if (key == "##compute_capability") {
std::getline(file, single_line);
config_split(single_line, ":", key, value);
while (single_line.compare(0, tmp_s.size(), tmp_s) != 0) {
m_compute_capability.insert(std::pair<std::string, int>(key, stoi(value)));
// std::cout << key << " " << value << std::endl;
std::getline(file, single_line);
config_split(single_line, ":", key, value);
}
}
if (key == "##l1_cache_config") {
std::getline(file, single_line);
config_split(single_line, ":", key, value);
while (single_line.compare(0, tmp_s.size(), tmp_s) != 0) {
l1_cache_config.insert(std::pair<std::string, std::string>(key, value));
// std::cout << key << " " << value << std::endl;
std::getline(file, single_line);
config_split(single_line, ":", key, value);
}
}
if (key == "##l2_cache_config") {
std::getline(file, single_line);
config_split(single_line, ":", key, value);
while (single_line.compare(0, tmp_s.size(), tmp_s) != 0) {
l2_cache_config.insert(std::pair<std::string, std::string>(key, value));
// std::cout << key << " " << value << std::endl;
std::getline(file, single_line);
config_split(single_line, ":", key, value);
}
}
if (key == "##gpu_isa_latency") {
while (std::getline(file, single_line)) {
if (single_line[0] == '/') {
continue; // "/..." => 注释;
}
if (single_line.compare(0, end_config.size(), end_config) == 0) {
break; // if "####" end;
}
if (single_line.length() > 1 && single_line.find(tmp_s) == 0) {
continue; // "##..." => 注释, but "####" not.
}
std::istringstream is(single_line); // String is = single_line;
std::string str;
std::queue<std::string> tmp_str; //queue
while (is >> str) { // (is == abc cde def) => 分别将abc、cde、def入栈;
tmp_str.push(str);
}
std::string opcode = tmp_str.front(); // 如上,则 opcode = "abc";
tmp_str.pop(); // then pop "abc";
int latency; // 延迟
std::string latency_t = (tmp_str.front()); // String latency_t = "cde";
if (latency_t == "-") {
latency = -1;
} else {
latency = std::stoi(tmp_str.front()); // string "cde" to int
}
tmp_str.pop(); // then pop "cde";
std::string unit = tmp_str.front(); // String unit = "def";
std::tuple<int, std::string> tuple_t(latency, unit);
gpu_isa_latency.insert(std::pair<std::string, std::tuple<int, std::string> >(opcode, tuple_t));
// std::cout << opcode << " " << latency << unit << std::endl;
}
key = end_config;
}
if (key == "##crossbar_config") {
std::getline(file, single_line);
config_split(single_line, ":", key, value);
while (single_line.compare(0, tmp_s.size(), tmp_s) != 0) {
crossbar_config.insert(std::pair<std::string, int>(key, std::stoi(value)));
// std::cout << key << " " << value << std::endl;
std::getline(file, single_line);
config_split(single_line, ":", key, value);
} //循环读入
}
if(key!=end_config){
m_gpu_config.insert(std::pair<std::string, std::string>(key, value));
}
// std::cout << key << " " << value << std::endl;
}
file.close();
}
void
gpu_config::config_split(const std::string &str, const std::string &pattern, std::string &str1, std::string &str2) {
std::string strs = str + pattern;
std::size_t pos = strs.find(pattern);
std::size_t size = strs.size();
bool bStop = false;
while (pos != std::string::npos) {
if (!bStop) {
str1 = strs.substr(0, pos);
bStop = true;
} else {
str2 = strs.substr(0, pos);
return;
}
strs = strs.substr(pos + 1, size);
pos = strs.find(pattern);
}
}