@@ -55,13 +55,15 @@ void verify_segments(pugi::xml_node parent, const pugiutil::loc_data& loc_data,
55
55
void verify_blocks (pugi::xml_node parent, const pugiutil::loc_data& loc_data);
56
56
void process_blocks (pugi::xml_node parent, const pugiutil::loc_data& loc_data);
57
57
void verify_grid (pugi::xml_node parent, const pugiutil::loc_data& loc_data, const DeviceGrid& grid);
58
+ void process_nodes_and_switches_bin (FILE* fp, int * wire_to_rr_ipin_switch, bool is_global_graph, const std::vector<t_segment_inf>& segment_inf, int numSwitches);
58
59
void process_nodes (pugi::xml_node parent, const pugiutil::loc_data& loc_data);
59
60
void process_connection_boxes (pugi::xml_node parent, const pugiutil::loc_data& loc_data);
60
61
void process_edges (pugi::xml_node parent, const pugiutil::loc_data& loc_data, int * wire_to_rr_ipin_switch, const int num_rr_switches);
61
62
void process_channels (t_chan_width& chan_width, pugi::xml_node parent, const pugiutil::loc_data& loc_data);
62
63
void process_rr_node_indices (const DeviceGrid& grid);
63
64
void process_seg_id (pugi::xml_node parent, const pugiutil::loc_data& loc_data);
64
65
void set_cost_indices (pugi::xml_node parent, const pugiutil::loc_data& loc_data, const bool is_global_graph, const int num_seg_types);
66
+ void set_cost_index_bin (int inode, t_rr_type node_type, const bool is_global_graph, const int num_seg_types, short seg_id);
65
67
66
68
/* *********************** Subroutine definitions ****************************/
67
69
@@ -154,8 +156,6 @@ void load_rr_file(const t_graph_type graph_type,
154
156
int num_rr_nodes = count_children (next_component, " node" , loc_data);
155
157
156
158
device_ctx.rr_nodes .resize (num_rr_nodes);
157
- device_ctx.connection_boxes .resize_nodes (num_rr_nodes);
158
- process_nodes (next_component, loc_data);
159
159
160
160
/* Loads edges, switches, and node look up tables*/
161
161
next_component = get_single_child (rr_graph, " switches" , loc_data);
@@ -164,26 +164,54 @@ void load_rr_file(const t_graph_type graph_type,
164
164
device_ctx.rr_switch_inf .resize (numSwitches);
165
165
166
166
process_switches (next_component, loc_data);
167
+ /* Branches to binary format */
168
+ next_component = get_single_child (rr_graph, " binary_nodes_and_edges" , loc_data, OPTIONAL);
169
+ if (next_component) {
170
+ auto filename = get_attribute (next_component, " file" , loc_data).as_string (" " );
171
+ VTR_LOG (" Using Binary File: %s\n " , filename);
172
+ FILE* fp = fopen (filename, " rb" );
173
+ if (fp == NULL ) {
174
+ VPR_THROW (VPR_ERROR_OTHER, " Binary File %s Does Not Exist\n " , filename);
175
+ }
167
176
168
- next_component = get_single_child (rr_graph, " rr_edges" , loc_data);
169
- process_edges (next_component, loc_data, wire_to_rr_ipin_switch, numSwitches);
177
+ process_nodes_and_switches_bin (fp, wire_to_rr_ipin_switch, is_global_graph, segment_inf, numSwitches);
170
178
171
- // Partition the rr graph edges for efficient access to configurable/non-configurable
172
- // edge subsets. Must be done after RR switches have been allocated
173
- partition_rr_graph_edges (device_ctx);
179
+ partition_rr_graph_edges (device_ctx);
180
+ process_rr_node_indices (grid);
181
+ init_fan_in (device_ctx.rr_nodes , device_ctx.rr_nodes .size ());
182
+ alloc_and_load_rr_indexed_data (segment_inf, device_ctx.rr_node_indices ,
183
+ max_chan_width, *wire_to_rr_ipin_switch, base_cost_type);
174
184
175
- process_rr_node_indices (grid);
185
+ } else {
186
+ /* Alloc rr nodes and count count nodes */
187
+ next_component = get_single_child (rr_graph, " rr_nodes" , loc_data);
176
188
177
- init_fan_in (device_ctx. rr_nodes , device_ctx. rr_nodes . size () );
189
+ int num_rr_nodes = count_children (next_component, " node " , loc_data );
178
190
179
- // sets the cost index and seg id information
180
- next_component = get_single_child (rr_graph, " rr_nodes" , loc_data);
181
- set_cost_indices (next_component, loc_data, is_global_graph, segment_inf.size ());
191
+ device_ctx.rr_nodes .resize (num_rr_nodes);
192
+ device_ctx.connection_boxes .resize_nodes (num_rr_nodes);
193
+ process_nodes (next_component, loc_data);
194
+
195
+ next_component = get_single_child (rr_graph, " rr_edges" , loc_data);
196
+ process_edges (next_component, loc_data, wire_to_rr_ipin_switch, numSwitches);
197
+
198
+ // Partition the rr graph edges for efficient access to configurable/non-configurable
199
+ // edge subsets. Must be done after RR switches have been allocated
200
+ partition_rr_graph_edges (device_ctx);
201
+
202
+ process_rr_node_indices (grid);
182
203
183
- alloc_and_load_rr_indexed_data (segment_inf, device_ctx.rr_node_indices ,
184
- max_chan_width, *wire_to_rr_ipin_switch, base_cost_type);
204
+ init_fan_in (device_ctx.rr_nodes , device_ctx.rr_nodes .size ());
185
205
186
- process_seg_id (next_component, loc_data);
206
+ // sets the cost index and seg id information
207
+ next_component = get_single_child (rr_graph, " rr_nodes" , loc_data);
208
+ set_cost_indices (next_component, loc_data, is_global_graph, segment_inf.size ());
209
+
210
+ alloc_and_load_rr_indexed_data (segment_inf, device_ctx.rr_node_indices ,
211
+ max_chan_width, *wire_to_rr_ipin_switch, base_cost_type);
212
+
213
+ process_seg_id (next_component, loc_data);
214
+ }
187
215
188
216
device_ctx.chan_width = nodes_per_chan;
189
217
@@ -195,6 +223,103 @@ void load_rr_file(const t_graph_type graph_type,
195
223
}
196
224
}
197
225
226
+ void process_nodes_and_switches_bin (FILE* fp,
227
+ int * wire_to_rr_ipin_switch,
228
+ bool is_global_graph,
229
+ const std::vector<t_segment_inf>& segment_inf,
230
+ int numSwitches) {
231
+ auto & device_ctx = g_vpr_ctx.mutable_device ();
232
+ uint32_t magic_num;
233
+ uint16_t format_version;
234
+ uint16_t header_length;
235
+ uint64_t num_rr_nodes;
236
+ fread_secure (&magic_num, sizeof (magic_num), 1 , fp);
237
+ fread_secure (&format_version, sizeof (format_version), 1 , fp);
238
+ fread_secure (&header_length, sizeof (header_length), 1 , fp);
239
+ char * header = new char [header_length + 1 ];
240
+ header[header_length] = ' \0 ' ;
241
+ fread_secure (header, sizeof (char ), header_length, fp);
242
+ fread_secure (&num_rr_nodes, sizeof (num_rr_nodes), 1 , fp);
243
+ device_ctx.rr_nodes .resize (num_rr_nodes);
244
+
245
+ if (magic_num != BINARY_MAGIC_NUM) {
246
+ VTR_LOG_WARN (" Not a VPR Binary rr_graph file\n " );
247
+ }
248
+
249
+ if (format_version != BINARY_FILE_VERSION) {
250
+ VTR_LOG_WARN (" Binary file format versions do not match\n " );
251
+ }
252
+
253
+ int inode;
254
+ t_rr_type node_type;
255
+ uint16_t num_edges;
256
+ e_direction direction;
257
+ e_side side;
258
+ int edge_sink_node;
259
+ uint16_t edge_switch;
260
+ uint16_t capacity;
261
+ float R;
262
+ float C;
263
+ uint16_t pos[5 ];
264
+
265
+ for (uint64_t i = 0 ; i < num_rr_nodes; i++) {
266
+ fread_secure (&inode, sizeof (inode), 1 , fp);
267
+ fread_secure (&node_type, sizeof (node_type), 1 , fp);
268
+ auto & node = device_ctx.rr_nodes [inode];
269
+ node.set_type (node_type);
270
+ if (node.type () == CHANX || node.type () == CHANY) {
271
+ fread_secure (&direction, sizeof (direction), 1 , fp);
272
+ node.set_direction (direction);
273
+ }
274
+
275
+ fread_secure (&capacity, sizeof (capacity), 1 , fp);
276
+ if (capacity > 0 )
277
+ node.set_capacity (capacity);
278
+ fread_secure (pos, sizeof (*pos), 5 , fp);
279
+ node.set_coordinates (pos[0 ], pos[1 ], pos[2 ], pos[3 ]);
280
+ node.set_ptc_num (pos[4 ]);
281
+ if (node.type () == IPIN || node.type () == OPIN) {
282
+ fread_secure (&side, sizeof (side), 1 , fp);
283
+ node.set_side (side);
284
+ }
285
+
286
+ fread_secure (&R, sizeof (R), 1 , fp);
287
+ fread_secure (&C, sizeof (C), 1 , fp);
288
+ node.set_rc_index (find_create_rr_rc_data (R, C));
289
+
290
+ fread_secure (&num_edges, sizeof (num_edges), 1 , fp);
291
+
292
+ node.set_num_edges (num_edges);
293
+ for (int j = 0 ; j < num_edges; j++) {
294
+ fread_secure (&edge_sink_node, sizeof (edge_sink_node), 1 , fp);
295
+ fread_secure (&edge_switch, sizeof (edge_switch), 1 , fp);
296
+ node.set_edge_sink_node (j, edge_sink_node);
297
+ node.set_edge_switch (j, edge_switch);
298
+ }
299
+ set_cost_index_bin (inode, node_type, is_global_graph, segment_inf.size (), 0 );
300
+ }
301
+ std::vector<int > count_for_wire_to_ipin_switches;
302
+ count_for_wire_to_ipin_switches.resize (numSwitches, 0 );
303
+ for (uint64_t i = 0 ; i < num_rr_nodes; i++) {
304
+ auto & node = device_ctx.rr_nodes [i];
305
+ if (node.type () == CHANX || node.type () == CHANY) {
306
+ num_edges = node.num_edges ();
307
+ for (int j = 0 ; j < num_edges; j++) {
308
+ if (device_ctx.rr_nodes [node.edge_sink_node (j)].type () == IPIN) {
309
+ count_for_wire_to_ipin_switches[j]++;
310
+ }
311
+ }
312
+ }
313
+ }
314
+ int max = -1 ;
315
+ for (int j = 0 ; j < numSwitches; j++) {
316
+ if (count_for_wire_to_ipin_switches[j] > max) {
317
+ *wire_to_rr_ipin_switch = j;
318
+ max = count_for_wire_to_ipin_switches[j];
319
+ }
320
+ }
321
+ }
322
+
198
323
/* Reads in the switch information and adds it to device_ctx.rr_switch_inf as specified*/
199
324
void process_switches (pugi::xml_node parent, const pugiutil::loc_data& loc_data) {
200
325
auto & device_ctx = g_vpr_ctx.mutable_device ();
@@ -932,3 +1057,29 @@ void process_connection_boxes(pugi::xml_node parent, const pugiutil::loc_data& l
932
1057
933
1058
device_ctx.connection_boxes .reset_boxes (std::make_pair (x_dim, y_dim), boxes);
934
1059
}
1060
+ /* This function sets the Source pins, sink pins, ipin, and opin
1061
+ * to their unique cost index identifier. CHANX and CHANY cost indicies are set after the
1062
+ * seg_id is read in from the rr graph */
1063
+ void set_cost_index_bin (int inode, t_rr_type node_type, const bool is_global_graph, const int num_seg_types, short seg_id) {
1064
+ auto & device_ctx = g_vpr_ctx.mutable_device ();
1065
+ auto & node = device_ctx.rr_nodes [inode];
1066
+ // set the cost index in order to load the segment information, rr nodes should be set already
1067
+ if (node_type == SOURCE) {
1068
+ node.set_cost_index (SOURCE_COST_INDEX);
1069
+ } else if (node_type == SINK) {
1070
+ node.set_cost_index (SINK_COST_INDEX);
1071
+ } else if (node_type == IPIN) {
1072
+ node.set_cost_index (IPIN_COST_INDEX);
1073
+ } else if (node_type == OPIN) {
1074
+ node.set_cost_index (OPIN_COST_INDEX);
1075
+ } else if (node_type == CHANX || node_type == CHANY) {
1076
+ /* CHANX and CHANY cost index is dependent on the segment id*/
1077
+ if (is_global_graph) {
1078
+ node.set_cost_index (0 );
1079
+ } else if (device_ctx.rr_nodes [inode].type () == CHANX) {
1080
+ node.set_cost_index (CHANX_COST_INDEX_START + seg_id);
1081
+ } else if (device_ctx.rr_nodes [inode].type () == CHANY) {
1082
+ node.set_cost_index (CHANX_COST_INDEX_START + num_seg_types + seg_id);
1083
+ }
1084
+ }
1085
+ }
0 commit comments