Skip to content

Commit d6498f3

Browse files
committed
equivalent: added bimap to store pin mappings between tile and block
Signed-off-by: Alessandro Comodi <[email protected]>
1 parent 1668b7c commit d6498f3

File tree

3 files changed

+88
-9
lines changed

3 files changed

+88
-9
lines changed

libs/libarchfpga/src/physical_types.h

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
#include "vtr_ndmatrix.h"
4040
#include "vtr_hash.h"
41+
#include "vtr_bimap.h"
4142

4243
#include "logic_types.h"
4344
#include "clock_types.h"
@@ -58,6 +59,8 @@ struct t_physical_tile_type;
5859
typedef const t_physical_tile_type* t_physical_tile_type_ptr;
5960
struct t_logical_block_type;
6061
typedef const t_logical_block_type* t_logical_block_type_ptr;
62+
struct t_logical_pin;
63+
struct t_physical_pin;
6164
struct t_pb_type;
6265
struct t_pb_graph_pin_power;
6366
struct t_mode;
@@ -616,12 +619,44 @@ struct t_physical_tile_type {
616619

617620
/* Unordered map indexed by the logical block index.
618621
* tile_block_pin_directs_map[logical block index][logical block pin] -> physical tile pin */
619-
std::unordered_map<int, std::unordered_map<int, int>> tile_block_pin_directs_map;
622+
std::unordered_map<int, vtr::bimap<t_logical_pin, t_physical_pin>> tile_block_pin_directs_map;
620623

621624
/* Returns the indices of pins that contain a clock for this physical logic block */
622625
std::vector<int> get_clock_pins_indices() const;
623626
};
624627

628+
struct t_logical_pin {
629+
int pin = -1;
630+
631+
t_logical_pin(int value) {
632+
pin = value;
633+
}
634+
635+
bool operator==(const t_logical_pin o) const {
636+
return pin == o.pin;
637+
}
638+
639+
bool operator<(const t_logical_pin o) const {
640+
return pin < o.pin;
641+
}
642+
};
643+
644+
struct t_physical_pin {
645+
int pin = -1;
646+
647+
t_physical_pin(int value) {
648+
pin = value;
649+
}
650+
651+
bool operator==(const t_physical_pin o) const {
652+
return pin == o.pin;
653+
}
654+
655+
bool operator<(const t_physical_pin o) const {
656+
return pin < o.pin;
657+
}
658+
};
659+
625660
/** Describes I/O and clock ports of a physical tile type
626661
*
627662
* It corresponds to <port/> tags in the FPGA architecture description

libs/libarchfpga/src/read_xml_arch_file.cpp

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#include "vtr_memory.h"
5353
#include "vtr_digest.h"
5454
#include "vtr_token.h"
55+
#include "vtr_bimap.h"
5556

5657
#include "arch_types.h"
5758
#include "arch_util.h"
@@ -3251,7 +3252,7 @@ static void ProcessEquivalentSiteDirects(pugi::xml_node Parent,
32513252
"There are no direct pin mappings between site %s and tile %s.\n", site_name.c_str(), PhysicalTileType->name);
32523253
}
32533254

3254-
std::unordered_map<int, int> directs_map;
3255+
vtr::bimap<t_logical_pin, t_physical_pin> directs_map;
32553256

32563257
CurDirect = Parent.first_child();
32573258
while (CurDirect) {
@@ -3279,7 +3280,16 @@ static void ProcessEquivalentSiteDirects(pugi::xml_node Parent,
32793280

32803281
int num_pins = from_pins.second - from_pins.first;
32813282
for (int i = 0; i < num_pins; i++) {
3282-
directs_map[to_pins.first + i] = from_pins.first + i;
3283+
t_physical_pin phy_pin(from_pins.first + i);
3284+
t_logical_pin log_pin(to_pins.first + i);
3285+
3286+
auto result = directs_map.insert(log_pin, phy_pin);
3287+
if (!result.second) {
3288+
archfpga_throw(loc_data.filename_c_str(), loc_data.line(Parent),
3289+
"Duplicate logical pin (%d) to physical pin (%d) mappings found for "
3290+
"Physical Tile %s and Logical Block %s.\n",
3291+
log_pin.pin, phy_pin.pin, PhysicalTileType->name, LogicalBlockType->name);
3292+
}
32833293
}
32843294

32853295
CurDirect = CurDirect.next_sibling(CurDirect.name());
@@ -4791,6 +4801,42 @@ static void link_physical_logical_types(std::vector<t_physical_tile_type>& Physi
47914801
archfpga_throw(__FILE__, __LINE__,
47924802
"Logical Block %s does not have any equivalent tiles.\n", logical_block.name);
47934803
}
4804+
4805+
std::unordered_map<int, bool> ignored_pins_check_map;
4806+
std::unordered_map<int, bool> global_pins_check_map;
4807+
4808+
for (int pin = 0; pin < logical_block.pb_type->num_pins; pin++) {
4809+
for (auto& tile : logical_block.equivalent_tiles) {
4810+
auto direct_map = tile->tile_block_pin_directs_map.at(logical_block.index);
4811+
auto result = direct_map.find(t_logical_pin(pin));
4812+
if (result == direct_map.end()) {
4813+
archfpga_throw(__FILE__, __LINE__,
4814+
"Logical pin %d not present in pin mapping between Tile %s and Block %s.\n",
4815+
pin, tile->name, logical_block.name);
4816+
}
4817+
4818+
int phy_index = result->second.pin;
4819+
4820+
bool is_ignored = tile->is_ignored_pin[phy_index];
4821+
bool is_global = tile->is_pin_global[phy_index];
4822+
4823+
auto ignored_result = ignored_pins_check_map.insert(std::pair<int, bool>(pin, is_ignored));
4824+
if (!ignored_result.second && ignored_result.first->second != is_ignored) {
4825+
archfpga_throw(__FILE__, __LINE__,
4826+
"Physical Tile %s has a different value for the ignored pin (physical pin: %d, logical pin: %d) "
4827+
"different from the corresponding pins of the other equivalent sites\n.",
4828+
tile->name, phy_index, pin);
4829+
}
4830+
4831+
auto global_result = global_pins_check_map.insert(std::pair<int, bool>(pin, is_global));
4832+
if (!global_result.second && global_result.first->second != is_global) {
4833+
archfpga_throw(__FILE__, __LINE__,
4834+
"Physical Tile %s has a different value for the global pin (physical pin: %d, logical pin: %d) "
4835+
"different from the corresponding pins of the other equivalent sites\n.",
4836+
tile->name, phy_index, pin);
4837+
}
4838+
}
4839+
}
47944840
}
47954841
}
47964842

@@ -4812,8 +4858,8 @@ static void check_port_direct_mappings(t_physical_tile_type_ptr physical_tile, t
48124858
}
48134859

48144860
for (auto pin_map : pin_direct_mapping) {
4815-
auto block_port = get_port_by_pin(logical_block, pin_map.first);
4816-
auto tile_port = get_port_by_pin(physical_tile, pin_map.second);
4861+
auto block_port = get_port_by_pin(logical_block, pin_map.first.pin);
4862+
auto tile_port = get_port_by_pin(physical_tile, pin_map.second.pin);
48174863

48184864
VTR_ASSERT(block_port != nullptr);
48194865
VTR_ASSERT(tile_port != nullptr);

vpr/src/route/route_common.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,11 +1033,9 @@ static vtr::vector<ClusterNetId, std::vector<int>> load_net_rr_terminals(const t
10331033
node_block_pin = cluster_ctx.clb_nlist.pin_logical_index(pin_id);
10341034

10351035
auto pin_directs_map = type->tile_block_pin_directs_map;
1036-
auto map_result = pin_directs_map.find(logical_block->index);
1037-
std::unordered_map<int, int> map = map_result->second;
1036+
auto map = pin_directs_map[logical_block->index];
10381037

1039-
auto pin_result = map.find(node_block_pin);
1040-
auto orig_phys_pin = pin_result->second;
1038+
auto orig_phys_pin = map[t_logical_pin(node_block_pin)].pin;
10411039

10421040
VTR_ASSERT(type->num_pins % type->capacity == 0);
10431041
int max_num_block_pins = type->num_pins / type->capacity;

0 commit comments

Comments
 (0)