Skip to content

Commit e686856

Browse files
mtdudekacomodi
authored andcommitted
interchange: fix alternative sites
Also fixes RR Graph generation with alternative site types Signed-off-by: Maciej Dudek <[email protected]>
1 parent 6f6b5d9 commit e686856

File tree

3 files changed

+96
-49
lines changed

3 files changed

+96
-49
lines changed

libs/libarchfpga/src/fpga_interchange_arch_utils.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ void process_cell_bel_mappings(DeviceResources::Device::Reader ar_,
135135

136136
int found_valid_prim = false;
137137
for (auto primitive : primLib.getCellDecls()) {
138-
bool is_prim = str(primitive.getLib()) == std::string("primitives");
139-
bool is_cell = cell_name == primitive.getName();
138+
if (cell_name != primitive.getName()) continue;
139+
if (str(primitive.getLib()) != std::string("primitives")) continue;
140140

141141
bool has_inout = false;
142142
for (auto port_idx : primitive.getPorts()) {
@@ -148,7 +148,7 @@ void process_cell_bel_mappings(DeviceResources::Device::Reader ar_,
148148
}
149149
}
150150

151-
if (is_prim && is_cell && !has_inout) {
151+
if (!has_inout) {
152152
found_valid_prim = true;
153153
break;
154154
}

libs/libarchfpga/src/read_fpga_interchange_arch.cpp

Lines changed: 68 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ static t_pin_to_pin_annotation get_pack_pattern(std::string pp_name, std::string
168168
return pp;
169169
}
170170

171-
void add_segment_with_default_values(t_segment_inf& seg, std::string name) {
171+
static void add_segment_with_default_values(t_segment_inf& seg, std::string name) {
172172
// Use default values as we will populate rr_graph with correct values
173173
// This segments are just declaration of future use
174174
seg.name = name;
@@ -381,6 +381,25 @@ struct ArchReader {
381381
return pad_bels_.count(name) != 0;
382382
}
383383

384+
void add_ltype(std::function<int(int)> map,
385+
const char* name,
386+
t_sub_tile& sub_tile,
387+
t_physical_tile_type& type) {
388+
389+
vtr::bimap<t_logical_pin, t_physical_pin> directs_map;
390+
auto ltype = get_type_by_name<t_logical_block_type>(name, ltypes_);
391+
392+
for (int npin = 0; npin < ltype->pb_type->num_ports; npin++) {
393+
t_physical_pin physical_pin(map(npin));
394+
t_logical_pin logical_pin(npin);
395+
396+
directs_map.insert(logical_pin, physical_pin);
397+
}
398+
399+
type.tile_block_pin_directs_map[ltype->index][sub_tile.index] = directs_map;
400+
sub_tile.equivalent_sites.push_back(ltype);
401+
}
402+
384403
/** @brief Utility function to fill in all the necessary information for the sub_tile
385404
*
386405
* Given a physical tile type and a corresponding sub tile with additional information on the IO pin count
@@ -421,47 +440,36 @@ struct ArchReader {
421440
}
422441
}
423442

424-
vtr::bimap<t_logical_pin, t_physical_pin> directs_map;
425-
426-
for (int npin = 0; npin < num_pins; npin++) {
427-
t_physical_pin physical_pin(npin);
428-
t_logical_pin logical_pin(npin);
429-
430-
directs_map.insert(logical_pin, physical_pin);
431-
}
432-
433-
auto ltype = get_type_by_name<t_logical_block_type>(sub_tile.name, ltypes_);
434-
435-
type.tile_block_pin_directs_map[ltype->index][sub_tile.index] = directs_map;
436-
sub_tile.equivalent_sites.push_back(ltype);
437-
438443
if (site_in_tile) {
439444
auto site_types = ar_.getSiteTypeList();
440445
auto site_type = site_types[site_in_tile->getPrimaryType()];
441446
auto alt_sites_pins = site_in_tile->getAltPinsToPrimaryPins();
442447

443-
for (int i = 0; i < site_type.getAltSiteTypes().size(); ++i) {
448+
if (take_sites_.count(site_type.getName()) != 0) {
449+
std::function<int(int)> map = [](int x){ return x; };
450+
add_ltype(map, sub_tile.name, sub_tile, type);
451+
}
452+
453+
for (int i = 0; i < (int)site_type.getAltSiteTypes().size(); ++i) {
444454
auto alt_site = site_types[site_type.getAltSiteTypes()[i]];
455+
445456
if (take_sites_.count(alt_site.getName()) == 0)
446457
continue;
447458

448-
auto ltype = get_type_by_name<t_logical_block_type>(str(alt_site.getName()).c_str(), ltypes_);
449-
sub_tile.equivalent_sites.push_back(ltype);
450-
451-
vtr::bimap<t_logical_pin, t_physical_pin> directs_map;
452459
auto pin_map = alt_sites_pins[i];
453460

454-
for (int npin = 0; npin < ltype->pb_type->num_ports; npin++) {
455-
auto pin = site_type.getPins()[pin_map.getPins()[npin]];
456-
auto idx = (*port_name_to_sub_tile_idx)[str(pin.getName())];
457-
t_physical_pin physical_pin(idx);
458-
t_logical_pin logical_pin(npin);
461+
std::function<int(int)> map = [pin_map, site_type, port_name_to_sub_tile_idx, this](int x){
462+
auto pin = site_type.getPins()[pin_map.getPins()[x]];
463+
return (*port_name_to_sub_tile_idx)[str(pin.getName())];
464+
};
459465

460-
directs_map.insert(logical_pin, physical_pin);
461-
}
462-
type.tile_block_pin_directs_map[ltype->index][sub_tile.index] = directs_map;
466+
add_ltype(map, str(alt_site.getName()).c_str(), sub_tile, type);
463467
}
468+
} else {
469+
std::function<int(int)> map = [](int x){ return x; };
470+
add_ltype(map, sub_tile.name, sub_tile, type);
464471
}
472+
465473
// Assign FC specs
466474
int iblk_pin = 0;
467475
for (const auto& port : sub_tile.ports) {
@@ -735,7 +743,22 @@ struct ArchReader {
735743
if (found)
736744
take_sites_.insert(site_type.getName());
737745

738-
// TODO: Enable also alternative site types handling
746+
for(auto alt_site_idx : site_type.getAltSiteTypes()) {
747+
auto alt_site = site_types[alt_site_idx];
748+
found = false;
749+
for (auto bel : alt_site.getBels()) {
750+
auto bel_name = bel.getName();
751+
bool res = bel_cell_mappings_.find(bel_name) != bel_cell_mappings_.end();
752+
753+
found |= res;
754+
755+
if (res || is_pad(str(bel_name)))
756+
take_bels_.insert(bel_name);
757+
}
758+
759+
if (found)
760+
take_sites_.insert(alt_site.getName());
761+
}
739762
}
740763
}
741764
}
@@ -1865,8 +1888,14 @@ struct ArchReader {
18651888

18661889
bool has_valid_sites = false;
18671890

1868-
for (auto site_type : tile.getSiteTypes())
1869-
has_valid_sites |= take_sites_.count(siteTypeList[site_type.getPrimaryType()].getName()) != 0;
1891+
for (auto site_type : tile.getSiteTypes()) {
1892+
auto site_ = siteTypeList[site_type.getPrimaryType()];
1893+
has_valid_sites |= take_sites_.count(site_.getName()) != 0;
1894+
for (auto alt_site_idx : site_.getAltSiteTypes()){
1895+
auto alt_site_ = siteTypeList[alt_site_idx];
1896+
has_valid_sites |= take_sites_.count(alt_site_.getName()) != 0;
1897+
}
1898+
}
18701899

18711900
if (!has_valid_sites)
18721901
continue;
@@ -1899,14 +1928,20 @@ struct ArchReader {
18991928
}
19001929

19011930
void process_sub_tiles(t_physical_tile_type& type, Device::TileType::Reader& tile) {
1902-
// TODO: only one subtile at the moment
19031931
auto siteTypeList = ar_.getSiteTypeList();
19041932
for (auto site_in_tile : tile.getSiteTypes()) {
19051933
t_sub_tile sub_tile;
19061934

1935+
bool site_taken = false;
1936+
19071937
auto site = siteTypeList[site_in_tile.getPrimaryType()];
1938+
site_taken |= take_sites_.count(site.getName()) != 0;
1939+
for (auto alt_site_idx : site.getAltSiteTypes()){
1940+
auto alt_site = siteTypeList[alt_site_idx];
1941+
site_taken |= take_sites_.count(alt_site.getName()) != 0;
1942+
}
19081943

1909-
if (take_sites_.count(site.getName()) == 0)
1944+
if (!site_taken)
19101945
continue;
19111946

19121947
sub_tile.index = type.capacity;

vpr/src/route/rr_graph_fpga_interchange.cpp

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,17 +1300,29 @@ struct InterchangeRRGraphBuilder {
13001300
*/
13011301
int next_good_site(int first_idx, const Device::Tile::Reader tile) {
13021302
auto tile_type = ar_.getTileTypeList()[tile.getType()];
1303+
auto site_types = ar_.getSiteTypeList();
13031304
size_t ans = first_idx;
13041305
for (; ans < tile.getSites().size(); ans++) {
13051306
auto site = tile.getSites()[ans];
1306-
auto site_type = ar_.getSiteTypeList()[tile_type.getSiteTypes()[site.getType()].getPrimaryType()];
1307-
1307+
auto site_type = site_types[tile_type.getSiteTypes()[site.getType()].getPrimaryType()];
13081308
bool found = false;
13091309
for (auto bel : site_type.getBels())
13101310
found |= bel_cell_mappings_.find(bel.getName()) != bel_cell_mappings_.end();
13111311

13121312
if (found)
13131313
break;
1314+
for(auto alt_site_idx : site_type.getAltSiteTypes()) {
1315+
auto alt_site = site_types[alt_site_idx];
1316+
for (auto bel : alt_site.getBels()) {
1317+
auto bel_name = bel.getName();
1318+
bool res = bel_cell_mappings_.find(bel_name) != bel_cell_mappings_.end();
1319+
found |= res;
1320+
}
1321+
if (found)
1322+
break;
1323+
}
1324+
if (found)
1325+
break;
13141326
}
13151327

13161328
return ans;
@@ -1478,7 +1490,7 @@ struct InterchangeRRGraphBuilder {
14781490
}
14791491

14801492
void pack_tiles() {
1481-
for (auto& node_loc : sink_source_loc_map_) {
1493+
for (const auto& node_loc : sink_source_loc_map_) {
14821494
int tile_id = node_loc.first;
14831495
int x, y;
14841496
t_location loc = tile_loc_bimap_[tile_id];
@@ -1624,7 +1636,7 @@ struct InterchangeRRGraphBuilder {
16241636
}
16251637

16261638
void pack_tiles_edges() {
1627-
for (auto& i : sink_source_loc_map_) {
1639+
for (const auto& i : sink_source_loc_map_) {
16281640
int tile_id = i.first;
16291641
int x, y;
16301642
t_location loc = tile_loc_bimap_[tile_id];
@@ -1638,22 +1650,22 @@ struct InterchangeRRGraphBuilder {
16381650
if (node_id == -1)
16391651
continue;
16401652

1641-
auto virtual_chan_key = virtual_redirect_[std::make_tuple(node_id, loc)];
16421653
e_rr_type pin = input ? e_rr_type::SINK : e_rr_type::SOURCE;
16431654
e_rr_type mux = input ? e_rr_type::IPIN : e_rr_type::OPIN;
1655+
1656+
auto virtual_chan_key = virtual_redirect_[std::make_tuple(node_id, loc)];
16441657
auto chan_key = std::make_tuple(std::get<0>(virtual_chan_key),
16451658
std::get<1>(virtual_chan_key),
16461659
virtual_beg_to_real_[virtual_chan_key]);
16471660

1648-
int pin_id, mux_id, track_id;
1649-
pin_id = loc_type_idx_to_rr_idx_[std::make_tuple(loc, pin, ipin)];
1650-
mux_id = loc_type_idx_to_rr_idx_[std::make_tuple(loc, mux, ipin)];
1651-
track_id = loc_type_idx_to_rr_idx_[chan_key];
1661+
int pin_id = loc_type_idx_to_rr_idx_[std::make_tuple(loc, pin, ipin)];
1662+
int mux_id = loc_type_idx_to_rr_idx_[std::make_tuple(loc, mux, ipin)];
1663+
1664+
int track_id = loc_type_idx_to_rr_idx_[chan_key];
16521665

1653-
int sink, sink_src, src;
1654-
sink = input ? pin_id : track_id;
1655-
sink_src = mux_id;
1656-
src = input ? track_id : pin_id;
1666+
int sink = input ? pin_id : track_id;
1667+
int sink_src = mux_id;
1668+
int src = input ? track_id : pin_id;
16571669

16581670
device_ctx_.rr_graph_builder.emplace_back_edge(RRNodeId(src),
16591671
RRNodeId(sink_src),

0 commit comments

Comments
 (0)