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 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
static tw_lpid torus_find_local_device(tw_lp *sender);

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

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

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

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

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

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

143
  /* for reverse computation */
144 145 146
  int saved_src_dim;
  int saved_src_dir;

147
  /* coordinates of the destination torus nodes */
148 149
  int* dest;

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

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

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

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

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

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

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

#endif
Philip Carns's avatar
Philip Carns committed
193 194 195 196 197 198 199 200 201

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