Skip to content

Commit 324d7fa

Browse files
committed
vpr: addressed review comments and fixed compilation errors
Signed-off-by: Alessandro Comodi <[email protected]>
1 parent e867548 commit 324d7fa

File tree

7 files changed

+275
-272
lines changed

7 files changed

+275
-272
lines changed

libs/libarchfpga/src/physical_types.h

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ struct t_equivalent_site;
5959
struct t_physical_tile_type;
6060
typedef const t_physical_tile_type* t_physical_tile_type_ptr;
6161
struct t_sub_tile;
62+
struct t_capacity_range;
6263
struct t_logical_block_type;
6364
typedef const t_logical_block_type* t_logical_block_type_ptr;
6465
struct t_logical_pin;
@@ -583,7 +584,7 @@ struct t_physical_tile_type {
583584
int width = 0;
584585
int height = 0;
585586

586-
std::vector<std::vector<std::vector<std::vector<bool>>>> pinloc; /* [0..width-1][0..height-1][0..3][0..num_pins-1] */
587+
vtr::NdMatrix<std::vector<bool>, 3> pinloc; /* [0..width-1][0..height-1][0..3][0..num_pins-1] */
587588

588589
std::vector<t_class> class_inf; /* [0..num_class-1] */
589590

@@ -627,6 +628,34 @@ struct t_physical_tile_type {
627628
bool is_output_type;
628629
};
629630

631+
/* Holds the capacity range of a certain sub_tile block within the parent physical tile type.
632+
* E.g. TILE_X has the following sub tiles:
633+
* - SUB_TILE_A: capacity_range --> 0 to 4
634+
* - SUB_TILE_B: capacity_range --> 5 to 11
635+
* - SUB_TILE_C: capacity_range --> 12 to 16
636+
*
637+
* Totale TILE_X capacity is 17
638+
*/
639+
struct t_capacity_range {
640+
private:
641+
int low = 0;
642+
int high = 0;
643+
644+
public:
645+
void set(int low_cap, int high_cap) {
646+
low = low_cap;
647+
high = high_cap;
648+
}
649+
650+
bool is_in_range(int cap) const {
651+
return cap >= low or cap <= high;
652+
}
653+
654+
int total() const {
655+
return high - low + 1;
656+
}
657+
};
658+
630659
/** Describes the possible placeable blocks within a physical tile type.
631660
* A sub tile adds flexibility in the tile composition description.
632661
*/
@@ -641,7 +670,9 @@ struct t_sub_tile {
641670

642671
std::vector<t_logical_block_type_ptr> equivalent_sites;
643672

644-
int capacity = 0;
673+
t_capacity_range capacity;
674+
675+
int num_phy_pins = 0;
645676

646677
int index = -1;
647678
};

libs/libarchfpga/src/read_xml_arch_file.cpp

Lines changed: 46 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -73,25 +73,26 @@ struct t_fc_override {
7373
};
7474

7575
struct t_pin_counts {
76-
int total = 0;
7776
int input = 0;
7877
int output = 0;
7978
int clock = 0;
8079

81-
void sum() {
82-
total = input + output + clock;
80+
int total() {
81+
return input + output + clock;
8382
}
8483
};
8584

86-
struct t_pin_loc {
85+
struct t_pin_locs {
8786
private:
87+
// Distribution must be set once for each physical tile type
88+
// and must be equal for each sub tile within a physical tile.
8889
bool distribution_set = false;
8990

9091
public:
9192
enum e_pin_location_distr distribution = E_SPREAD_PIN_DISTR;
9293

9394
/* [0..num_sub_tiles-1][0..width-1][0..height-1][0..3][0..num_tokens-1] */
94-
std::vector<std::vector<std::vector<std::vector<std::vector<std::string>>>>> assignments;
95+
vtr::NdMatrix<std::vector<std::string>, 4> assignments;
9596

9697
bool is_distribution_set() {
9798
return distribution_set;
@@ -113,7 +114,7 @@ static void SetupPinClasses(t_physical_tile_type* PhysicalTileType);
113114

114115
static void LoadPinLoc(pugi::xml_node Locations,
115116
t_physical_tile_type* type,
116-
t_pin_loc* pin_loc,
117+
t_pin_locs* pin_locs,
117118
const pugiutil::loc_data& loc_data);
118119
template<typename T>
119120
static std::pair<int, int> ProcessPinString(pugi::xml_node Locations,
@@ -160,7 +161,7 @@ static void ProcessEquivalentSiteCustomConnection(pugi::xml_node Parent,
160161
static void ProcessPinLocations(pugi::xml_node Locations,
161162
t_physical_tile_type* PhysicalTileType,
162163
t_sub_tile* SubTile,
163-
t_pin_loc* pin_loc,
164+
t_pin_locs* pin_locs,
164165
const pugiutil::loc_data& loc_data);
165166
static void ProcessSubTiles(pugi::xml_node Node,
166167
t_physical_tile_type* PhysicalTileType,
@@ -480,8 +481,9 @@ static void SetupPinClasses(t_physical_tile_type* PhysicalTileType) {
480481
pin_count = 0;
481482

482483
/* Equivalent pins share the same class, non-equivalent pins belong to different pin classes */
483-
for (const auto& sub_tile : PhysicalTileType->sub_tiles) {
484-
for (i = 0; i < sub_tile.capacity; ++i) {
484+
for (auto& sub_tile : PhysicalTileType->sub_tiles) {
485+
int capacity = sub_tile.capacity.total();
486+
for (i = 0; i < capacity; ++i) {
485487
for (const auto& port : sub_tile.ports) {
486488
if (port.equivalent != PortEquivalence::NONE) {
487489
t_class class_inf;
@@ -544,13 +546,13 @@ static void SetupPinClasses(t_physical_tile_type* PhysicalTileType) {
544546

545547
static void LoadPinLoc(pugi::xml_node Locations,
546548
t_physical_tile_type* type,
547-
t_pin_loc* pin_loc,
549+
t_pin_locs* pin_locs,
548550
const pugiutil::loc_data& loc_data) {
549551
type->pin_width_offset.resize(type->num_pins, 0);
550552
type->pin_height_offset.resize(type->num_pins, 0);
551553

552554
std::vector<int> physical_pin_counts(type->num_pins, 0);
553-
if (pin_loc->distribution == E_SPREAD_PIN_DISTR) {
555+
if (pin_locs->distribution == E_SPREAD_PIN_DISTR) {
554556
/* evenly distribute pins starting at bottom left corner */
555557

556558
int num_sides = 4 * (type->width * type->height);
@@ -575,7 +577,7 @@ static void LoadPinLoc(pugi::xml_node Locations,
575577
}
576578
VTR_ASSERT(side_index == num_sides);
577579
VTR_ASSERT(count == type->num_pins);
578-
} else if (pin_loc->distribution == E_PERIMETER_PIN_DISTR) {
580+
} else if (pin_locs->distribution == E_PERIMETER_PIN_DISTR) {
579581
//Add one pin at-a-time to perimeter sides in round-robin order
580582
int ipin = 0;
581583
while (ipin < type->num_pins) {
@@ -601,7 +603,7 @@ static void LoadPinLoc(pugi::xml_node Locations,
601603
}
602604
VTR_ASSERT(ipin == type->num_pins);
603605

604-
} else if (pin_loc->distribution == E_SPREAD_INPUTS_PERIMETER_OUTPUTS_PIN_DISTR) {
606+
} else if (pin_locs->distribution == E_SPREAD_INPUTS_PERIMETER_OUTPUTS_PIN_DISTR) {
605607
//Collect the sets of block input/output pins
606608
std::vector<int> input_pins;
607609
std::vector<int> output_pins;
@@ -668,23 +670,24 @@ static void LoadPinLoc(pugi::xml_node Locations,
668670
VTR_ASSERT(ipin == output_pins.size());
669671

670672
} else {
671-
VTR_ASSERT(pin_loc->distribution == E_CUSTOM_PIN_DISTR);
673+
VTR_ASSERT(pin_locs->distribution == E_CUSTOM_PIN_DISTR);
672674
for (auto& sub_tile : type->sub_tiles) {
673675
int sub_tile_index = sub_tile.index;
676+
int sub_tile_capacity = sub_tile.capacity.total();
674677

675678
for (int width = 0; width < type->width; ++width) {
676679
for (int height = 0; height < type->height; ++height) {
677680
for (e_side side : {TOP, RIGHT, BOTTOM, LEFT}) {
678-
for (auto token : pin_loc->assignments[sub_tile_index][width][height][side]) {
681+
for (auto token : pin_locs->assignments[sub_tile_index][width][height][side]) {
679682
auto pin_range = ProcessPinString<t_sub_tile*>(Locations,
680683
&sub_tile,
681684
token.c_str(),
682685
loc_data);
683686

684687
for (int pin_num = pin_range.first; pin_num < pin_range.second; ++pin_num) {
685-
VTR_ASSERT(pin_num < (int)sub_tile.sub_tile_to_tile_pin_indices.size() / sub_tile.capacity);
686-
for (int capacity = 0; capacity < sub_tile.capacity; ++capacity) {
687-
int sub_tile_pin_index = pin_num + capacity * type->num_pins / sub_tile.capacity;
688+
VTR_ASSERT(pin_num < (int)sub_tile.sub_tile_to_tile_pin_indices.size() / sub_tile_capacity);
689+
for (int capacity = 0; capacity < sub_tile_capacity; ++capacity) {
690+
int sub_tile_pin_index = pin_num + capacity * type->num_pins / sub_tile_capacity;
688691
int physical_pin_index = sub_tile.sub_tile_to_tile_pin_indices[sub_tile_pin_index];
689692
type->pinloc[width][height][side][physical_pin_index] = true;
690693
type->pin_width_offset[physical_pin_index] += width;
@@ -1930,9 +1933,9 @@ static void Process_Fc(pugi::xml_node Node,
19301933

19311934
/* Go through all the port/segment combinations and create the (potentially
19321935
* overriden) pin/seg Fc specifications */
1933-
int pins_per_capacity_instance = pin_counts.total / SubTile->capacity;
1936+
int pins_per_capacity_instance = pin_counts.total() / SubTile->capacity.total();
19341937
for (size_t iseg = 0; iseg < segments.size(); ++iseg) {
1935-
for (int icapacity = 0; icapacity < SubTile->capacity; ++icapacity) {
1938+
for (int icapacity = 0; icapacity < SubTile->capacity.total(); ++icapacity) {
19361939
//If capacity > 0, we need t offset the block index by the number of pins per instance
19371940
//this ensures that all pins have an Fc specification
19381941
int iblk_pin = icapacity * pins_per_capacity_instance;
@@ -3003,8 +3006,6 @@ static t_pin_counts ProcessSubTilePorts(pugi::xml_node Parent,
30033006
}
30043007
}
30053008

3006-
pin_counts.sum();
3007-
30083009
return pin_counts;
30093010
}
30103011

@@ -3124,7 +3125,7 @@ static void ProcessEquivalentSiteDirectConnection(pugi::xml_node Parent,
31243125
t_physical_tile_type* PhysicalTileType,
31253126
t_logical_block_type* LogicalBlockType,
31263127
const pugiutil::loc_data& loc_data) {
3127-
int num_pins = (int)SubTile->sub_tile_to_tile_pin_indices.size() / SubTile->capacity;
3128+
int num_pins = (int)SubTile->sub_tile_to_tile_pin_indices.size() / SubTile->capacity.total();
31283129

31293130
if (num_pins != LogicalBlockType->pb_type->num_pins) {
31303131
archfpga_throw(loc_data.filename_c_str(), loc_data.line(Parent),
@@ -3207,7 +3208,7 @@ static void ProcessEquivalentSiteCustomConnection(pugi::xml_node Parent,
32073208
static void ProcessPinLocations(pugi::xml_node Locations,
32083209
t_physical_tile_type* PhysicalTileType,
32093210
t_sub_tile* SubTile,
3210-
t_pin_loc* pin_loc,
3211+
t_pin_locs* pin_locs,
32113212
const pugiutil::loc_data& loc_data) {
32123213
pugi::xml_node Cur;
32133214
const char* Prop;
@@ -3233,16 +3234,16 @@ static void ProcessPinLocations(pugi::xml_node Locations,
32333234
distribution = E_SPREAD_PIN_DISTR;
32343235
}
32353236

3236-
if (pin_loc->is_distribution_set()) {
3237-
if (pin_loc->distribution != distribution) {
3237+
if (pin_locs->is_distribution_set()) {
3238+
if (pin_locs->distribution != distribution) {
32383239
archfpga_throw(loc_data.filename_c_str(), loc_data.line(Locations),
32393240
"Sub Tile %s has a different pin location pattern (%s) with respect "
32403241
"to the sibling sub tiles",
32413242
SubTile->name, Prop);
32423243
}
32433244
} else {
3244-
pin_loc->distribution = distribution;
3245-
pin_loc->set_distribution();
3245+
pin_locs->distribution = distribution;
3246+
pin_locs->set_distribution();
32463247
}
32473248

32483249
int sub_tile_index = SubTile->index;
@@ -3303,7 +3304,7 @@ static void ProcessPinLocations(pugi::xml_node Locations,
33033304
if (Count > 0) {
33043305
for (int pin = 0; pin < Count; ++pin) {
33053306
/* Store location assignment */
3306-
pin_loc->assignments[sub_tile_index][x_offset][y_offset][side].push_back(std::string(Tokens[pin].c_str()));
3307+
pin_locs->assignments[sub_tile_index][x_offset][y_offset][side].push_back(std::string(Tokens[pin].c_str()));
33073308

33083309
/* Advance through list of pins in this location */
33093310
}
@@ -3318,7 +3319,7 @@ static void ProcessPinLocations(pugi::xml_node Locations,
33183319
for (int w = 0; w < PhysicalTileType->width; ++w) {
33193320
for (int h = 0; h < PhysicalTileType->height; ++h) {
33203321
for (e_side side : {TOP, RIGHT, BOTTOM, LEFT}) {
3321-
for (auto token : pin_loc->assignments[sub_tile_index][w][h][side]) {
3322+
for (auto token : pin_locs->assignments[sub_tile_index][w][h][side]) {
33223323
InstPort inst_port(token.c_str());
33233324

33243325
//A pin specification should contain only the block name, and not any instace count information
@@ -3398,24 +3399,15 @@ static void ProcessSubTiles(pugi::xml_node Node,
33983399
pugi::xml_node Cur;
33993400
int index = 0;
34003401

3401-
int num_sub_tiles = count_children(Node, "sub_tile", loc_data);
3402-
int width = PhysicalTileType->width;
3403-
int height = PhysicalTileType->height;
3404-
int num_sides = 4;
3402+
unsigned long int num_sub_tiles = count_children(Node, "sub_tile", loc_data);
3403+
unsigned long int width = PhysicalTileType->width;
3404+
unsigned long int height = PhysicalTileType->height;
3405+
unsigned long int num_sides = 4;
34053406

34063407
std::map<std::string, int> sub_tile_names;
34073408

3408-
t_pin_loc pin_loc;
3409-
pin_loc.assignments.resize(num_sub_tiles);
3410-
for (int isub_tile = 0; isub_tile < num_sub_tiles; isub_tile++) {
3411-
pin_loc.assignments[isub_tile].resize(width);
3412-
for (int iwidth = 0; iwidth < width; iwidth++) {
3413-
pin_loc.assignments[isub_tile][iwidth].resize(height);
3414-
for (int iheight = 0; iheight < height; iheight++) {
3415-
pin_loc.assignments[isub_tile][iwidth][iheight].resize(num_sides);
3416-
}
3417-
}
3418-
}
3409+
t_pin_locs pin_locs;
3410+
pin_locs.assignments.resize({num_sub_tiles, width, height, num_sides});
34193411

34203412
if (num_sub_tiles == 0) {
34213413
archfpga_throw(loc_data.filename_c_str(), loc_data.line(Node),
@@ -3448,7 +3440,7 @@ static void ProcessSubTiles(pugi::xml_node Node,
34483440

34493441
/* Load properties */
34503442
unsigned int capacity = get_attribute(CurSubTile, "capacity", loc_data, ReqOpt::OPTIONAL).as_uint(1);
3451-
SubTile.capacity = capacity;
3443+
SubTile.capacity.set(PhysicalTileType->capacity, capacity - 1);
34523444
PhysicalTileType->capacity += capacity;
34533445

34543446
/* Process sub tile port definitions */
@@ -3457,22 +3449,24 @@ static void ProcessSubTiles(pugi::xml_node Node,
34573449
/* Map Sub Tile physical pins with the Physical Tile Type physical pins.
34583450
* This takes into account the capacity of each sub tiles to add the correct offset.
34593451
*/
3460-
for (int ipin = 0; ipin < (int)capacity * pin_counts.total; ipin++) {
3452+
for (int ipin = 0; ipin < (int)capacity * pin_counts.total(); ipin++) {
34613453
SubTile.sub_tile_to_tile_pin_indices.push_back(PhysicalTileType->num_pins + ipin);
34623454
}
34633455

3456+
SubTile.num_phy_pins = pin_counts.total() * capacity;
3457+
34643458
/* Assign pin counts to the Physical Tile Type */
34653459
PhysicalTileType->num_input_pins += capacity * pin_counts.input;
34663460
PhysicalTileType->num_output_pins += capacity * pin_counts.output;
34673461
PhysicalTileType->num_clock_pins += capacity * pin_counts.clock;
3468-
PhysicalTileType->num_pins += capacity * pin_counts.total;
3462+
PhysicalTileType->num_pins += capacity * pin_counts.total();
34693463

34703464
/* Assign drivers and receivers count to Physical Tile Type */
34713465
PhysicalTileType->num_receivers += capacity * pin_counts.input;
34723466
PhysicalTileType->num_drivers += capacity * pin_counts.output;
34733467

34743468
Cur = get_single_child(CurSubTile, "pinlocations", loc_data, ReqOpt::OPTIONAL);
3475-
ProcessPinLocations(Cur, PhysicalTileType, &SubTile, &pin_loc, loc_data);
3469+
ProcessPinLocations(Cur, PhysicalTileType, &SubTile, &pin_locs, loc_data);
34763470

34773471
/* Load Fc */
34783472
Cur = get_single_child(CurSubTile, "fc", loc_data, ReqOpt::OPTIONAL);
@@ -3491,19 +3485,10 @@ static void ProcessSubTiles(pugi::xml_node Node,
34913485

34923486
// Initialize pinloc data structure.
34933487
int num_pins = PhysicalTileType->num_pins;
3494-
PhysicalTileType->pinloc.resize(width);
3495-
for (int iwidth = 0; iwidth < width; iwidth++) {
3496-
PhysicalTileType->pinloc[iwidth].resize(height);
3497-
for (int iheight = 0; iheight < height; iheight++) {
3498-
PhysicalTileType->pinloc[iwidth][iheight].resize(num_sides);
3499-
for (int iside = 0; iside < num_sides; iside++) {
3500-
PhysicalTileType->pinloc[iwidth][iheight][iside].resize(num_pins);
3501-
}
3502-
}
3503-
}
3488+
PhysicalTileType->pinloc.resize({width, height, num_sides}, std::vector<bool>(num_pins, false));
35043489

35053490
SetupPinClasses(PhysicalTileType);
3506-
LoadPinLoc(Cur, PhysicalTileType, &pin_loc, loc_data);
3491+
LoadPinLoc(Cur, PhysicalTileType, &pin_locs, loc_data);
35073492
}
35083493

35093494
/* Takes in node pointing to <typelist> and loads all the
@@ -4969,6 +4954,7 @@ e_side string_to_side(std::string side_str) {
49694954
return side;
49704955
}
49714956

4957+
// TODO: Correctly link the sub tiles with the correct logic tiles.
49724958
static void link_physical_logical_types(std::vector<t_physical_tile_type>& PhysicalTileTypes,
49734959
std::vector<t_logical_block_type>& LogicalBlockTypes) {
49744960
for (auto& physical_tile : PhysicalTileTypes) {

vpr/src/place/place.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,9 +1706,6 @@ static void free_placement_structs(const t_placer_opts& placer_opts) {
17061706
}
17071707

17081708
free_placement_macros_structs();
1709-
1710-
/* Frees up all the data structure used in vpr_utils. */
1711-
free_blk_pin_from_port_pin();
17121709
}
17131710

17141711
/* Allocates the major structures needed only by the placer, primarily for *

vpr/src/place/timing_place_lookup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ std::vector<int> get_best_classes(enum e_pin_type pintype, t_physical_tile_type_
222222
std::vector<int> best_classes;
223223
int best_class_index = 0;
224224
//Collect all classes of matching type which do not have all their pins ignored
225-
for (auto class_inf : type->class_inf) {
225+
for (const auto& class_inf : type->class_inf) {
226226
if (class_inf.type == pintype) {
227227
bool all_ignored = true;
228228
for (int ipin = 0; ipin < class_inf.num_pins; ++ipin) {

0 commit comments

Comments
 (0)