Skip to content

Commit ff37218

Browse files
litghostvaughnbetz
authored andcommitted
Fix port processing in read netlist to handle cases where num_in_port = 0.
Signed-off-by: Keith Rothman <[email protected]>
1 parent bc3f229 commit ff37218

File tree

3 files changed

+47
-14
lines changed

3 files changed

+47
-14
lines changed

vpr/src/base/check_netlist.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ void check_netlist(int verbosity) {
4040
/* This routine checks that the netlist makes sense. */
4141
auto& cluster_ctx = g_vpr_ctx.mutable_clustering();
4242

43+
// Return internal netlist verification first.
44+
cluster_ctx.clb_nlist.verify();
45+
4346
net_hash_table = alloc_hash_table();
4447

4548
/* Check that nets fanout and have a driver. */

vpr/src/base/netlist.tpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,7 @@ PinId Netlist<BlockId, PortId, PinId, NetId>::create_pin(const PortId port_id, B
704704

705705
//See if the pin already exists
706706
PinId pin_id = find_pin(port_id, port_bit);
707+
707708
if (!pin_id) {
708709
//Not found, create it
709710

@@ -736,6 +737,7 @@ PinId Netlist<BlockId, PortId, PinId, NetId>::create_pin(const PortId port_id, B
736737
VTR_ASSERT(pin_port_bit(pin_id) == port_bit);
737738
VTR_ASSERT(pin_net(pin_id) == net_id);
738739
VTR_ASSERT(pin_is_constant(pin_id) == is_const);
740+
VTR_ASSERT(pin_type(pin_id) == type);
739741
VTR_ASSERT_SAFE(find_pin(port_id, port_bit) == pin_id);
740742

741743
return pin_id;
@@ -1696,7 +1698,9 @@ bool Netlist<BlockId, PortId, PinId, NetId>::validate_net_pin_refs() const {
16961698
if (pin_id) {
16971699
VTR_ASSERT(pin_index == NET_DRIVER_INDEX);
16981700
if (pin_type(pin_id) != PinType::DRIVER) {
1699-
VPR_FATAL_ERROR(VPR_ERROR_NETLIST, "Driver pin not found at expected index in net");
1701+
VPR_FATAL_ERROR(VPR_ERROR_NETLIST,
1702+
"Driver pin %zu not found at expected index in net %zu",
1703+
size_t(pin_id), size_t(net_id));
17001704
}
17011705
}
17021706
} else {

vpr/src/base/read_netlist.cpp

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
static const char* netlist_file_name = nullptr;
3737

38-
static int processPorts(pugi::xml_node Parent, t_pb* pb, t_pb_routes& pb_route, const pugiutil::loc_data& loc_data);
38+
static void processPorts(pugi::xml_node Parent, t_pb* pb, t_pb_routes& pb_route, const pugiutil::loc_data& loc_data);
3939

4040
static void processPb(pugi::xml_node Parent, const ClusterBlockId index, t_pb* pb, t_pb_routes& pb_route, int* num_primitives, const pugiutil::loc_data& loc_data, ClusteredNetlist* clb_nlist);
4141

@@ -395,13 +395,41 @@ static void processPb(pugi::xml_node Parent, const ClusterBlockId index, t_pb* p
395395
auto& atom_ctx = g_vpr_ctx.mutable_atom();
396396

397397
auto inputs = pugiutil::get_single_child(Parent, "inputs", loc_data);
398-
int num_in_ports = processPorts(inputs, pb, pb_route, loc_data);
398+
processPorts(inputs, pb, pb_route, loc_data);
399399

400400
auto outputs = pugiutil::get_single_child(Parent, "outputs", loc_data);
401-
int num_out_ports = processPorts(outputs, pb, pb_route, loc_data);
401+
processPorts(outputs, pb, pb_route, loc_data);
402402

403403
auto clocks = pugiutil::get_single_child(Parent, "clocks", loc_data);
404-
int num_clock_ports = processPorts(clocks, pb, pb_route, loc_data);
404+
processPorts(clocks, pb, pb_route, loc_data);
405+
406+
int num_in_ports = 0;
407+
int begin_out_port;
408+
int end_out_port;
409+
int begin_clock_port;
410+
int end_clock_port;
411+
412+
{
413+
int num_out_ports = 0;
414+
int num_clock_ports = 0;
415+
for (i = 0; i < pb->pb_graph_node->pb_type->num_ports; i++) {
416+
if (pb->pb_graph_node->pb_type->ports[i].is_clock
417+
&& pb->pb_graph_node->pb_type->ports[i].type == IN_PORT) {
418+
num_clock_ports++;
419+
} else if (!pb->pb_graph_node->pb_type->ports[i].is_clock
420+
&& pb->pb_graph_node->pb_type->ports[i].type == IN_PORT) {
421+
num_in_ports++;
422+
} else {
423+
VTR_ASSERT(pb->pb_graph_node->pb_type->ports[i].type == OUT_PORT);
424+
num_out_ports++;
425+
}
426+
}
427+
428+
begin_out_port = num_in_ports;
429+
end_out_port = begin_out_port + num_out_ports;
430+
begin_clock_port = end_out_port;
431+
end_clock_port = begin_clock_port + num_clock_ports;
432+
}
405433

406434
auto attrs = pugiutil::get_single_child(Parent, "attributes", loc_data, pugiutil::OPTIONAL);
407435
auto params = pugiutil::get_single_child(Parent, "parameters", loc_data, pugiutil::OPTIONAL);
@@ -410,15 +438,13 @@ static void processPb(pugi::xml_node Parent, const ClusterBlockId index, t_pb* p
410438

411439
//Create the ports in the clb_nlist for the top-level pb
412440
if (pb->is_root()) {
413-
VTR_ASSERT(num_in_ports <= num_out_ports);
414-
415441
for (i = 0; i < num_in_ports; i++) {
416442
clb_nlist->create_port(index, pb_type->ports[i].name, pb_type->ports[i].num_pins, PortType::INPUT);
417443
}
418-
for (i = num_in_ports; i < num_out_ports; i++) {
444+
for (i = begin_out_port; i < end_out_port; i++) {
419445
clb_nlist->create_port(index, pb_type->ports[i].name, pb_type->ports[i].num_pins, PortType::OUTPUT);
420446
}
421-
for (i = num_out_ports; i < num_clock_ports; i++) {
447+
for (i = begin_clock_port; i < end_clock_port; i++) {
422448
clb_nlist->create_port(index, pb_type->ports[i].name, pb_type->ports[i].num_pins, PortType::CLOCK);
423449
}
424450

@@ -576,7 +602,7 @@ static int add_net_to_hash(t_hash** nhash, const char* net_name, int* ncount) {
576602
return hash_value->index;
577603
}
578604

579-
static int processPorts(pugi::xml_node Parent, t_pb* pb, t_pb_routes& pb_route, const pugiutil::loc_data& loc_data) {
605+
static void processPorts(pugi::xml_node Parent, t_pb* pb, t_pb_routes& pb_route, const pugiutil::loc_data& loc_data) {
580606
int i, j, num_tokens;
581607
int in_port = 0, out_port = 0, clock_port = 0;
582608
std::vector<std::string> pins;
@@ -852,10 +878,6 @@ static int processPorts(pugi::xml_node Parent, t_pb* pb, t_pb_routes& pb_route,
852878
pb->set_atom_pin_bit_index(pb_gpin, atom_pin_index);
853879
}
854880
}
855-
856-
//Return the sum of the ports + 1, as we want to number of the ports
857-
//E.g. If there is 1 input port, the in_port index is 0, but num_in_ports = 1
858-
return in_port + out_port + clock_port + 1;
859881
}
860882

861883
/**
@@ -877,6 +899,8 @@ static void load_external_nets_and_cb(ClusteredNetlist& clb_nlist) {
877899

878900
/* Assumes that complex block pins are ordered inputs, outputs, globals */
879901

902+
clb_nlist.verify();
903+
880904
/* Determine the external nets of complex block */
881905
for (auto blk_id : clb_nlist.blocks()) {
882906
block_type = clb_nlist.block_type(blk_id);
@@ -956,6 +980,8 @@ static void load_external_nets_and_cb(ClusteredNetlist& clb_nlist) {
956980
}
957981
}
958982

983+
clb_nlist.verify();
984+
959985
vtr::vector<ClusterNetId, int> count(ext_ncount);
960986

961987
/* complete load of external nets so that each net points back to the blocks,

0 commit comments

Comments
 (0)