torus.h 5.69 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
22
23
24
#ifndef INC_torus_h
#define INC_torus_h

#include <ross.h>
#include <assert.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
#define DEBUG 1
#define MEAN_INTERVAL 100
#define CATEGORY_NAME_MAX 16
#define MAX_NAME_LENGTH 256
#define TRACE -1 

25
26
/* Torus network model implementation of codes, implements the modelnet API */

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

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

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

/* 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,
88
   .mn_report_stats = torus_report_stats,
89
90
};

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

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

struct nodes_message
{
122
  /* category: comes from codes message */
123
  char category[CATEGORY_NAME_MAX];
124
  /* time the packet was generated */
125
  tw_stime travel_start_time;
126
  /* for reverse event computation*/
127
128
  tw_stime saved_available_time;

129
  /* packet ID */
130
  unsigned long long packet_ID;
131
  /* event type of the message */
132
133
  nodes_event_t	 type;

134
  /* for reverse computation */
135
136
137
  int saved_src_dim;
  int saved_src_dir;

138
  /* coordinates of the destination torus nodes */
139
140
  int* dest;

141
  /* final destination LP ID, comes from codes, can be a server or any other I/O LP type */
142
  tw_lpid final_dest_gid;
143
  /* destination torus node of the message */
144
  tw_lpid dest_lp;
145
  /* LP ID of the sender, comes from codes, can be a server or any other I/O LP type */
146
147
  tw_lpid sender_lp;

148
  /* number of hops traversed by the packet */
149
  int my_N_hop;
150
  /* source dimension of the message */
151
  int source_dim;
152
  /* source direction of the message */
153
  int source_direction;
154
  /* next torus hop that the packet will traverse */
155
  int next_stop;
156
  /* size of the torus packet */
157
  int packet_size;
158
  /* chunk id of the flit (distinguishes flits) */
159
160
  short chunk_id;

161
  /* for codes local and remote events, only carried by the last packet of the message */
162
163
164
165
  int local_event_size_bytes;
  int remote_event_size_bytes;
};

166
/* for calculating torus model statistics, average and maximum travel time of a packet */
167
168
169
170
tw_stime         average_travel_time = 0;
tw_stime         total_time = 0;
tw_stime         max_latency = 0;

171
/* indicates delays calculated through the bandwidth calculation of the torus link */
172
173
174
float head_delay=0.0;
float credit_delay = 0.0;

175
/* number of finished packets on each PE */
Philip Carns's avatar
Philip Carns committed
176
static long long       N_finished_packets = 0;
177
/* total number of hops traversed by a message on each PE */
Philip Carns's avatar
Philip Carns committed
178
static long long       total_hops = 0;
179
180

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

#endif
Philip Carns's avatar
Philip Carns committed
184
185
186
187
188
189
190
191
192

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