GitLab maintenance scheduled form Friday, 2021-06-18 5:00pm to Satursday, 2021-06-19 10:00pm CT - Services will be unavailable during this time.

torus.h 6.25 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
typedef struct nodes_message nodes_message;

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

87 88
static tw_lpid torus_find_local_device(tw_lp *sender);

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

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

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

  /* records torus statistics for this LP having different communication categories */
  struct mn_stats torus_stats_array[CATEGORY_MAX];
132 133 134 135
};

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

143
  /* packet ID */
144
  unsigned long long packet_ID;
145
  /* event type of the message */
146 147
  nodes_event_t	 type;

148
  /* for reverse computation */
149 150 151
  int saved_src_dim;
  int saved_src_dir;

152
  /* coordinates of the destination torus nodes */
153 154
  int* dest;

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

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

175 176 177
  int is_pull;
  uint64_t pull_size;

178
  /* for codes local and remote events, only carried by the last packet of the message */
179 180 181 182
  int local_event_size_bytes;
  int remote_event_size_bytes;
};

183
/* for calculating torus model statistics, average and maximum travel time of a packet */
184 185 186 187
tw_stime         average_travel_time = 0;
tw_stime         total_time = 0;
tw_stime         max_latency = 0;

188
/* indicates delays calculated through the bandwidth calculation of the torus link */
189 190 191
float head_delay=0.0;
float credit_delay = 0.0;

192
/* number of finished packets on each PE */
Philip Carns's avatar
Philip Carns committed
193
static long long       N_finished_packets = 0;
194
/* total number of hops traversed by a message on each PE */
Philip Carns's avatar
Philip Carns committed
195
static long long       total_hops = 0;
196 197

/* number of chunks/flits in each torus packet, calculated through the size of each flit (32 bytes by default) */
198
uint64_t num_chunks;
199 200

#endif
Philip Carns's avatar
Philip Carns committed
201 202 203 204 205 206 207 208 209

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