-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathcodes-iolang-wrkld.c
More file actions
264 lines (237 loc) · 7.78 KB
/
codes-iolang-wrkld.c
File metadata and controls
264 lines (237 loc) · 7.78 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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
/*
* Copyright (C) 2013 University of Chicago.
* See COPYRIGHT notice in top-level directory.
*
*/
#include <assert.h>
#include <ross.h>
#include "src/iokernellang/CodesIOKernelTypes.h"
#include "src/iokernellang/CodesIOKernelParser.h"
#include "src/iokernellang/CodesIOKernelContext.h"
#include "src/iokernellang/codesparser.h"
#include "src/iokernellang/CodesKernelHelpers.h"
#include "src/iokernellang/codeslexer.h"
#include "codes/codes-workload.h"
#include "codes/quickhash.h"
#define RANK_HASH_TABLE_SIZE 400
/* This file implements the CODES workload API for the I/O kernel language of
the BG/P storage model */
static void * iolang_io_workload_read_config(
ConfigHandle * handle,
char const * section_name,
char const * annotation,
int num_ranks);
/* load the workload file */
static int iolang_io_workload_load(const void* params, int app_id, int rank);
/* get next operation */
static void iolang_io_workload_get_next(int app_id, int rank, struct codes_workload_op *op);
/* mapping from bg/p operation enums to CODES workload operations enum */
static int convertTypes(int inst);
static int hash_rank_compare(void *key, struct qhash_head *link);
typedef struct codes_iolang_wrkld_state_per_rank codes_iolang_wrkld_state_per_rank;
static struct qhash_table *rank_tbl = NULL;
static int rank_tbl_pop = 0;
static int nranks = -1;
/* implements the codes workload method */
struct codes_workload_method iolang_workload_method =
{
.method_name = "iolang_workload",
.codes_workload_read_config = iolang_io_workload_read_config,
.codes_workload_load = iolang_io_workload_load,
.codes_workload_get_next = iolang_io_workload_get_next,
};
/* state of the I/O workload that each simulated compute node/MPI rank will have */
struct codes_iolang_wrkld_state_per_rank
{
int rank;
CodesIOKernelContext codes_context;
CodesIOKernel_pstate * codes_pstate;
codeslang_inst next_event;
struct qhash_head hash_link;
iolang_workload_info task_info;
};
static void * iolang_io_workload_read_config(
ConfigHandle * handle,
char const * section_name,
char const * annotation,
int num_ranks)
{
iolang_params *p = malloc(sizeof(*p));
assert(p);
p->num_cns = -1;
p->use_relpath = 1;
p->io_kernel_meta_path[0] = '\0';
p->io_kernel_path[0] = '\0';
int rc = configuration_get_value_relpath(handle, section_name,
"io_kernel_meta_path", annotation, p->io_kernel_meta_path,
MAX_NAME_LENGTH_WKLD);
assert(rc > 0);
rc = configuration_get_value_int(handle, section_name, "num_ranks",
annotation, &p->num_cns);
if (rc != 0)
p->num_cns = num_ranks;
return p;
}
/* loads the workload file for each simulated MPI rank/ compute node LP */
int iolang_io_workload_load(const void* params, int app_id, int rank)
{
int t = -1;
iolang_params* i_param = (struct iolang_params*)params;
APP_ID_UNSUPPORTED(app_id, "iolang")
/* we have to get the number of compute nodes/ranks from the bg/p model parameters
* because the number of ranks are specified in the iolang config file not the
* workload files */
if(nranks == -1)
nranks = i_param->num_cns;
codes_iolang_wrkld_state_per_rank* wrkld_per_rank = NULL;
if(!rank_tbl)
{
rank_tbl = qhash_init(hash_rank_compare, quickhash_32bit_hash, RANK_HASH_TABLE_SIZE);
if(!rank_tbl)
{
return -1;
}
}
wrkld_per_rank = (codes_iolang_wrkld_state_per_rank*)malloc(sizeof(*wrkld_per_rank));
if(!wrkld_per_rank)
return -1;
wrkld_per_rank->codes_pstate = CodesIOKernel_pstate_new();
wrkld_per_rank->rank = rank;
t = codes_kernel_helper_bootstrap(i_param->io_kernel_path,
i_param->io_kernel_meta_path,
rank,
nranks,
i_param->use_relpath,
&(wrkld_per_rank->codes_context),
&(wrkld_per_rank->codes_pstate),
&(wrkld_per_rank->task_info),
&(wrkld_per_rank->next_event));
qhash_add(rank_tbl, &(wrkld_per_rank->rank), &(wrkld_per_rank->hash_link));
rank_tbl_pop++;
return t;
}
/* Maps the enum types from I/O language to the CODES workload API */
static int convertTypes(int inst)
{
switch(inst)
{
case CL_WRITEAT: /* write to file */
return CODES_WK_WRITE;
case CL_READAT:
return CODES_WK_READ;
case CL_CLOSE:
return CODES_WK_CLOSE; /* close the file */
case CL_OPEN:
return CODES_WK_OPEN; /* open file */
case CL_SYNC:
return CODES_WK_BARRIER; /* barrier in CODES workload is similar to sync in I/O lang? */
case CL_SLEEP:
return CODES_WK_DELAY; /* sleep or delay */
case CL_EXIT:
return CODES_WK_END; /* end of the operations/ no more operations in file */
case CL_DELETE:
return CODES_WK_IGNORE;
case CL_GETRANK:
return CODES_WK_IGNORE; /* defined in I/O lang but not in workloads API*/
case CL_GETSIZE:
return CODES_WK_IGNORE; /* defined in I/O lang but not in workload API */
default:
return CODES_WK_IGNORE;
}
}
/* Gets the next operation specified in the workload file for the simulated MPI rank */
void iolang_io_workload_get_next(int app_id, int rank, struct codes_workload_op *op)
{
(void)app_id;
/* If the number of simulated compute nodes per LP is initialized only then we get the next operation
else we return an error code may be? */
codes_iolang_wrkld_state_per_rank* next_wrkld;
struct qhash_head *hash_link = NULL;
hash_link = qhash_search(rank_tbl, &rank);
if(!hash_link)
{
op->op_type = CODES_WK_END;
return;
}
next_wrkld = qhash_entry(hash_link, struct codes_iolang_wrkld_state_per_rank, hash_link);
int type = codes_kernel_helper_parse_input(next_wrkld->codes_pstate, &(next_wrkld->codes_context),&(next_wrkld->next_event));
op->op_type = (enum codes_workload_op_type) convertTypes(type);
if (op->op_type == CODES_WK_IGNORE)
return;
switch(op->op_type)
{
case CODES_WK_WRITE:
{
op->u.write.file_id = (next_wrkld->next_event).var[0];
op->u.write.offset = (next_wrkld->next_event).var[2];
op->u.write.size = (next_wrkld->next_event).var[1];
}
break;
case CODES_WK_DELAY:
{
/* io language represents delays in nanoseconds */
op->u.delay.seconds = (double)(next_wrkld->next_event).var[0] / (1000 * 1000 * 1000);
}
break;
case CODES_WK_END:
{
/* delete the hash entry*/
qhash_del(hash_link);
rank_tbl_pop--;
/* if no more entries are there, delete the hash table */
if(!rank_tbl_pop)
{
qhash_finalize(rank_tbl);
rank_tbl = NULL;
}
}
break;
case CODES_WK_CLOSE:
{
op->u.close.file_id = (next_wrkld->next_event).var[0];
}
break;
case CODES_WK_BARRIER:
{
op->u.barrier.count = nranks;
op->u.barrier.root = 0;
}
break;
case CODES_WK_OPEN:
{
op->u.open.file_id = (next_wrkld->next_event).var[0];
op->u.open.create_flag = 1;
}
break;
case CODES_WK_READ:
{
op->u.read.file_id = (next_wrkld->next_event).var[0];
op->u.read.offset = (next_wrkld->next_event).var[2];
op->u.read.size = (next_wrkld->next_event).var[1];
}
break;
default:
{
// Return error code
//printf("\n Invalid operation specified %d ", op->op_type);
}
}
return;
}
static int hash_rank_compare(void *key, struct qhash_head *link)
{
int *in_rank = (int *)key;
codes_iolang_wrkld_state_per_rank *tmp;
tmp = qhash_entry(link, codes_iolang_wrkld_state_per_rank, hash_link);
if (tmp->rank == *in_rank)
return 1;
return 0;
}
/*
* Local variables:
* c-indent-level: 4
* c-basic-offset: 4
* End:
*
* vim: ft=c ts=8 sts=4 sw=4 expandtab
*/