codes-iolang-wrkld.c 6.85 KB
Newer Older
1 2 3 4 5 6
/*
 * Copyright (C) 2013 University of Chicago.
 * See COPYRIGHT notice in top-level directory.
 *
 */
#include <ross.h>
7 8 9 10 11 12
#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"
13 14

#include "codes/codes-workload.h"
15
#include "src/workload/codes-workload-method.h"
16 17 18
#include "codes/quickhash.h"

#define RANK_HASH_TABLE_SIZE 400 
19 20 21 22 23

/* This file implements the CODES workload API for the I/O kernel language of
the BG/P storage model */

/* load the workload file */
24
int iolang_io_workload_load(const char* params, int app_id, int rank);
25 26

/* get next operation */
27
void iolang_io_workload_get_next(int app_id, int rank, struct codes_workload_op *op);
28 29 30

/* mapping from bg/p operation enums to CODES workload operations enum */
static int convertTypes(int inst);
31
static int hash_rank_compare(void *key, struct qhash_head *link);
32

33
typedef struct codes_iolang_wrkld_state_per_rank codes_iolang_wrkld_state_per_rank;
34 35 36
static struct qhash_table *rank_tbl = NULL;
static int rank_tbl_pop = 0;
int num_ranks = -1;
37 38

/* implements the codes workload method */
39
struct codes_workload_method iolang_workload_method =
40
{
41 42 43
    .method_name = "iolang_workload",
    .codes_workload_load = iolang_io_workload_load,
    .codes_workload_get_next = iolang_io_workload_get_next,
44 45 46
};

/* state of the I/O workload that each simulated compute node/MPI rank will have */
47
struct codes_iolang_wrkld_state_per_rank
48
{
49
    int rank;
50 51 52
    CodesIOKernelContext codes_context;
    CodesIOKernel_pstate * codes_pstate;
    codeslang_inst next_event;
53
    struct qhash_head hash_link;
54
    iolang_workload_info task_info;
55 56 57
};

/* loads the workload file for each simulated MPI rank/ compute node LP */
58
int iolang_io_workload_load(const char* params, int app_id, int rank)
59 60
{
    int t = -1;
61
    iolang_params* i_param = (struct iolang_params*)params;
62

63 64
    APP_ID_UNSUPPORTED(app_id, "iolang")

65
    /* we have to get the number of compute nodes/ranks from the bg/p model parameters
66
     * because the number of ranks are specified in the iolang config file not the
67 68
     * workload files */
    if(num_ranks == -1)
69
        num_ranks = i_param->num_cns;
70

71
    codes_iolang_wrkld_state_per_rank* wrkld_per_rank = NULL;
72
    if(!rank_tbl)
73
    {
74 75 76 77 78
	  rank_tbl = qhash_init(hash_rank_compare, quickhash_32bit_hash, RANK_HASH_TABLE_SIZE);
	  if(!rank_tbl)
	  {
		  return -1;
	  }
79
    }
80
    wrkld_per_rank = (codes_iolang_wrkld_state_per_rank*)malloc(sizeof(*wrkld_per_rank));
81 82 83 84 85
    if(!wrkld_per_rank)
	    return -1;

    wrkld_per_rank->codes_pstate = CodesIOKernel_pstate_new();
    wrkld_per_rank->rank = rank;
86 87
    t = codes_kernel_helper_bootstrap(i_param->io_kernel_path, 
				      i_param->io_kernel_meta_path,
88
        			      rank, 
89
                          num_ranks,
90
                      i_param->use_relpath,
91 92 93 94 95 96
				      &(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++;
97 98 99 100 101 102 103 104 105
    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 */
106 107 108
	    return CODES_WK_WRITE;
	case CL_READAT:
	    return CODES_WK_READ;
109
	case CL_CLOSE:
110
	    return CODES_WK_CLOSE; /* close the file */
111
	case CL_OPEN:
112
	    return CODES_WK_OPEN; /* open file */
113
	case CL_SYNC:
114
	    return CODES_WK_BARRIER; /* barrier in CODES workload is similar to sync in I/O lang? */
115
	case CL_SLEEP:
116
	    return CODES_WK_DELAY; /* sleep or delay */
117
	case CL_EXIT:
118
	    return CODES_WK_END; /* end of the operations/ no more operations in file */
119
	case CL_DELETE:
Jonathan Jenkins's avatar
Jonathan Jenkins committed
120
	    return CODES_WK_IGNORE;
121
	case CL_GETRANK: 
Jonathan Jenkins's avatar
Jonathan Jenkins committed
122
	    return CODES_WK_IGNORE; /* defined in I/O lang but not in workloads API*/
123
	case CL_GETSIZE: 
Jonathan Jenkins's avatar
Jonathan Jenkins committed
124
	    return CODES_WK_IGNORE; /* defined in I/O lang but not in workload API */
125
	default:
Jonathan Jenkins's avatar
Jonathan Jenkins committed
126
	   return CODES_WK_IGNORE;
127
    } 
128 129
}

130
/* Gets the next operation specified in the workload file for the simulated MPI rank */
131
void iolang_io_workload_get_next(int app_id, int rank, struct codes_workload_op *op)
132 133 134
{
    /* 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?  */
135
        codes_iolang_wrkld_state_per_rank* next_wrkld;
136 137 138 139 140 141 142
	struct qhash_head *hash_link = NULL; 
	hash_link = qhash_search(rank_tbl, &rank);
	if(!hash_link)
	{
		op->op_type = CODES_WK_END;
		return;
	}
143
	next_wrkld = qhash_entry(hash_link, struct codes_iolang_wrkld_state_per_rank, hash_link);
144 145

	int type = codes_kernel_helper_parse_input(next_wrkld->codes_pstate, &(next_wrkld->codes_context),&(next_wrkld->next_event));
146
        op->op_type = (enum codes_workload_op_type) convertTypes(type);
Elsa Gonsiorowski (Uranus)'s avatar
merge  
Elsa Gonsiorowski (Uranus) committed
147 148
        if (op->op_type == CODES_WK_IGNORE)
            return;
149 150 151 152
	switch(op->op_type)
	{
	    case CODES_WK_WRITE:
	    {
153
                op->u.write.file_id = (next_wrkld->next_event).var[0];
154
		op->u.write.offset = (next_wrkld->next_event).var[2];
155
		op->u.write.size = (next_wrkld->next_event).var[1];
156 157 158 159
	    }
	    break;
	    case CODES_WK_DELAY:
	    {
160 161
            /* io language represents delays in nanoseconds */
            op->u.delay.seconds = (double)(next_wrkld->next_event).var[0] / (1000 * 1000 * 1000);
162 163 164 165
	    }
	    break;
	    case CODES_WK_END:
	    {
166 167 168 169 170 171
		/* 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)
172 173 174 175
          {
            qhash_finalize(rank_tbl);
            rank_tbl = NULL;
          }
176 177 178 179
	    }
	    break;
	    case CODES_WK_CLOSE:
	    {
180
	        op->u.close.file_id = (next_wrkld->next_event).var[0];
181 182 183 184
	    }
	    break;
	    case CODES_WK_BARRIER:
	    {
185
	       op->u.barrier.count = num_ranks;
186 187 188 189 190
	       op->u.barrier.root = 0;
	    }
	    break;
	    case CODES_WK_OPEN:
	    {
191
	        op->u.open.file_id =  (next_wrkld->next_event).var[0];
192
            op->u.open.create_flag = 1;
193 194 195 196
	    }
	    break;
	    case CODES_WK_READ:
	    {
197
                op->u.read.file_id = (next_wrkld->next_event).var[0];
198
		op->u.read.offset = (next_wrkld->next_event).var[2];
199
		op->u.read.size = (next_wrkld->next_event).var[1];
200 201 202 203
	    }
	    break;
	    default:
	     {
Jonathan Jenkins's avatar
Jonathan Jenkins committed
204

205 206 207 208 209 210
		// Return error code
		//printf("\n Invalid operation specified %d ", op->op_type);
	     }
	}
    return;
}
211 212 213 214

static int hash_rank_compare(void *key, struct qhash_head *link)
{
    int *in_rank = (int *)key;
215
    codes_iolang_wrkld_state_per_rank *tmp;
216

217
    tmp = qhash_entry(link, codes_iolang_wrkld_state_per_rank, hash_link);
218 219 220 221 222 223
    if (tmp->rank == *in_rank)
	return 1;

    return 0;
}

Jonathan Jenkins's avatar
Jonathan Jenkins committed
224 225 226 227 228 229 230 231
/*
 * Local variables:
 *  c-indent-level: 4
 *  c-basic-offset: 4
 * End:
 *
 * vim: ft=c ts=8 sts=4 sw=4 expandtab
 */