torus.h 6.07 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
int * half_length;
46
47
/* size of each torus chunk, by default it is set to 32 */
int chunk_size;
48

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

54
/* nodes event enumeration, packet generation, send, receive and buffer event types */
55
typedef enum nodes_event_t nodes_event_t;
56
/* state of a torus compute node (come up with a better name instead of compute node?)*/
57
typedef struct nodes_state nodes_state;
58
/* torus message--- can be a packet or a flit */
59
60
61
62
63
64
65
66
67
68
69
70
71
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);
72
/* torus reverse event handler */
73
static void torus_packet_event_rc(tw_lp *sender);
74
75
/* torus setup function, sets up configurable parameters like torus dimensions,
 * length of each dimension, channel bandwidth, buffer size etc. */
76
static void torus_setup(const void* net_params);
77
/* returns size of the torus message */
78
static int torus_get_msg_sz(void);
79
/* returns torus lp type */
80
static const tw_lptype* torus_get_lp_type(void);
81
/* reports torus statistics */
82
static void torus_report_stats(void);
83

84
85
static tw_lpid torus_find_local_device(tw_lp *sender);

86
87
88
89
90
91
92
93
94
/* 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,
95
   .mn_report_stats = torus_report_stats,
96
   .model_net_method_find_local_device = torus_find_local_device,
97
98
};

99
/* event type of each torus message, can be packet generate, flit arrival, flit send or credit */
100
101
102
103
104
105
106
107
enum nodes_event_t
{
  GENERATE = 1,
  ARRIVAL, 
  SEND,
  CREDIT,
};

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

  /* records torus statistics for this LP having different communication categories */
  struct mn_stats torus_stats_array[CATEGORY_MAX];
129
130
131
132
};

struct nodes_message
{
133
  /* category: comes from codes message */
134
  char category[CATEGORY_NAME_MAX];
135
  /* time the packet was generated */
136
  tw_stime travel_start_time;
137
  /* for reverse event computation*/
138
139
  tw_stime saved_available_time;

140
  /* packet ID */
141
  unsigned long long packet_ID;
142
  /* event type of the message */
143
144
  nodes_event_t	 type;

145
  /* for reverse computation */
146
147
148
  int saved_src_dim;
  int saved_src_dir;

149
  /* coordinates of the destination torus nodes */
150
151
  int* dest;

152
  /* final destination LP ID, comes from codes, can be a server or any other I/O LP type */
153
  tw_lpid final_dest_gid;
154
  /* destination torus node of the message */
155
  tw_lpid dest_lp;
156
  /* LP ID of the sender, comes from codes, can be a server or any other I/O LP type */
157
158
  tw_lpid sender_lp;

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

172
  /* for codes local and remote events, only carried by the last packet of the message */
173
174
175
176
  int local_event_size_bytes;
  int remote_event_size_bytes;
};

177
/* for calculating torus model statistics, average and maximum travel time of a packet */
178
179
180
181
tw_stime         average_travel_time = 0;
tw_stime         total_time = 0;
tw_stime         max_latency = 0;

182
/* indicates delays calculated through the bandwidth calculation of the torus link */
183
184
185
float head_delay=0.0;
float credit_delay = 0.0;

186
/* number of finished packets on each PE */
Philip Carns's avatar
Philip Carns committed
187
static long long       N_finished_packets = 0;
188
/* total number of hops traversed by a message on each PE */
Philip Carns's avatar
Philip Carns committed
189
static long long       total_hops = 0;
190
191

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

#endif
Philip Carns's avatar
Philip Carns committed
195
196
197
198
199
200
201
202
203

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