Skip to content

Commit 13f29e2

Browse files
Merge pull request #3330 from AlexandreSinger/feature-pack-pb-cleanup
[Pack] Removed Temp Scratch Pad from pb_graph_node
2 parents 07addcc + 8f34d85 commit 13f29e2

File tree

2 files changed

+52
-32
lines changed

2 files changed

+52
-32
lines changed

libs/libarchfpga/src/physical_types.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,8 +1323,6 @@ class t_pb_graph_node {
13231323

13241324
int total_pb_pins; /* only valid for top-level */
13251325

1326-
void* temp_scratch_pad; /* temporary data, useful for keeping track of things when traversing data structure */
1327-
13281326
int* input_pin_class_size; /* Stores the number of pins that belong to a particular input pin class */
13291327
int num_input_pin_class; /* number of input pin classes that this pb_graph_node has */
13301328
int* output_pin_class_size; /* Stores the number of pins that belong to a particular output pin class */

vpr/src/pack/prepack.cpp

Lines changed: 52 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <cstring>
1717
#include <map>
1818
#include <queue>
19+
#include <unordered_map>
1920
#include <utility>
2021
#include <vector>
2122

@@ -42,7 +43,8 @@ static void free_list_of_pack_patterns(std::vector<t_pack_patterns>& list_of_pac
4243
static void free_pack_pattern(t_pack_patterns* pack_pattern);
4344

4445
static void discover_pattern_names_in_pb_graph_node(t_pb_graph_node* pb_graph_node,
45-
std::unordered_map<std::string, int>& pattern_names);
46+
std::unordered_map<std::string, int>& pattern_names,
47+
std::unordered_map<t_pb_graph_node*, t_pack_pattern_block*>& last_added_pattern_block);
4648

4749
static void forward_infer_pattern(t_pb_graph_pin* pb_graph_pin);
4850

@@ -56,13 +58,15 @@ static t_pb_graph_edge* find_expansion_edge_of_pattern(const int pattern_index,
5658
static void forward_expand_pack_pattern_from_edge(const t_pb_graph_edge* expansion_edge,
5759
t_pack_patterns& packing_pattern,
5860
int* L_num_blocks,
59-
const bool make_root_of_chain);
61+
const bool make_root_of_chain,
62+
std::unordered_map<t_pb_graph_node*, t_pack_pattern_block*>& last_added_pattern_block);
6063

6164
static void backward_expand_pack_pattern_from_edge(const t_pb_graph_edge* expansion_edge,
6265
t_pack_patterns& packing_pattern,
6366
t_pb_graph_pin* destination_pin,
6467
t_pack_pattern_block* destination_block,
65-
int* L_num_blocks);
68+
int* L_num_blocks,
69+
std::unordered_map<t_pb_graph_node*, t_pack_pattern_block*>& last_added_pattern_block);
6670

6771
static int compare_pack_pattern(const t_pack_patterns* pattern_a, const t_pack_patterns* pattern_b);
6872

@@ -153,14 +157,19 @@ static std::vector<t_pack_patterns> alloc_and_load_pack_patterns(const std::vect
153157
int L_num_blocks;
154158
t_pb_graph_edge* expansion_edge;
155159

160+
// Use this map to keep track of the last primitive from each pb_graph_node
161+
// that was added to a packing pattern.
162+
std::unordered_map<t_pb_graph_node*, t_pack_pattern_block*> last_added_pattern_block;
163+
156164
/* alloc and initialize array of packing patterns based on architecture complex blocks */
157165
std::unordered_map<std::string, int> pattern_names;
158166
for (const t_logical_block_type& type : logical_block_types) {
159-
discover_pattern_names_in_pb_graph_node(type.pb_graph_head, pattern_names);
167+
discover_pattern_names_in_pb_graph_node(type.pb_graph_head, pattern_names, last_added_pattern_block);
160168
}
161169

162170
std::vector<t_pack_patterns> packing_patterns = alloc_and_init_pattern_list_from_hash(pattern_names);
163171

172+
164173
/* load packing patterns by traversing the edges to find edges belonging to pattern */
165174
for (size_t i = 0; i < pattern_names.size(); i++) {
166175
for (const t_logical_block_type& type : logical_block_types) {
@@ -174,7 +183,8 @@ static std::vector<t_pack_patterns> alloc_and_load_pack_patterns(const std::vect
174183
packing_patterns[i].base_cost = 0;
175184
// use the found expansion edge to build the pack pattern
176185
backward_expand_pack_pattern_from_edge(expansion_edge,
177-
packing_patterns[i], nullptr, nullptr, &L_num_blocks);
186+
packing_patterns[i], nullptr, nullptr, &L_num_blocks,
187+
last_added_pattern_block);
178188
packing_patterns[i].num_blocks = L_num_blocks;
179189

180190
/* Default settings: A section of a netlist must match all blocks in a pack
@@ -214,19 +224,19 @@ static std::vector<t_pack_patterns> alloc_and_load_pack_patterns(const std::vect
214224

215225
/**
216226
* Locate all pattern names
217-
* Side-effect: set all pb_graph_node temp_scratch_pad field to NULL
218227
* For cases where a pattern inference is "obvious", mark it as obvious.
219228
*/
220229
static void discover_pattern_names_in_pb_graph_node(t_pb_graph_node* pb_graph_node,
221-
std::unordered_map<std::string, int>& pattern_names) {
230+
std::unordered_map<std::string, int>& pattern_names,
231+
std::unordered_map<t_pb_graph_node*, t_pack_pattern_block*>& last_added_pattern_block) {
222232
/* Iterate over all edges to discover if an edge in current physical block belongs to a pattern
223233
* If edge does, then record the name of the pattern in a hash table */
224234

225235
if (pb_graph_node == nullptr) {
226236
return;
227237
}
228238

229-
pb_graph_node->temp_scratch_pad = nullptr;
239+
last_added_pattern_block[pb_graph_node] = nullptr;
230240

231241
for (int i = 0; i < pb_graph_node->num_input_ports; i++) {
232242
for (int j = 0; j < pb_graph_node->num_input_pins[i]; j++) {
@@ -330,7 +340,7 @@ static void discover_pattern_names_in_pb_graph_node(t_pb_graph_node* pb_graph_no
330340
for (int i = 0; i < pb_graph_node->pb_type->num_modes; i++) {
331341
for (int j = 0; j < pb_graph_node->pb_type->modes[i].num_pb_type_children; j++) {
332342
for (int k = 0; k < pb_graph_node->pb_type->modes[i].pb_type_children[j].num_pb; k++) {
333-
discover_pattern_names_in_pb_graph_node(&pb_graph_node->child_pb_graph_nodes[i][j][k], pattern_names);
343+
discover_pattern_names_in_pb_graph_node(&pb_graph_node->child_pb_graph_nodes[i][j][k], pattern_names, last_added_pattern_block);
334344
}
335345
}
336346
}
@@ -484,7 +494,8 @@ static t_pb_graph_edge* find_expansion_edge_of_pattern(const int pattern_index,
484494
static void forward_expand_pack_pattern_from_edge(const t_pb_graph_edge* expansion_edge,
485495
t_pack_patterns& packing_pattern,
486496
int* L_num_blocks,
487-
bool make_root_of_chain) {
497+
bool make_root_of_chain,
498+
std::unordered_map<t_pb_graph_node*, t_pack_pattern_block*>& last_added_pattern_block) {
488499
int i, j, k;
489500
int iport, ipin, iedge;
490501
bool found; /* Error checking, ensure only one fan-out for each pattern net */
@@ -517,8 +528,8 @@ static void forward_expand_pack_pattern_from_edge(const t_pb_graph_edge* expansi
517528
/* This is the destination node */
518529
found = true;
519530

520-
// the temp_scratch_pad points to the last primitive from this pb_graph_node that was added to a packing pattern.
521-
const auto& destination_pb_temp = (t_pack_pattern_block*)destination_pb_graph_node->temp_scratch_pad;
531+
// Keep track of the last primitive from this pb_graph_node that was added to a packing pattern.
532+
const t_pack_pattern_block* destination_pb_temp = last_added_pattern_block[destination_pb_graph_node];
522533
// if this pb_graph_node (primitive) is not added to the packing pattern already, add it and expand all its edges
523534
if (destination_pb_temp == nullptr || destination_pb_temp->pattern_index != curr_pattern_index) {
524535
// a primitive that belongs to this pack pattern is found: 1) create a new pattern block,
@@ -528,7 +539,7 @@ static void forward_expand_pack_pattern_from_edge(const t_pb_graph_edge* expansi
528539
packing_pattern.base_cost += compute_primitive_base_cost(destination_pb_graph_node);
529540
destination_block->block_id = *L_num_blocks;
530541
(*L_num_blocks)++;
531-
destination_pb_graph_node->temp_scratch_pad = (void*)destination_block;
542+
last_added_pattern_block[destination_pb_graph_node] = destination_block;
532543
destination_block->pattern_index = curr_pattern_index;
533544
destination_block->pb_type = destination_pb_graph_node->pb_type;
534545

@@ -539,7 +550,8 @@ static void forward_expand_pack_pattern_from_edge(const t_pb_graph_edge* expansi
539550
backward_expand_pack_pattern_from_edge(destination_pb_graph_node->input_pins[iport][ipin].input_edges[iedge],
540551
packing_pattern,
541552
&destination_pb_graph_node->input_pins[iport][ipin],
542-
destination_block, L_num_blocks);
553+
destination_block, L_num_blocks,
554+
last_added_pattern_block);
543555
}
544556
}
545557
}
@@ -549,7 +561,8 @@ static void forward_expand_pack_pattern_from_edge(const t_pb_graph_edge* expansi
549561
for (ipin = 0; ipin < destination_pb_graph_node->num_output_pins[iport]; ipin++) {
550562
for (iedge = 0; iedge < destination_pb_graph_node->output_pins[iport][ipin].num_output_edges; iedge++) {
551563
forward_expand_pack_pattern_from_edge(destination_pb_graph_node->output_pins[iport][ipin].output_edges[iedge],
552-
packing_pattern, L_num_blocks, false);
564+
packing_pattern, L_num_blocks, false,
565+
last_added_pattern_block);
553566
}
554567
}
555568
}
@@ -561,14 +574,14 @@ static void forward_expand_pack_pattern_from_edge(const t_pb_graph_edge* expansi
561574
backward_expand_pack_pattern_from_edge(destination_pb_graph_node->clock_pins[iport][ipin].input_edges[iedge],
562575
packing_pattern,
563576
&destination_pb_graph_node->clock_pins[iport][ipin],
564-
destination_block, L_num_blocks);
577+
destination_block, L_num_blocks, last_added_pattern_block);
565578
}
566579
}
567580
}
568581
}
569582

570583
// if this pb_graph_node (primitive) should be added to the pack pattern blocks
571-
if (((t_pack_pattern_block*)destination_pb_graph_node->temp_scratch_pad)->pattern_index == curr_pattern_index) {
584+
if (last_added_pattern_block[destination_pb_graph_node]->pattern_index == curr_pattern_index) {
572585
// if this pb_graph_node is known to be the root of the chain, update the root block and root pin
573586
if (make_root_of_chain == true) {
574587
packing_pattern.chain_root_pins = {{expansion_edge->output_pins[i]}};
@@ -584,7 +597,8 @@ static void forward_expand_pack_pattern_from_edge(const t_pb_graph_edge* expansi
584597
forward_expand_pack_pattern_from_edge(expansion_edge->output_pins[i]->output_edges[j],
585598
packing_pattern,
586599
L_num_blocks,
587-
make_root_of_chain);
600+
make_root_of_chain,
601+
last_added_pattern_block);
588602
} else {
589603
for (k = 0; k < expansion_edge->output_pins[i]->output_edges[j]->num_pack_patterns; k++) {
590604
if (expansion_edge->output_pins[i]->output_edges[j]->pack_pattern_indices[k] == curr_pattern_index) {
@@ -603,7 +617,8 @@ static void forward_expand_pack_pattern_from_edge(const t_pb_graph_edge* expansi
603617
forward_expand_pack_pattern_from_edge(expansion_edge->output_pins[i]->output_edges[j],
604618
packing_pattern,
605619
L_num_blocks,
606-
make_root_of_chain);
620+
make_root_of_chain,
621+
last_added_pattern_block);
607622
}
608623
} // End for pack patterns of output edge
609624
}
@@ -622,7 +637,8 @@ static void backward_expand_pack_pattern_from_edge(const t_pb_graph_edge* expans
622637
t_pack_patterns& packing_pattern,
623638
t_pb_graph_pin* destination_pin,
624639
t_pack_pattern_block* destination_block,
625-
int* L_num_blocks) {
640+
int* L_num_blocks,
641+
std::unordered_map<t_pb_graph_node*, t_pack_pattern_block*>& last_added_pattern_block) {
626642
int i, j, k;
627643
int iport, ipin, iedge;
628644
bool found; /* Error checking, ensure only one fan-out for each pattern net */
@@ -658,13 +674,13 @@ static void backward_expand_pack_pattern_from_edge(const t_pb_graph_edge* expans
658674
found = true;
659675

660676
/* If this pb_graph_node is part not of the current pattern index, put it in and expand all its edges */
661-
source_block = (t_pack_pattern_block*)source_pb_graph_node->temp_scratch_pad;
677+
source_block = last_added_pattern_block[source_pb_graph_node];
662678
if (source_block == nullptr || source_block->pattern_index != curr_pattern_index) {
663679
source_block = new t_pack_pattern_block();
664680
source_block->block_id = *L_num_blocks;
665681
(*L_num_blocks)++;
666682
packing_pattern.base_cost += compute_primitive_base_cost(source_pb_graph_node);
667-
source_pb_graph_node->temp_scratch_pad = (void*)source_block;
683+
last_added_pattern_block[source_pb_graph_node] = source_block;
668684
source_block->pattern_index = curr_pattern_index;
669685
source_block->pb_type = source_pb_graph_node->pb_type;
670686

@@ -680,7 +696,8 @@ static void backward_expand_pack_pattern_from_edge(const t_pb_graph_edge* expans
680696
packing_pattern,
681697
&source_pb_graph_node->input_pins[iport][ipin],
682698
source_block,
683-
L_num_blocks);
699+
L_num_blocks,
700+
last_added_pattern_block);
684701
}
685702
}
686703
}
@@ -692,7 +709,8 @@ static void backward_expand_pack_pattern_from_edge(const t_pb_graph_edge* expans
692709
forward_expand_pack_pattern_from_edge(source_pb_graph_node->output_pins[iport][ipin].output_edges[iedge],
693710
packing_pattern,
694711
L_num_blocks,
695-
false);
712+
false,
713+
last_added_pattern_block);
696714
}
697715
}
698716
}
@@ -705,15 +723,16 @@ static void backward_expand_pack_pattern_from_edge(const t_pb_graph_edge* expans
705723
packing_pattern,
706724
&source_pb_graph_node->clock_pins[iport][ipin],
707725
source_block,
708-
L_num_blocks);
726+
L_num_blocks,
727+
last_added_pattern_block);
709728
}
710729
}
711730
}
712731
}
713732

714733
if (destination_pin != nullptr) {
715-
VTR_ASSERT(((t_pack_pattern_block*)source_pb_graph_node->temp_scratch_pad)->pattern_index == curr_pattern_index);
716-
source_block = (t_pack_pattern_block*)source_pb_graph_node->temp_scratch_pad;
734+
VTR_ASSERT(last_added_pattern_block[source_pb_graph_node]->pattern_index == curr_pattern_index);
735+
source_block = last_added_pattern_block[source_pb_graph_node];
717736
pack_pattern_connection = new t_pack_pattern_connections();
718737
pack_pattern_connection->from_block = source_block;
719738
pack_pattern_connection->from_pin = expansion_edge->input_pins[i];
@@ -750,7 +769,8 @@ static void backward_expand_pack_pattern_from_edge(const t_pb_graph_edge* expans
750769
forward_expand_pack_pattern_from_edge(expansion_edge,
751770
packing_pattern,
752771
L_num_blocks,
753-
true);
772+
true,
773+
last_added_pattern_block);
754774
}
755775
// this input pin of the expansion edge has a driving pin
756776
} else {
@@ -762,7 +782,8 @@ static void backward_expand_pack_pattern_from_edge(const t_pb_graph_edge* expans
762782
packing_pattern,
763783
destination_pin,
764784
destination_block,
765-
L_num_blocks);
785+
L_num_blocks,
786+
last_added_pattern_block);
766787
// if pattern shouldn't be inferred
767788
} else {
768789
// check if this input pin edge is annotated with the current pattern
@@ -775,7 +796,8 @@ static void backward_expand_pack_pattern_from_edge(const t_pb_graph_edge* expans
775796
packing_pattern,
776797
destination_pin,
777798
destination_block,
778-
L_num_blocks);
799+
L_num_blocks,
800+
last_added_pattern_block);
779801
}
780802
}
781803
}

0 commit comments

Comments
 (0)