-
Notifications
You must be signed in to change notification settings - Fork 213
Expand file tree
/
Copy pathaccel-sim.cc
More file actions
231 lines (197 loc) · 8.17 KB
/
accel-sim.cc
File metadata and controls
231 lines (197 loc) · 8.17 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#include "accel-sim.h"
#include "accelsim_version.h"
accel_sim_framework::accel_sim_framework(std::string config_file,
std::string trace_file) {
std::cout << "Accel-Sim [build " << g_accelsim_version << "]";
m_gpgpu_context = new gpgpu_context();
// mimic argv
unsigned argc = 5;
const char *argv[] = {"accel-sim.out", "-config", config_file.c_str(),
"-trace", trace_file.c_str()};
gpgpu_sim *m_gpgpu_sim =
gpgpu_trace_sim_init_perf_model(argc, argv, m_gpgpu_context, &tconfig);
m_gpgpu_sim->init();
tracer = trace_parser(tconfig.get_traces_filename());
tconfig.parse_config();
init();
}
accel_sim_framework::accel_sim_framework(int argc, const char **argv) {
std::cout << "Accel-Sim [build " << g_accelsim_version << "]";
m_gpgpu_context = new gpgpu_context();
m_gpgpu_sim =
gpgpu_trace_sim_init_perf_model(argc, argv, m_gpgpu_context, &tconfig);
m_gpgpu_sim->init();
tracer = trace_parser(tconfig.get_traces_filename());
tconfig.parse_config();
init();
}
void accel_sim_framework::simulation_loop() {
// for each kernel
// load file
// parse and create kernel info
// launch
// while loop till the end of the end kernel execution
// prints stats
while (commandlist_index < commandlist.size() || !kernels_info.empty()) {
parse_commandlist();
// Launch all kernels within window that are on a stream that isn't already
// running
for (auto k : kernels_info) {
bool stream_busy = false;
for (auto s : busy_streams) {
if (s == k->get_cuda_stream_id()) stream_busy = true;
}
if (!stream_busy && m_gpgpu_sim->can_start_kernel() &&
!k->was_launched()) {
std::cout << "launching kernel name: " << k->get_name()
<< " uid: " << k->get_uid()
<< " cuda_stream_id: " << k->get_cuda_stream_id()
<< std::endl;
m_gpgpu_sim->launch(k);
k->set_launched();
busy_streams.push_back(k->get_cuda_stream_id());
}
}
unsigned finished_kernel_uid = simulate();
// cleanup finished kernel
if (finished_kernel_uid || m_gpgpu_sim->cycle_insn_cta_max_hit() ||
(!concurrent_kernel_sm && !m_gpgpu_sim->active())) {
cleanup(finished_kernel_uid);
}
if (sim_cycles) {
m_gpgpu_sim->update_stats();
m_gpgpu_context->print_simulation_time();
}
if (m_gpgpu_sim->cycle_insn_cta_max_hit()) {
printf(
"GPGPU-Sim: ** break due to reaching the maximum cycles (or "
"instructions) **\n");
fflush(stdout);
break;
}
}
}
void accel_sim_framework::parse_commandlist() {
// gulp up as many commands as possible - either cpu_gpu_mem_copy
// or kernel_launch - until the vector "kernels_info" has reached
// the window_size or we have read every command from commandlist
while (kernels_info.size() < window_size && commandlist_index < commandlist.size()) {
trace_kernel_info_t *kernel_info = NULL;
if (commandlist[commandlist_index].m_type == command_type::cpu_gpu_mem_copy) {
size_t addre, Bcount;
tracer.parse_memcpy_info(commandlist[commandlist_index].command_string, addre, Bcount);
std::cout << "launching memcpy command : "
<< commandlist[commandlist_index].command_string << std::endl;
m_gpgpu_sim->perf_memcpy_to_gpu(addre, Bcount);
commandlist_index++;
} else if (commandlist[commandlist_index].m_type == command_type::kernel_launch) {
// Read trace header info for window_size number of kernels
kernel_trace_t *kernel_trace_info =
tracer.parse_kernel_info(commandlist[commandlist_index].command_string);
kernel_info = create_kernel_info(kernel_trace_info, m_gpgpu_context,
&tconfig, &tracer);
kernels_info.push_back(kernel_info);
std::cout << "Header info loaded for kernel command : "
<< commandlist[commandlist_index].command_string << std::endl;
commandlist_index++;
} else {
// unsupported commands will fail the simulation
assert(0 && "Undefined Command");
}
}
}
void accel_sim_framework::cleanup(unsigned finished_kernel) {
trace_kernel_info_t *k = NULL;
unsigned long long finished_kernel_cuda_stream_id = -1;
for (unsigned j = 0; j < kernels_info.size(); j++) {
k = kernels_info.at(j);
if (k->get_uid() == finished_kernel ||
m_gpgpu_sim->cycle_insn_cta_max_hit() ||
(!concurrent_kernel_sm && !m_gpgpu_sim->active())) {
for (unsigned int l = 0; l < busy_streams.size(); l++) {
if (busy_streams.at(l) == k->get_cuda_stream_id()) {
finished_kernel_cuda_stream_id = k->get_cuda_stream_id();
busy_streams.erase(busy_streams.begin() + l);
break;
}
}
tracer.kernel_finalizer(k->get_trace_info());
delete k->entry();
delete k;
kernels_info.erase(kernels_info.begin() + j);
if (!m_gpgpu_sim->cycle_insn_cta_max_hit() && m_gpgpu_sim->active())
break;
}
}
assert(k);
m_gpgpu_sim->print_stats(finished_kernel_cuda_stream_id);
}
unsigned accel_sim_framework::simulate() {
unsigned finished_kernel_uid = 0;
do {
if (!m_gpgpu_sim->active()) break;
// performance simulation
if (m_gpgpu_sim->active()) {
m_gpgpu_sim->cycle();
sim_cycles = true;
m_gpgpu_sim->deadlock_check();
} else {
if (m_gpgpu_sim->cycle_insn_cta_max_hit()) {
m_gpgpu_context->the_gpgpusim->g_stream_manager
->stop_all_running_kernels();
break;
}
}
active = m_gpgpu_sim->active();
finished_kernel_uid = m_gpgpu_sim->finished_kernel();
} while (active && !finished_kernel_uid);
return finished_kernel_uid;
}
trace_kernel_info_t *accel_sim_framework::create_kernel_info(kernel_trace_t *kernel_trace_info,
gpgpu_context *m_gpgpu_context,
trace_config *config,
trace_parser *parser) {
gpgpu_ptx_sim_info info;
info.smem = kernel_trace_info->shmem;
info.regs = kernel_trace_info->nregs;
dim3 gridDim(kernel_trace_info->grid_dim_x, kernel_trace_info->grid_dim_y,
kernel_trace_info->grid_dim_z);
dim3 blockDim(kernel_trace_info->tb_dim_x, kernel_trace_info->tb_dim_y,
kernel_trace_info->tb_dim_z);
trace_function_info *function_info =
new trace_function_info(info, m_gpgpu_context);
function_info->set_name(kernel_trace_info->kernel_name.c_str());
trace_kernel_info_t *kernel_info = new trace_kernel_info_t(
gridDim, blockDim, function_info, parser, config, kernel_trace_info);
return kernel_info;
}
gpgpu_sim *accel_sim_framework::gpgpu_trace_sim_init_perf_model(
int argc, const char *argv[], gpgpu_context *m_gpgpu_context,
trace_config *m_config) {
srand(1);
print_splash();
option_parser_t opp = option_parser_create();
m_gpgpu_context->ptx_reg_options(opp);
m_gpgpu_context->func_sim->ptx_opcocde_latency_options(opp);
icnt_reg_options(opp);
m_gpgpu_context->the_gpgpusim->g_the_gpu_config =
new gpgpu_sim_config(m_gpgpu_context);
m_gpgpu_context->the_gpgpusim->g_the_gpu_config->reg_options(
opp); // register GPU microrachitecture options
m_config->reg_options(opp);
option_parser_cmdline(opp, argc, argv); // parse configuration options
fprintf(stdout, "GPGPU-Sim: Configuration options:\n\n");
option_parser_print(opp, stdout);
// Set the Numeric locale to a standard locale where a decimal point is a
// "dot" not a "comma" so it does the parsing correctly independent of the
// system environment variables
assert(setlocale(LC_NUMERIC, "C"));
m_gpgpu_context->the_gpgpusim->g_the_gpu_config->init();
m_gpgpu_context->the_gpgpusim->g_the_gpu = new trace_gpgpu_sim(
*(m_gpgpu_context->the_gpgpusim->g_the_gpu_config), m_gpgpu_context);
m_gpgpu_context->the_gpgpusim->g_stream_manager =
new stream_manager((m_gpgpu_context->the_gpgpusim->g_the_gpu),
m_gpgpu_context->func_sim->g_cuda_launch_blocking);
m_gpgpu_context->the_gpgpusim->g_simulation_starttime = time((time_t *)NULL);
return m_gpgpu_context->the_gpgpusim->g_the_gpu;
}