@@ -55,12 +55,14 @@ 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_edges (pugi::xml_node parent, const pugiutil::loc_data& loc_data, int * wire_to_rr_ipin_switch, const int num_rr_switches);
60
61
void process_channels (t_chan_width& chan_width, pugi::xml_node parent, const pugiutil::loc_data& loc_data);
61
62
void process_rr_node_indices (const DeviceGrid& grid);
62
63
void process_seg_id (pugi::xml_node parent, const pugiutil::loc_data& loc_data);
63
64
void set_cost_indices (pugi::xml_node parent, const pugiutil::loc_data& loc_data, const bool is_global_graph, const int num_seg_types);
65
+ 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);
64
66
65
67
/* *********************** Subroutine definitions ****************************/
66
68
@@ -140,41 +142,60 @@ void load_rr_file(const t_graph_type graph_type,
140
142
int max_chan_width = (is_global_graph ? 1 : nodes_per_chan.max );
141
143
VTR_ASSERT (max_chan_width > 0 );
142
144
143
- /* Alloc rr nodes and count count nodes */
144
- next_component = get_single_child (rr_graph, " rr_nodes" , loc_data);
145
-
146
- int num_rr_nodes = count_children (next_component, " node" , loc_data);
147
-
148
- device_ctx.rr_nodes .resize (num_rr_nodes);
149
- process_nodes (next_component, loc_data);
150
-
151
145
/* Loads edges, switches, and node look up tables*/
152
146
next_component = get_single_child (rr_graph, " switches" , loc_data);
153
147
154
148
int numSwitches = count_children (next_component, " switch" , loc_data);
155
149
device_ctx.rr_switch_inf .resize (numSwitches);
156
150
157
151
process_switches (next_component, loc_data);
152
+ /* Branches to binary format */
153
+ next_component = get_single_child (rr_graph, " binary_nodes_and_edges" , loc_data, OPTIONAL);
154
+ if (next_component) {
155
+ auto filename = get_attribute (next_component, " file" , loc_data).as_string (" " );
156
+ VTR_LOG (" Using Binary File: %s\n " , filename);
157
+ FILE* fp = fopen (filename, " rb" );
158
+ if (fp == NULL ) {
159
+ VPR_THROW (VPR_ERROR_OTHER, " Binary File %s Does Not Exist\n " , filename);
160
+ }
158
161
159
- next_component = get_single_child (rr_graph, " rr_edges" , loc_data);
160
- process_edges (next_component, loc_data, wire_to_rr_ipin_switch, numSwitches);
162
+ process_nodes_and_switches_bin (fp, wire_to_rr_ipin_switch, is_global_graph, segment_inf, numSwitches);
163
+
164
+ partition_rr_graph_edges (device_ctx);
165
+ process_rr_node_indices (grid);
166
+ init_fan_in (device_ctx.rr_nodes , device_ctx.rr_nodes .size ());
167
+ alloc_and_load_rr_indexed_data (segment_inf, device_ctx.rr_node_indices ,
168
+ max_chan_width, *wire_to_rr_ipin_switch, base_cost_type);
169
+
170
+ } else {
171
+ /* Alloc rr nodes and count count nodes */
172
+ next_component = get_single_child (rr_graph, " rr_nodes" , loc_data);
161
173
162
- // Partition the rr graph edges for efficient access to configurable/non-configurable
163
- // edge subsets. Must be done after RR switches have been allocated
164
- partition_rr_graph_edges (device_ctx);
174
+ int num_rr_nodes = count_children (next_component, " node" , loc_data);
165
175
166
- process_rr_node_indices (grid);
176
+ device_ctx.rr_nodes .resize (num_rr_nodes);
177
+ process_nodes (next_component, loc_data);
167
178
168
- init_fan_in (device_ctx.rr_nodes , device_ctx.rr_nodes .size ());
179
+ next_component = get_single_child (rr_graph, " rr_edges" , loc_data);
180
+ process_edges (next_component, loc_data, wire_to_rr_ipin_switch, numSwitches);
169
181
170
- // sets the cost index and seg id information
171
- next_component = get_single_child (rr_graph, " rr_nodes " , loc_data);
172
- set_cost_indices (next_component, loc_data, is_global_graph, segment_inf. size () );
182
+ // Partition the rr graph edges for efficient access to configurable/non-configurable
183
+ // edge subsets. Must be done after RR switches have been allocated
184
+ partition_rr_graph_edges (device_ctx );
173
185
174
- alloc_and_load_rr_indexed_data (segment_inf, device_ctx.rr_node_indices ,
175
- max_chan_width, *wire_to_rr_ipin_switch, base_cost_type);
186
+ process_rr_node_indices (grid);
176
187
177
- process_seg_id (next_component, loc_data);
188
+ init_fan_in (device_ctx.rr_nodes , device_ctx.rr_nodes .size ());
189
+
190
+ // sets the cost index and seg id information
191
+ next_component = get_single_child (rr_graph, " rr_nodes" , loc_data);
192
+ set_cost_indices (next_component, loc_data, is_global_graph, segment_inf.size ());
193
+
194
+ alloc_and_load_rr_indexed_data (segment_inf, device_ctx.rr_node_indices ,
195
+ max_chan_width, *wire_to_rr_ipin_switch, base_cost_type);
196
+
197
+ process_seg_id (next_component, loc_data);
198
+ }
178
199
179
200
device_ctx.chan_width = nodes_per_chan;
180
201
@@ -185,6 +206,103 @@ void load_rr_file(const t_graph_type graph_type,
185
206
}
186
207
}
187
208
209
+ void process_nodes_and_switches_bin (FILE* fp,
210
+ int * wire_to_rr_ipin_switch,
211
+ bool is_global_graph,
212
+ const std::vector<t_segment_inf>& segment_inf,
213
+ int numSwitches) {
214
+ auto & device_ctx = g_vpr_ctx.mutable_device ();
215
+ uint32_t magic_num;
216
+ uint16_t format_version;
217
+ uint16_t header_length;
218
+ uint64_t num_rr_nodes;
219
+ fread_secure (&magic_num, sizeof (magic_num), 1 , fp);
220
+ fread_secure (&format_version, sizeof (format_version), 1 , fp);
221
+ fread_secure (&header_length, sizeof (header_length), 1 , fp);
222
+ char * header = new char [header_length + 1 ];
223
+ header[header_length] = ' \0 ' ;
224
+ fread_secure (header, sizeof (char ), header_length, fp);
225
+ fread_secure (&num_rr_nodes, sizeof (num_rr_nodes), 1 , fp);
226
+ device_ctx.rr_nodes .resize (num_rr_nodes);
227
+
228
+ if (magic_num != BINARY_MAGIC_NUM) {
229
+ VTR_LOG_WARN (" Not a VPR Binary rr_graph file\n " );
230
+ }
231
+
232
+ if (format_version != BINARY_FILE_VERSION) {
233
+ VTR_LOG_WARN (" Binary file format versions do not match\n " );
234
+ }
235
+
236
+ int inode;
237
+ t_rr_type node_type;
238
+ uint16_t num_edges;
239
+ e_direction direction;
240
+ e_side side;
241
+ int edge_sink_node;
242
+ uint16_t edge_switch;
243
+ uint16_t capacity;
244
+ float R;
245
+ float C;
246
+ uint16_t pos[5 ];
247
+
248
+ for (uint64_t i = 0 ; i < num_rr_nodes; i++) {
249
+ fread_secure (&inode, sizeof (inode), 1 , fp);
250
+ fread_secure (&node_type, sizeof (node_type), 1 , fp);
251
+ auto & node = device_ctx.rr_nodes [inode];
252
+ node.set_type (node_type);
253
+ if (node.type () == CHANX || node.type () == CHANY) {
254
+ fread_secure (&direction, sizeof (direction), 1 , fp);
255
+ node.set_direction (direction);
256
+ }
257
+
258
+ fread_secure (&capacity, sizeof (capacity), 1 , fp);
259
+ if (capacity > 0 )
260
+ node.set_capacity (capacity);
261
+ fread_secure (pos, sizeof (*pos), 5 , fp);
262
+ node.set_coordinates (pos[0 ], pos[1 ], pos[2 ], pos[3 ]);
263
+ node.set_ptc_num (pos[4 ]);
264
+ if (node.type () == IPIN || node.type () == OPIN) {
265
+ fread_secure (&side, sizeof (side), 1 , fp);
266
+ node.set_side (side);
267
+ }
268
+
269
+ fread_secure (&R, sizeof (R), 1 , fp);
270
+ fread_secure (&C, sizeof (C), 1 , fp);
271
+ node.set_rc_index (find_create_rr_rc_data (R, C));
272
+
273
+ fread_secure (&num_edges, sizeof (num_edges), 1 , fp);
274
+
275
+ node.set_num_edges (num_edges);
276
+ for (int j = 0 ; j < num_edges; j++) {
277
+ fread_secure (&edge_sink_node, sizeof (edge_sink_node), 1 , fp);
278
+ fread_secure (&edge_switch, sizeof (edge_switch), 1 , fp);
279
+ node.set_edge_sink_node (j, edge_sink_node);
280
+ node.set_edge_switch (j, edge_switch);
281
+ }
282
+ set_cost_index_bin (inode, node_type, is_global_graph, segment_inf.size (), 0 );
283
+ }
284
+ std::vector<int > count_for_wire_to_ipin_switches;
285
+ count_for_wire_to_ipin_switches.resize (numSwitches, 0 );
286
+ for (uint64_t i = 0 ; i < num_rr_nodes; i++) {
287
+ auto & node = device_ctx.rr_nodes [i];
288
+ if (node.type () == CHANX || node.type () == CHANY) {
289
+ num_edges = node.num_edges ();
290
+ for (int j = 0 ; j < num_edges; j++) {
291
+ if (device_ctx.rr_nodes [node.edge_sink_node (j)].type () == IPIN) {
292
+ count_for_wire_to_ipin_switches[j]++;
293
+ }
294
+ }
295
+ }
296
+ }
297
+ int max = -1 ;
298
+ for (int j = 0 ; j < numSwitches; j++) {
299
+ if (count_for_wire_to_ipin_switches[j] > max) {
300
+ *wire_to_rr_ipin_switch = j;
301
+ max = count_for_wire_to_ipin_switches[j];
302
+ }
303
+ }
304
+ }
305
+
188
306
/* Reads in the switch information and adds it to device_ctx.rr_switch_inf as specified*/
189
307
void process_switches (pugi::xml_node parent, const pugiutil::loc_data& loc_data) {
190
308
auto & device_ctx = g_vpr_ctx.mutable_device ();
@@ -876,3 +994,30 @@ void set_cost_indices(pugi::xml_node parent, const pugiutil::loc_data& loc_data,
876
994
rr_node = rr_node.next_sibling (rr_node.name ());
877
995
}
878
996
}
997
+
998
+ /* This function sets the Source pins, sink pins, ipin, and opin
999
+ * to their unique cost index identifier. CHANX and CHANY cost indicies are set after the
1000
+ * seg_id is read in from the rr graph */
1001
+ 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) {
1002
+ auto & device_ctx = g_vpr_ctx.mutable_device ();
1003
+ auto & node = device_ctx.rr_nodes [inode];
1004
+ // set the cost index in order to load the segment information, rr nodes should be set already
1005
+ if (node_type == SOURCE) {
1006
+ node.set_cost_index (SOURCE_COST_INDEX);
1007
+ } else if (node_type == SINK) {
1008
+ node.set_cost_index (SINK_COST_INDEX);
1009
+ } else if (node_type == IPIN) {
1010
+ node.set_cost_index (IPIN_COST_INDEX);
1011
+ } else if (node_type == OPIN) {
1012
+ node.set_cost_index (OPIN_COST_INDEX);
1013
+ } else if (node_type == CHANX || node_type == CHANY) {
1014
+ /* CHANX and CHANY cost index is dependent on the segment id*/
1015
+ if (is_global_graph) {
1016
+ node.set_cost_index (0 );
1017
+ } else if (device_ctx.rr_nodes [inode].type () == CHANX) {
1018
+ node.set_cost_index (CHANX_COST_INDEX_START + seg_id);
1019
+ } else if (device_ctx.rr_nodes [inode].type () == CHANY) {
1020
+ node.set_cost_index (CHANX_COST_INDEX_START + num_seg_types + seg_id);
1021
+ }
1022
+ }
1023
+ }
0 commit comments