model-net.h 9.05 KB
Newer Older
1
/*
Philip Carns's avatar
Philip Carns committed
2
 * Copyright (C) 2013 University of Chicago.
3
 * See COPYRIGHT notice in top-level directory.
Philip Carns's avatar
Philip Carns committed
4
 *
5 6 7 8 9 10
 */

#ifndef MODELNET_H
#define MODELNET_H

#include "ross.h"
11
#include "codes/lp-type-lookup.h"
12
#include "codes/configuration.h"
13
#include "codes/lp-io.h"
14
#include <stdint.h>
15

16 17
#define PULL_MSG_SIZE 128

18
#define MAX_NAME_LENGTH 256
19 20
#define CATEGORY_NAME_MAX 16
#define CATEGORY_MAX 12
21

22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
/* HACK: there is currently no scheduling fidelity across multiple
 * model_net_event calls. Hence, problems arise when some LP sends multiple
 * messages as part of an event and expects FCFS ordering. A proper fix which
 * involves model-net LP-level scheduling of requests is ideal, but not 
 * feasible for now (would basically have to redesign model-net), so expose
 * explicit start-sequence and stop-sequence markers as a workaround */
extern int in_sequence;
extern tw_stime mn_msg_offset;
#define MN_START_SEQ() do {\
    in_sequence = 1; \
    mn_msg_offset = 0.0; \
} while (0)
#define MN_END_SEQ() do {\
    in_sequence = 0;\
} while (0)


39
typedef struct simplenet_param simplenet_param;
40
typedef struct simplewan_param simplewan_param;
41 42
typedef struct dragonfly_param dragonfly_param;
typedef struct torus_param torus_param;
Philip Carns's avatar
Philip Carns committed
43
typedef struct loggp_param loggp_param;
44
typedef struct mn_stats mn_stats;
45

46 47 48 49 50 51 52 53 54 55 56 57
// use the X-macro to get types and names rolled up into one structure
// format: { enum vals, config name, internal lp name, lp method struct}
// last value is sentinel
#define NETWORK_DEF \
    X(SIMPLENET, "modelnet_simplenet", "simplenet", &simplenet_method)\
    X(SIMPLEWAN, "modelnet_simplewan", "simplewan", &simplewan_method)\
    X(TORUS,     "modelnet_torus",     "torus",     &torus_method)\
    X(DRAGONFLY, "modelnet_dragonfly", "dragonfly", &dragonfly_method)\
    X(LOGGP,     "modelnet_loggp",     "loggp",     &loggp_method)\
    X(MAX_NETS,  NULL,                 NULL,        NULL)

#define X(a,b,c,d) a,
58 59
enum NETWORKS
{
60
    NETWORK_DEF
61
};
62 63 64 65 66 67
#undef X

// network identifiers (both the config lp names and the model-net internal
// names)
extern char * model_net_lp_config_names[];
extern char * model_net_method_names[];
68

69 70 71 72 73 74 75 76 77 78 79 80 81
/* data structure for tracking network statistics */
struct mn_stats
{
    char category[CATEGORY_NAME_MAX];
    long send_count;
    long send_bytes;
    tw_stime send_time;
    long recv_count;
    long recv_bytes;
    tw_stime recv_time;
    long max_event_size;
};

Philip Carns's avatar
Philip Carns committed
82 83 84 85 86 87
/* structs for initializing a network/ specifying network parameters */
struct loggp_param
{
  char* net_config_file; /* file with loggp parameter table */
};

88 89 90 91 92 93 94 95
/* structs for initializing a network/ specifying network parameters */
struct simplenet_param
{
  double net_startup_ns; /*simplenet startup cost*/
  double net_bw_mbps; /*Link bandwidth per byte*/
  int num_nics;
};

96 97 98 99 100 101
struct simplewan_param
{
    char bw_filename[MAX_NAME_LENGTH];
    char startup_filename[MAX_NAME_LENGTH];
};

102 103 104
struct dragonfly_param
{
  int num_routers; /*Number of routers in a group*/
105 106 107 108 109 110 111 112
  double local_bandwidth;/* bandwidth of the router-router channels within a group */
  double global_bandwidth;/* bandwidth of the inter-group router connections */
  double cn_bandwidth;/* bandwidth of the compute node channels connected to routers */
  int num_vcs; /* number of virtual channels */
  int local_vc_size; /* buffer size of the router-router channels */
  int global_vc_size; /* buffer size of the global channels */
  int cn_vc_size; /* buffer size of the compute node channels */
  short routing; /* minimal or non-minimal routing */
113 114 115 116
};

struct torus_param
{
117
  int n_dims; /*Dimension of the torus network, 5-D, 7-D or any other*/
118
  int* dim_length; /*Length of each torus dimension*/
119 120 121 122
  double link_bandwidth;/* bandwidth for each torus link */
  int buffer_size; /* number of buffer slots for each vc in flits*/
  int num_vc; /* number of virtual channels for each torus link */
  float mean_process;/* mean process time for each flit  */
123
  int chunk_size; /* chunk is the smallest unit--default set to 32 */
124
};
125
 /* In general we need to figure out how to pass configuration information to
126 127 128 129 130 131 132
 * the methods and we need to be able to calculate ross event message size.
 */
/*Initialize the network by specifying the network parameters. The 
 * underlying model-net.c function call will set the network parameters 
 * according to the network name specified*/
// return an integer being the identifier for the type of network
// call modelnet setup 1 time for a torus and retur value is 0 for e.g.
133 134 135 136 137

/* call set params for configuring the network parameters from the config file*/
int model_net_set_params();

// setup the modelnet parameters
138
int model_net_setup(char* net_name, uint64_t packet_size, const void* net_params);
139 140 141

/* utility function to get the modelnet ID post-setup */
int model_net_get_id(char *net_name);
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
/* allocate and transmit a new event that will pass through model_net to 
 * arrive at its destination:
 *
 * - category: category name to associate with this communication
 *   - OPTIONAL: callers can set this to NULL if they don't want to use it,
 *     and model_net methods can ignore it if they don't support it
 * - final_dest_lp: the LP that the message should be delivered to.
 *   - NOTE: this is _not_ the LP of an underlying network method (for
 *     example, it is not a torus or dragonfly LP), but rather the LP of an
 *     MPI process or storage server that you are transmitting to.
 * - message_size: this is the size of the message (in bytes) that modelnet
 *     will simulate transmitting to the final_dest_lp.  It can be any size
 *     (i.e. it is not constrained by transport packet size).
 * - remote_event_size: this is the size of the ROSS event structure that
 *     will be delivered to the final_dest_lp.
 * - remote_event: pointer ot data to be used as the remove event message
 * - self_event_size: this is the size of the ROSS event structure that will
 *     be delivered to the calling LP once local completion has occurred for
 *     the network transmission.
 *     - NOTE: "local completion" in this sense means that model_net has
 *       transmitted the data off of the local node, but it does not mean that
 *       the data has been (or even will be) delivered.  Once this event is
 *       delivered the caller is free to re-use its buffer.
 * - self_event: pionter to data to be used as the self event message
 * - sender: pointer to the tw_lp structure of the API caller.  This is
 *     identical to the sender argument to tw_event_new().
 */
// first argument becomes the network ID
void model_net_event(
    int net_id,
    char* category, 
    tw_lpid final_dest_lp, 
174
    uint64_t message_size, 
175
    tw_stime offset,
176 177 178 179 180 181
    int remote_event_size,
    const void* remote_event,
    int self_event_size,
    const void* self_event,
    tw_lp *sender);

182 183 184 185 186 187
/* model_net_find_local_device()
 *
 * returns the LP id of the network card attached to the calling LP
 */
tw_lpid model_net_find_local_device(int net_id, tw_lp *sender);

188 189
int model_net_get_msg_sz(int net_id);

190 191 192 193 194 195 196 197 198 199 200 201 202
/* model_net_event_rc()
 *
 * This function does reverse computation for the model_net_event_new()
 * function.
 * - sender: pointer to the tw_lp structure of the API caller.  This is
 *   identical to the sender argument to tw_event_new().
 */
/* NOTE: we may end up needing additoinal arguments here to track state for
 * reverse computation; add as needed 
 */
void model_net_event_rc(
    int net_id,
    tw_lp *sender,
203
    uint64_t message_size);
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

/* Issue a 'pull' from the memory of the destination LP, without
 * requiring the destination LP to do event processing. This is meant as a
 * simulation-based abstraction of RDMA. A control packet will be sent to the
 * destination LP, the payload will be sent back to the requesting LP, and the
 * requesting LP will be issued it's given completion event.
 *
 * Parameters are largely the same as model_net_event, with the following
 * exceptions:
 * - final_dest_lp is the lp to pull data from
 * - self_event_size, self_event are applied at the requester upon receipt of 
 *   the payload from the dest
 */
void model_net_pull_event(
        int net_id,
        char *category,
        tw_lpid final_dest_lp,
        uint64_t message_size,
        tw_stime offset,
        int self_event_size,
        const void *self_event,
        tw_lp *sender);
void model_net_pull_event_rc(
        int net_id,
        tw_lp *sender);

231 232 233
/* returns pointer to LP information for simplenet module */
const tw_lptype* model_net_get_lp_type(int net_id);

234
uint64_t model_net_get_packet_size(int net_id);
235

236 237 238
/* used for reporting overall network statistics for e.g. average latency ,
 * maximum latency, total number of packets finished during the entire
 * simulation etc. */
239
void model_net_report_stats(int net_id);
240

241
/* writing model-net statistics on a per LP basis */
242 243
void model_net_write_stats(tw_lpid lpid, mn_stats* stat);

244
/* printing model-net statistics on a per LP basis */
245 246 247 248
void model_net_print_stats(tw_lpid lpid, mn_stats mn_stats_array[]);

/* find model-net statistics */
mn_stats* model_net_find_stats(const char* category, mn_stats mn_stats_array[]);
249 250 251 252 253 254 255 256 257 258
#endif /* MODELNET_H */

/*
 * Local variables:
 *  c-indent-level: 4
 *  c-basic-offset: 4
 * End:
 *
 * vim: ft=c ts=8 sts=4 sw=4 expandtab
 */