Skip to content

Commit d9dec1f

Browse files
authored
Merge pull request #2590 from verilog-to-routing/add_flat_site_index_to_pg_graph_node
add flat idx to pb_graph_node , populate in alloc_and_load_pb_graph
2 parents 8791d19 + bf3bdf0 commit d9dec1f

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

libs/libarchfpga/src/physical_types.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,6 +1225,12 @@ struct t_pin_to_pin_annotation {
12251225
* parent_pb_graph_node : parent pb graph node
12261226
* total_primitive_count : Total number of this primitive type in the cluster. If there are 10 ALMs per cluster
12271227
* and 2 FFs per ALM (given the mode of the parent of this primitive) then the total is 20.
1228+
* This member is only used by nodes corresponding to primitive sites.
1229+
* flat_site_index : Index of this primitive site within its primitive type within this cluster type.
1230+
* Values are in [0...total_primitive_count-1], e.g. if there are 10 ALMs per cluster, 2 FFS
1231+
* and 2 LUTs per ALM, then flat site indices for FFs would run from 0 to 19, and flat site
1232+
indices for LUTs would run from 0 to 19. This member is only used by nodes corresponding
1233+
to primitive sites. It is used when reconstructing clusters from a flat placement file.
12281234
* illegal_modes : vector containing illegal modes that result in conflicts during routing
12291235
*/
12301236
class t_pb_graph_node {
@@ -1281,6 +1287,8 @@ class t_pb_graph_node {
12811287
int num_output_pin_class; /* number of output pin classes that this pb_graph_node has */
12821288

12831289
int total_primitive_count; /* total number of this primitive type in the cluster */
1290+
int flat_site_index; /* index of this primitive within sites of its type in this cluster */
1291+
12841292

12851293
/* Interconnect instances for this pb
12861294
* Only used for power

vpr/src/pack/pb_type_graph.cpp

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ static void alloc_and_load_pb_graph(t_pb_graph_node* pb_graph_node,
4848
t_pb_graph_node* parent_pb_graph_node,
4949
t_pb_type* pb_type,
5050
const int index,
51+
const int flat_index,
5152
bool load_power_structures,
5253
int& pin_count_in_cluster);
5354

@@ -134,6 +135,11 @@ static bool check_input_pins_equivalence(const t_pb_graph_pin* cur_pin,
134135
std::map<int, int>& edges_map,
135136
int* line_num);
136137

138+
/* computes the index of a pb graph node at its level of the pb hierarchy */
139+
static int compute_flat_index_for_child_node(int num_children_of_type,
140+
int parent_flat_index,
141+
int child_index);
142+
137143
/**
138144
* Allocate memory into types and load the pb graph with interconnect edges
139145
*/
@@ -151,6 +157,7 @@ void alloc_and_load_all_pb_graphs(bool load_power_structures, bool is_flat) {
151157
nullptr,
152158
type.pb_type,
153159
0,
160+
0,
154161
load_power_structures,
155162
pin_count_in_cluster);
156163
type.pb_graph_head->total_pb_pins = pin_count_in_cluster;
@@ -224,6 +231,7 @@ static void alloc_and_load_pb_graph(t_pb_graph_node* pb_graph_node,
224231
t_pb_graph_node* parent_pb_graph_node,
225232
t_pb_type* pb_type,
226233
const int index,
234+
const int flat_index,
227235
bool load_power_structures,
228236
int& pin_count_in_cluster) {
229237
int i, j, k, i_input, i_output, i_clockport;
@@ -237,6 +245,7 @@ static void alloc_and_load_pb_graph(t_pb_graph_node* pb_graph_node,
237245
pb_graph_node->num_clock_ports = 0;
238246

239247
pb_graph_node->total_primitive_count = 0;
248+
pb_graph_node->flat_site_index = 0;
240249

241250
/* Generate ports for pb graph node */
242251
for (i = 0; i < pb_type->num_ports; i++) {
@@ -349,11 +358,15 @@ static void alloc_and_load_pb_graph(t_pb_graph_node* pb_graph_node,
349358
sizeof(t_pb_graph_node*));
350359
for (j = 0; j < pb_type->modes[i].num_pb_type_children; j++) {
351360
pb_graph_node->child_pb_graph_nodes[i][j] = (t_pb_graph_node*)vtr::calloc(pb_type->modes[i].pb_type_children[j].num_pb, sizeof(t_pb_graph_node));
352-
for (k = 0; k < pb_type->modes[i].pb_type_children[j].num_pb; k++) {
361+
int num_children_of_type = pb_type->modes[i].pb_type_children[j].num_pb;
362+
363+
for (k = 0; k < num_children_of_type; k++) {
364+
int child_flat_index = compute_flat_index_for_child_node(num_children_of_type, flat_index, k);
353365
alloc_and_load_pb_graph(&pb_graph_node->child_pb_graph_nodes[i][j][k],
354366
pb_graph_node,
355367
&pb_type->modes[i].pb_type_children[j],
356368
k,
369+
child_flat_index,
357370
load_power_structures,
358371
pin_count_in_cluster);
359372
}
@@ -380,6 +393,10 @@ static void alloc_and_load_pb_graph(t_pb_graph_node* pb_graph_node,
380393
pb_node = pb_node->parent_pb_graph_node;
381394
}
382395
pb_graph_node->total_primitive_count = total_count;
396+
397+
// if this is a primitive, then flat_index corresponds
398+
// to its index within all primitives of this type
399+
pb_graph_node->flat_site_index = flat_index;
383400
}
384401
}
385402

@@ -1914,3 +1931,22 @@ const t_pb_graph_edge* get_edge_between_pins(const t_pb_graph_pin* driver_pin, c
19141931

19151932
return nullptr;
19161933
}
1934+
1935+
/* Date:June 8th, 2024
1936+
* Author: Kate Thurmer
1937+
* Purpose: This subroutine computes the index of a pb graph node at its
1938+
level of the pb hierarchy; it is computed by the parent and
1939+
passed to each child of each child pb type. When the child is
1940+
a primitive, the computed indes is its flat site index.
1941+
For example, if there are 10 ALMs, each with 2 FFs and 2 LUTs,
1942+
then the ALM at index N, when calling this function for
1943+
its FF child at index M, would compute the child's index as:
1944+
N*(FFs per ALM) + M
1945+
e.g. for FF[1] in ALM[5], this returns
1946+
5*(2 FFS per ALM) + 1 = 11
1947+
*/
1948+
static int compute_flat_index_for_child_node(int num_children_of_type,
1949+
int parent_flat_index,
1950+
int child_index) {
1951+
return parent_flat_index*num_children_of_type + child_index;
1952+
}

0 commit comments

Comments
 (0)