Skip to content

Commit 53a91e9

Browse files
committed
place: fix equivalent placement issues
In addition now physical_tile_type() and logical_block_type() returns the highest priority corresponding type Signed-off-by: Alessandro Comodi <[email protected]>
1 parent ef08d57 commit 53a91e9

File tree

5 files changed

+69
-37
lines changed

5 files changed

+69
-37
lines changed

libs/libarchfpga/src/physical_types.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -609,8 +609,12 @@ struct t_physical_tile_type {
609609

610610
std::vector<std::string> equivalent_sites_names;
611611
std::vector<t_logical_block_type_ptr> equivalent_sites;
612-
613-
/* Unordered map indexed by the logical block index.
612+
613+
/* Map holding the priority for which this logical block needs to be placed.
614+
* logical_blocks_priority[priority] -> vector holding the logical_block indices */
615+
std::map<int, std::vector<int>> logical_blocks_priority;
616+
617+
/* Unordered map indexed by the logical block index.
614618
* tile_block_pin_directs_map[logical block index][logical block pin] -> physical tile pin */
615619
std::unordered_map<int, std::unordered_map<int, int>> tile_block_pin_directs_map;
616620

@@ -669,7 +673,10 @@ struct t_logical_block_type {
669673
int index = -1; /* index of type descriptor in array (allows for index referencing) */
670674

671675
std::vector<t_physical_tile_type_ptr> equivalent_tiles;
672-
std::map<int, std::vector<t_physical_tile_type_ptr>> placement_priority;
676+
677+
/* Map holding the priority for which this logical block needs to be placed.
678+
* physical_tiles_priority[priority] -> vector holding the physical tile indices */
679+
std::map<int, std::vector<int>> physical_tiles_priority;
673680
};
674681

675682
/*************************************************************************************************

libs/libarchfpga/src/read_xml_arch_file.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2976,6 +2976,8 @@ static void ProcessTiles(pugi::xml_node Node,
29762976

29772977
t_physical_tile_type PhysicalTileType;
29782978

2979+
PhysicalTileType.index = index;
2980+
29792981
/* Parses the properties fields of the type */
29802982
ProcessTileProps(CurTileType, &PhysicalTileType, loc_data);
29812983

@@ -3025,8 +3027,6 @@ static void ProcessTiles(pugi::xml_node Node,
30253027
Cur = get_single_child(CurTileType, "equivalent_sites", loc_data, ReqOpt::REQUIRED);
30263028
ProcessTileEquivalentSites(Cur, &PhysicalTileType, LogicalBlockTypes, loc_data);
30273029

3028-
PhysicalTileType.index = index;
3029-
30303030
/* Type fully read */
30313031
++index;
30323032

@@ -3217,15 +3217,16 @@ static void ProcessTileEquivalentSites(pugi::xml_node Parent,
32173217
while (CurSite) {
32183218
check_node(CurSite, "site", loc_data);
32193219

3220-
expect_only_attributes(CurSite, {"pb_type"}, loc_data);
3220+
expect_only_attributes(CurSite, {"pb_type", "priority"}, loc_data);
32213221
/* Load equivalent site name */
32223222
auto Prop = std::string(get_attribute(CurSite, "pb_type", loc_data).value());
32233223
PhysicalTileType->equivalent_sites_names.push_back(Prop);
32243224

32253225
auto LogicalBlockType = get_type_by_name<t_logical_block_type>(Prop.c_str(), LogicalBlockTypes);
32263226

32273227
auto priority = get_attribute(CurSite, "priority", loc_data, ReqOpt::OPTIONAL).as_int(0);
3228-
LogicalBlockType->placement_priority[priority].push_back(PhysicalTileType);
3228+
LogicalBlockType->physical_tiles_priority[priority].push_back(PhysicalTileType->index);
3229+
PhysicalTileType->logical_blocks_priority[priority].push_back(LogicalBlockType->index);
32293230

32303231
ProcessEquivalentSiteDirects(CurSite, PhysicalTileType, LogicalBlockType, Prop, loc_data);
32313232

@@ -4796,8 +4797,7 @@ static void check_port_direct_mappings(t_physical_tile_type_ptr physical_tile, t
47964797
auto block_port = get_port_by_pin(logical_block, pin_map.first);
47974798
auto tile_port = get_port_by_pin(physical_tile, pin_map.second);
47984799

4799-
if (0 != strcmp(tile_port->name, block_port->name)
4800-
|| tile_port->type != block_port->type
4800+
if (tile_port->type != block_port->type
48014801
|| tile_port->num_pins != block_port->num_pins
48024802
|| tile_port->equivalent != block_port->equivalent) {
48034803
archfpga_throw(__FILE__, __LINE__,
@@ -4832,7 +4832,7 @@ static const t_port* get_port_by_name(t_logical_block_type_ptr type, const char*
48324832

48334833
static const t_physical_tile_port* get_port_by_pin(t_physical_tile_type_ptr type, int pin) {
48344834
for (auto port : type->ports) {
4835-
if (pin >= port.absolute_first_pin_index && pin < port.num_pins) {
4835+
if (pin >= port.absolute_first_pin_index && pin < port.absolute_first_pin_index + port.num_pins) {
48364836
return &type->ports[port.index];
48374837
}
48384838
}
@@ -4845,7 +4845,7 @@ static const t_port* get_port_by_pin(t_logical_block_type_ptr type, int pin) {
48454845

48464846
for (int i = 0; i < pb_type->num_ports; i++) {
48474847
auto port = pb_type->ports[i];
4848-
if (pin >= port.absolute_first_pin_index && pin < port.num_pins) {
4848+
if (pin >= port.absolute_first_pin_index && pin < port.absolute_first_pin_index + port.num_pins) {
48494849
return &pb_type->ports[port.index];
48504850
}
48514851
}

vpr/src/place/move_utils.cpp

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,33 @@ bool find_to_loc_uniform(t_physical_tile_type_ptr type,
588588
if (cx_from == cx_to && cy_from == cy_to) {
589589
continue; //Same from/to location -- try again for new y-position
590590
} else {
591-
legal = true;
591+
VTR_ASSERT(cx_to != OPEN);
592+
VTR_ASSERT(cy_to != OPEN);
593+
594+
//Convert to true (uncompressed) grid locations
595+
to.x = to_compressed_block_grid.compressed_to_grid_x[cx_to];
596+
to.y = to_compressed_block_grid.compressed_to_grid_y[cy_to];
597+
598+
auto& place_ctx = g_vpr_ctx.placement();
599+
auto& cluster_ctx = g_vpr_ctx.clustering();
600+
601+
auto blocks = place_ctx.grid_blocks[to.x][to.y].blocks;
602+
bool impossible_swap = false;
603+
for (auto blk : blocks) {
604+
if (blk == ClusterBlockId::INVALID()) {
605+
continue;
606+
}
607+
608+
auto block_type = cluster_ctx.clb_nlist.block_type(blk);
609+
if (!is_tile_compatible(from_type, block_type)) {
610+
impossible_swap = true;
611+
break;
612+
}
613+
}
614+
615+
if (!impossible_swap) {
616+
legal = true;
617+
}
592618
}
593619
}
594620
}
@@ -598,13 +624,6 @@ bool find_to_loc_uniform(t_physical_tile_type_ptr type,
598624
return false;
599625
}
600626

601-
VTR_ASSERT(cx_to != OPEN);
602-
VTR_ASSERT(cy_to != OPEN);
603-
604-
//Convert to true (uncompressed) grid locations
605-
to.x = to_compressed_block_grid.compressed_to_grid_x[cx_to];
606-
to.y = to_compressed_block_grid.compressed_to_grid_y[cy_to];
607-
608627
//Each x/y location contains only a single type, so we can pick a random
609628
//z (capcity) location
610629
to.z = vtr::irand(type->capacity - 1);

vpr/src/place/place.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ static void placement_inner_loop(float t,
418418

419419
static void recompute_costs_from_scratch(const t_placer_opts& placer_opts, const PlaceDelayModel* delay_model, t_placer_costs* costs);
420420

421-
static t_physical_tile_type_ptr pick_highest_priority_type(t_logical_block_type_ptr logical_block, int num_needed_types, int* free_locations);
421+
static t_physical_tile_type_ptr pick_highest_placement_priority_type(t_logical_block_type_ptr logical_block, int num_needed_types, int* free_locations);
422422

423423
static void calc_placer_stats(t_placer_statistics& stats, float& success_rat, double& std_dev, const t_placer_costs& costs, const int move_lim);
424424

@@ -2410,7 +2410,7 @@ static void initial_placement_pl_macros(int macros_max_num_tries, int* free_loca
24102410
// Assume that all the blocks in the macro are of the same type
24112411
blk_id = pl_macros[imacro].members[0].blk_index;
24122412
auto logical_block = cluster_ctx.clb_nlist.block_type(blk_id);
2413-
auto type = pick_highest_priority_type(logical_block, int(pl_macros[imacro].members.size()), free_locations);
2413+
auto type = pick_highest_placement_priority_type(logical_block, int(pl_macros[imacro].members.size()), free_locations);
24142414

24152415
if (type == nullptr) {
24162416
VPR_FATAL_ERROR(VPR_ERROR_PLACE,
@@ -2488,7 +2488,7 @@ static void initial_placement_blocks(int* free_locations, enum e_pad_loc_type pa
24882488
* that location again, so remove it from the free_locations array.
24892489
*/
24902490

2491-
auto type = pick_highest_priority_type(logical_block, 1, free_locations);
2491+
auto type = pick_highest_placement_priority_type(logical_block, 1, free_locations);
24922492

24932493
if (type == nullptr) {
24942494
VPR_FATAL_ERROR(VPR_ERROR_PLACE,
@@ -2850,12 +2850,15 @@ int check_macro_placement_consistency() {
28502850
return error;
28512851
}
28522852

2853-
static t_physical_tile_type_ptr pick_highest_priority_type(t_logical_block_type_ptr logical_block, int num_needed_types, int* free_locations) {
2853+
static t_physical_tile_type_ptr pick_highest_placement_priority_type(t_logical_block_type_ptr logical_block, int num_needed_types, int* free_locations) {
2854+
auto& device_ctx = g_vpr_ctx.device();
2855+
auto physical_tiles = device_ctx.physical_tile_types;
2856+
28542857
// Loop through the ordered map to get tiles in a decreasing priority order
2855-
for (auto& physical_tiles : logical_block->placement_priority) {
2856-
for (auto tile : physical_tiles.second) {
2857-
if (free_locations[tile->index] >= num_needed_types) {
2858-
return tile;
2858+
for (auto& physical_tiles_ids : logical_block->physical_tiles_priority) {
2859+
for (auto tile_id : physical_tiles_ids.second) {
2860+
if (free_locations[tile_id] >= num_needed_types) {
2861+
return &physical_tiles[tile_id];
28592862
}
28602863
}
28612864
}

vpr/src/util/vpr_utils.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -646,12 +646,13 @@ bool is_empty_type(t_logical_block_type_ptr type) {
646646

647647
t_physical_tile_type_ptr physical_tile_type(t_logical_block_type_ptr logical_block_type) {
648648
auto& device_ctx = g_vpr_ctx.device();
649+
auto& physical_tiles = device_ctx.physical_tile_types;
649650

650-
if (0 == logical_block_type->equivalent_tiles.size())
651-
return device_ctx.EMPTY_PHYSICAL_TILE_TYPE;
652-
653-
for (auto type : logical_block_type->equivalent_tiles) {
654-
if (0 == strcmp(type->name, logical_block_type->name)) return type;
651+
// Loop through the ordered map to get tiles in a decreasing priority order
652+
for (auto& physical_tiles_ids : logical_block_type->physical_tiles_priority) {
653+
for (auto tile_id : physical_tiles_ids.second) {
654+
return &physical_tiles[tile_id];
655+
}
655656
}
656657

657658
return nullptr;
@@ -669,13 +670,15 @@ t_physical_tile_type_ptr physical_tile_type(ClusterBlockId blk) {
669670

670671
t_logical_block_type_ptr logical_block_type(t_physical_tile_type_ptr physical_tile_type) {
671672
auto& device_ctx = g_vpr_ctx.device();
673+
auto& logical_blocks = device_ctx.logical_block_types;
672674

673-
if (0 == physical_tile_type->equivalent_sites.size())
674-
return device_ctx.EMPTY_LOGICAL_BLOCK_TYPE;
675-
676-
for (auto type : physical_tile_type->equivalent_sites) {
677-
if (0 == strcmp(type->name, physical_tile_type->name)) return type;
675+
// Loop through the ordered map to get tiles in a decreasing priority order
676+
for (auto& logical_blocks_ids : physical_tile_type->logical_blocks_priority) {
677+
for (auto block_id : logical_blocks_ids.second) {
678+
return &logical_blocks[block_id];
679+
}
678680
}
681+
679682
return nullptr;
680683
}
681684

0 commit comments

Comments
 (0)