dragonfly.h 6.92 KB
Newer Older
1
/*
Philip Carns's avatar
Philip Carns committed
2 3 4 5
 * Copyright (C) 2013 University of Chicago.
 * See COPYRIGHT notice in top-level directory.
 *
 */
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

#ifndef INC_dragonfly_h
#define INC_dragonfly_h

#include <ross.h>

#include "codes/codes_mapping.h"
#include "codes/codes.h"
#include "codes/model-net.h"
#include "codes/model-net-method.h"

#define CHUNK_SIZE 32.0
#define CREDIT_SIZE 8
#define MEAN_PROCESS 1.0
#define MAX_NAME_LENGTH 256

22 23 24 25
#define CATEGORY_NAME_MAX 16
#define CATEGORY_MAX 12


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
// debugging parameters
#define TRACK 235221
#define PRINT_ROUTER_TABLE 1
#define DEBUG 1

// arrival rate
static double MEAN_INTERVAL=200.0;
/* radix of a dragonfly router = number of global channels + number of
 * compute node channels + number of local router channels */
static int radix=0;

/* configurable parameters, coming from the codes config file*/
/* number of virtual channels, number of routers comes from the
 * config file, number of compute nodes, global channels and group
 * is calculated from these configurable parameters */
int num_vcs, num_routers, num_cn, num_global_channels, num_groups;

/* configurable parameters, global channel, local channel and 
 * compute node bandwidth */
double global_bandwidth, local_bandwidth, cn_bandwidth;

/*configurable parameters, global virtual channel size, local
 * virtual channel size and compute node channel size */
int global_vc_size, local_vc_size, cn_vc_size;

/* global variables for codes mapping */
char lp_group_name[MAX_NAME_LENGTH], lp_type_name[MAX_NAME_LENGTH];
int mapping_grp_id, mapping_type_id, mapping_rep_id, mapping_offset;

/* sets up the dragonfly initial network parameters like number of dragonfly groups, 
 * number of compute nodes, number of global channels, bandwidth etc. */
static void dragonfly_setup(const void* net_params);

/* reports dragonfly statistics like average packet delay, average number of hops
 * traversed and maximum packet latency */
static void dragonfly_report_stats();

63 64
static tw_lpid dragonfly_find_local_device(tw_lp *sender);

65 66 67
/* dragonfly packet event method called by modelnet, this method triggers the packet
 * generate event of dragonfly and attached remote and local events to the last packet
 * of the message */
68
static tw_stime dragonfly_packet_event(char* category, tw_lpid final_dest_lp, uint64_t packet_size, int is_pull, uint64_t pull_size, tw_stime offset, int remote_event_size, const void* remote_event, int self_event_size, const void* self_event, tw_lp *sender, int is_last_pckt);
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91

/* returns dragonfly message size */
static int dragonfly_get_msg_sz(void);

/* reverse handler for dragonfly packet event */
static void dragonfly_packet_event_rc(tw_lp *sender);

/* returns the lp type of dragonfly compute node (terminal) */
static const tw_lptype* dragonfly_get_cn_lp_type(void);

/* returns the lp type of dragonfly router */
static const tw_lptype* dragonfly_get_router_lp_type(void);

/* data structure for dragonfly statistics */
struct model_net_method dragonfly_method =
{
    .method_name = "dragonfly",
    .mn_setup = dragonfly_setup,
    .model_net_method_packet_event = dragonfly_packet_event,
    .model_net_method_packet_event_rc = dragonfly_packet_event_rc,
    .mn_get_lp_type = dragonfly_get_cn_lp_type,
    .mn_get_msg_sz = dragonfly_get_msg_sz,
    .mn_report_stats = dragonfly_report_stats,
92
    .model_net_method_find_local_device = dragonfly_find_local_device,
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
};

/* handles terminal and router events like packet generate/send/receive/buffer */
typedef enum event_t event_t;

typedef struct terminal_state terminal_state;
typedef struct terminal_message terminal_message;
typedef struct router_state router_state;

/* dragonfly compute node data structure */
struct terminal_state
{
   unsigned long long packet_counter;

   // Dragonfly specific parameters
   unsigned int router_id;
   unsigned int terminal_id;

   // Each terminal will have an input and output channel with the router
   int* vc_occupancy; // NUM_VC
   int* output_vc_state;
   tw_stime terminal_available_time;
   tw_stime next_credit_available_time;
// Terminal generate, sends and arrival T_SEND, T_ARRIVAL, T_GENERATE
// Router-Router Intra-group sends and receives RR_LSEND, RR_LARRIVE
// Router-Router Inter-group sends and receives RR_GSEND, RR_GARRIVE
119
   struct mn_stats dragonfly_stats_array[CATEGORY_MAX];
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
};
/* terminal event type (1-4) */
enum event_t
{
  T_GENERATE=1,
  T_ARRIVE,
  T_SEND,
  T_BUFFER,
  R_SEND,
  R_ARRIVE,
  R_BUFFER
};
/* status of a virtual channel can be idle, active, allocated or wait for credit */
enum vc_status
{
   VC_IDLE,
   VC_ACTIVE,
   VC_ALLOC,
   VC_CREDIT
};

/* whether the last hop of a packet was global, local or a terminal */
enum last_hop
{
   GLOBAL,
   LOCAL,
   TERMINAL
};

/* three forms of routing algorithms available, adaptive routing is not
 * accurate and fully functional in the current version as the formulas
 * for detecting load on global channels are not very accurate */
enum ROUTING_ALGO
{
   MINIMAL,
   NON_MINIMAL,
   ADAPTIVE
};

/* this message is used for both dragonfly compute nodes and routers */
struct terminal_message
{
  /* flit travel start time*/
  tw_stime travel_start_time;
 /* packet ID of the flit  */
  unsigned long long packet_ID;
  /* event type of the flit */
  short  type;
  /* category: comes from codes */
  char category[MAX_NAME_LENGTH];
  /* final destination LP ID, this comes from codes can be a server or any other LP type*/
  tw_lpid final_dest_gid;
  /*sending LP ID from CODES, can be a server or any other LP type */
  tw_lpid sender_lp;
 /* destination terminal ID of the dragonfly */
  unsigned int dest_terminal_id;
  /* source terminal ID of the dragonfly */
  unsigned int src_terminal_id;
  /* number of hops traversed by the packet */
  short my_N_hop;
  /* Intermediate LP ID from which this message is coming */
  unsigned int intm_lp_id;
  short old_vc;
  short saved_vc;
  /* last hop of the message, can be a terminal, local router or global router */
  short last_hop;
  // For buffer message
   short vc_index;
   int input_chan;
   int output_chan;
190 191
    int is_pull;
    uint64_t pull_size;
192 193 194 195 196 197
   
   tw_stime saved_available_time;
   tw_stime saved_credit_time;

   int intm_group_id;
   short chunk_id;
198
   uint64_t packet_size;
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
   int remote_event_size_bytes;
   int local_event_size_bytes;
};

struct router_state
{
   unsigned int router_id;
   unsigned int group_id;
  
   int* global_channel; 
   tw_stime* next_output_available_time;
   tw_stime* next_credit_available_time;
   int* vc_occupancy;
   int* output_vc_state;
};

short routing = MINIMAL;

int minimal_count, nonmin_count;
int adaptive_threshold;
int head_delay;
int num_packets;
221
uint64_t num_chunks;
222 223 224 225 226 227 228 229 230 231 232 233

static tw_stime         dragonfly_total_time = 0;
static tw_stime         dragonfly_max_latency = 0;

int num_vc;
int num_terminal=0, num_router=0;
int total_routers, total_terminals, total_mpi_procs;

static long long       total_hops = 0;
static long long       N_finished_packets = 0;

#endif
Philip Carns's avatar
Philip Carns committed
234 235 236 237 238 239 240 241 242

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