torus.h 5.88 KB
Newer Older
1
/*
2 3 4 5
 * * Copyright (C) 2013, University of Chicago
 * *
 * * See COPYRIGHT notice in top-level directory.
 * */
6

7 8 9 10 11 12
#ifndef INC_torus_h
#define INC_torus_h

#include <ross.h>
#include <assert.h>

13
#include "codes/lp-io.h"
14 15 16 17 18 19 20 21 22 23 24
#include "codes/codes_mapping.h"
#include "codes/codes.h"
#include "codes/model-net.h"
#include "codes/model-net-method.h"

#define CHUNK_SIZE 32
#define DEBUG 1
#define MEAN_INTERVAL 100
#define MAX_NAME_LENGTH 256
#define TRACE -1 

25 26 27
#define CATEGORY_NAME_MAX 16
#define CATEGORY_MAX 12

28 29
/* Torus network model implementation of codes, implements the modelnet API */

30 31
// Total number of nodes in torus, calculate in main
int N_nodes = 1;
32
/* Link bandwidth for each torus link, configurable from the config file */
33
double link_bandwidth;
34
/* buffer size of each torus link, configurable */
35
int buffer_size;
36
/* number of virtual channels for each torus link, configurable */
37
int num_vc;
38
/* number of torus dimensions, configurable */
39
int n_dims;
40
/* length of each torus dimension, configurable */
41
int * dim_length;
42
/* factor, used in torus coordinate calculation */
43
int * factor;
44
/* half length of each dimension, used in torus coordinates calculation */
45 46
int * half_length;

47
/* codes mapping group name, lp type name */
48
char grp_name[MAX_NAME_LENGTH], type_name[MAX_NAME_LENGTH];
49
/* codes mapping group id, lp type id, repetition id and offset */
50 51
int grp_id, lp_type_id, rep_id, offset;

52
/* nodes event enumeration, packet generation, send, receive and buffer event types */
53
typedef enum nodes_event_t nodes_event_t;
54
/* state of a torus compute node (come up with a better name instead of compute node?)*/
55
typedef struct nodes_state nodes_state;
56
/* torus message--- can be a packet or a flit */
57 58 59 60 61 62 63 64 65 66 67 68 69
typedef struct nodes_message nodes_message;

/* Issues a torus packet event call */
static void torus_packet_event(
		       char* category,
		       tw_lpid final_dest_lp,
		       int packet_size,
		       int remote_event_size,
		       const void* remote_event,
		       int self_event_size,
		       const void* self_event,
		       tw_lp *sender,
		       int is_last_pckt);
70
/* torus reverse event handler */
71
static void torus_packet_event_rc(tw_lp *sender);
72 73
/* torus setup function, sets up configurable parameters like torus dimensions,
 * length of each dimension, channel bandwidth, buffer size etc. */
74
static void torus_setup(const void* net_params);
75
/* returns size of the torus message */
76
static int torus_get_msg_sz(void);
77
/* returns torus lp type */
78
static const tw_lptype* torus_get_lp_type(void);
79
/* reports torus statistics */
80
static void torus_report_stats(void);
81 82 83 84 85 86 87 88 89 90

/* data structure for torus statistics */
struct model_net_method torus_method =
{
   .method_name = "torus",
   .mn_setup = torus_setup,
   .model_net_method_packet_event = torus_packet_event,
   .model_net_method_packet_event_rc = torus_packet_event_rc,
   .mn_get_lp_type = torus_get_lp_type,
   .mn_get_msg_sz = torus_get_msg_sz,
91
   .mn_report_stats = torus_report_stats,
92 93
};

94
/* event type of each torus message, can be packet generate, flit arrival, flit send or credit */
95 96 97 98 99 100 101 102
enum nodes_event_t
{
  GENERATE = 1,
  ARRIVAL, 
  SEND,
  CREDIT,
};

103
/* state of a torus node */
104 105
struct nodes_state
{
106
  /* counts the number of packets sent from this compute node */
107
  unsigned long long packet_counter;            
108
  /* availability time of each torus link */
109
  tw_stime** next_link_available_time; 
110
  /* availability of each torus credit link */
111
  tw_stime** next_credit_available_time;
112
  /* next flit generate time */
113
  tw_stime** next_flit_generate_time;
114
  /* buffer size for each torus virtual channel */
115
  int** buffer;
116
  /* coordinates of the current torus node */
117
  int* dim_position;
118
  /* neighbor LP ids for this torus node */
119 120
  int* neighbour_minus_lpID;
  int* neighbour_plus_lpID;
121 122 123

  /* records torus statistics for this LP having different communication categories */
  struct mn_stats torus_stats_array[CATEGORY_MAX];
124 125 126 127
};

struct nodes_message
{
128
  /* category: comes from codes message */
129
  char category[CATEGORY_NAME_MAX];
130
  /* time the packet was generated */
131
  tw_stime travel_start_time;
132
  /* for reverse event computation*/
133 134
  tw_stime saved_available_time;

135
  /* packet ID */
136
  unsigned long long packet_ID;
137
  /* event type of the message */
138 139
  nodes_event_t	 type;

140
  /* for reverse computation */
141 142 143
  int saved_src_dim;
  int saved_src_dir;

144
  /* coordinates of the destination torus nodes */
145 146
  int* dest;

147
  /* final destination LP ID, comes from codes, can be a server or any other I/O LP type */
148
  tw_lpid final_dest_gid;
149
  /* destination torus node of the message */
150
  tw_lpid dest_lp;
151
  /* LP ID of the sender, comes from codes, can be a server or any other I/O LP type */
152 153
  tw_lpid sender_lp;

154
  /* number of hops traversed by the packet */
155
  int my_N_hop;
156
  /* source dimension of the message */
157
  int source_dim;
158
  /* source direction of the message */
159
  int source_direction;
160
  /* next torus hop that the packet will traverse */
161
  int next_stop;
162
  /* size of the torus packet */
163
  int packet_size;
164
  /* chunk id of the flit (distinguishes flits) */
165 166
  short chunk_id;

167
  /* for codes local and remote events, only carried by the last packet of the message */
168 169 170 171
  int local_event_size_bytes;
  int remote_event_size_bytes;
};

172
/* for calculating torus model statistics, average and maximum travel time of a packet */
173 174 175 176
tw_stime         average_travel_time = 0;
tw_stime         total_time = 0;
tw_stime         max_latency = 0;

177
/* indicates delays calculated through the bandwidth calculation of the torus link */
178 179 180
float head_delay=0.0;
float credit_delay = 0.0;

181
/* number of finished packets on each PE */
Philip Carns's avatar
Philip Carns committed
182
static long long       N_finished_packets = 0;
183
/* total number of hops traversed by a message on each PE */
Philip Carns's avatar
Philip Carns committed
184
static long long       total_hops = 0;
185 186

/* number of chunks/flits in each torus packet, calculated through the size of each flit (32 bytes by default) */
187 188 189
int num_chunks;

#endif
Philip Carns's avatar
Philip Carns committed
190 191 192 193 194 195 196 197 198

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