Skip to content

Commit d076e56

Browse files
committed
Use 2 boolean's per physical types instead of std::set to mark IO types.
std::set is a fairly heavy-weight data structure, and consumes more memory and is slower than a boolean. Signed-off-by: Keith Rothman <[email protected]>
1 parent 9b13f5d commit d076e56

File tree

8 files changed

+83
-70
lines changed

8 files changed

+83
-70
lines changed

libs/libarchfpga/src/arch_util.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,3 +1321,38 @@ bool is_library_model(const char* model_name) {
13211321
bool is_library_model(const t_model* model) {
13221322
return is_library_model(model->name);
13231323
}
1324+
1325+
//Returns true if the specified block type contains the specified blif model name
1326+
bool block_type_contains_blif_model(t_logical_block_type_ptr type, const std::string& blif_model_name) {
1327+
return pb_type_contains_blif_model(type->pb_type, blif_model_name);
1328+
}
1329+
1330+
//Returns true of a pb_type (or it's children) contain the specified blif model name
1331+
bool pb_type_contains_blif_model(const t_pb_type* pb_type, const std::string& blif_model_name) {
1332+
if (!pb_type) {
1333+
return false;
1334+
}
1335+
1336+
if (pb_type->blif_model != nullptr) {
1337+
//Leaf pb_type
1338+
VTR_ASSERT(pb_type->num_modes == 0);
1339+
if (blif_model_name == pb_type->blif_model
1340+
|| ".subckt " + blif_model_name == pb_type->blif_model) {
1341+
return true;
1342+
} else {
1343+
return false;
1344+
}
1345+
} else {
1346+
for (int imode = 0; imode < pb_type->num_modes; ++imode) {
1347+
const t_mode* mode = &pb_type->modes[imode];
1348+
1349+
for (int ichild = 0; ichild < mode->num_pb_type_children; ++ichild) {
1350+
const t_pb_type* pb_type_child = &mode->pb_type_children[ichild];
1351+
if (pb_type_contains_blif_model(pb_type_child, blif_model_name)) {
1352+
return true;
1353+
}
1354+
}
1355+
}
1356+
}
1357+
return false;
1358+
}

libs/libarchfpga/src/arch_util.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef ARCH_UTIL_H
22
#define ARCH_UTIL_H
33

4+
#include <regex>
45
#include "physical_types.h"
56

67
class InstPort {
@@ -74,4 +75,11 @@ bool segment_exists(const t_arch* arch, std::string name);
7475
const t_segment_inf* find_segment(const t_arch* arch, std::string name);
7576
bool is_library_model(const char* model_name);
7677
bool is_library_model(const t_model* model);
78+
79+
//Returns true if the specified block type contains the specified blif model name
80+
bool block_type_contains_blif_model(t_logical_block_type_ptr type, const std::string& blif_model_name);
81+
82+
//Returns true of a pb_type (or it's children) contain the specified blif model name
83+
bool pb_type_contains_blif_model(const t_pb_type* pb_type, const std::string& blif_model_name);
84+
7785
#endif

libs/libarchfpga/src/physical_types.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,9 @@ struct t_physical_tile_type {
618618

619619
/* Returns the indices of pins that contain a clock for this physical logic block */
620620
std::vector<int> get_clock_pins_indices() const;
621+
622+
bool is_input_type;
623+
bool is_output_type;
621624
};
622625

623626
/** A logical pin defines the pin index of a logical block type (i.e. a top level PB type)

libs/libarchfpga/src/read_xml_arch_file.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ static void ProcessTiles(pugi::xml_node Node,
9898
const t_default_fc_spec& arch_def_fc,
9999
t_arch& arch,
100100
const pugiutil::loc_data& loc_data);
101+
static void MarkIoTypes(std::vector<t_physical_tile_type>& PhysicalTileTypes);
101102
static void ProcessTileProps(pugi::xml_node Node,
102103
t_physical_tile_type* PhysicalTileType,
103104
const pugiutil::loc_data& loc_data);
@@ -401,6 +402,7 @@ void XmlReadArch(const char* ArchFile,
401402
SyncModelsPbTypes(arch, LogicalBlockTypes);
402403
UpdateAndCheckModels(arch);
403404

405+
MarkIoTypes(PhysicalTileTypes);
404406
} catch (pugiutil::XmlError& e) {
405407
archfpga_throw(ArchFile, e.line(),
406408
"%s", e.what());
@@ -3047,6 +3049,27 @@ static void ProcessTiles(pugi::xml_node Node,
30473049
tile_type_descriptors.clear();
30483050
}
30493051

3052+
static void MarkIoTypes(std::vector<t_physical_tile_type>& PhysicalTileTypes) {
3053+
for (auto& type : PhysicalTileTypes) {
3054+
type.is_input_type = false;
3055+
type.is_output_type = false;
3056+
3057+
for (const auto& equivalent_site : type.equivalent_sites) {
3058+
if (block_type_contains_blif_model(equivalent_site, MODEL_INPUT)) {
3059+
type.is_input_type = true;
3060+
break;
3061+
}
3062+
}
3063+
3064+
for (const auto& equivalent_site : type.equivalent_sites) {
3065+
if (block_type_contains_blif_model(equivalent_site, MODEL_OUTPUT)) {
3066+
type.is_output_type = true;
3067+
break;
3068+
}
3069+
}
3070+
}
3071+
}
3072+
30503073
static void ProcessTileProps(pugi::xml_node Node,
30513074
t_physical_tile_type* PhysicalTileType,
30523075
const pugiutil::loc_data& loc_data) {

vpr/src/base/SetupVPR.cpp

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -112,24 +112,20 @@ void SetupVPR(const t_options* Options,
112112

113113
/* TODO: this is inelegant, I should be populating this information in XmlReadArch */
114114
device_ctx.EMPTY_PHYSICAL_TILE_TYPE = nullptr;
115-
for (const auto& type : device_ctx.physical_tile_types) {
115+
int num_inputs = 0;
116+
int num_outputs = 0;
117+
for (auto& type : device_ctx.physical_tile_types) {
116118
if (strcmp(type.name, EMPTY_BLOCK_NAME) == 0) {
117119
VTR_ASSERT(device_ctx.EMPTY_PHYSICAL_TILE_TYPE == nullptr);
118120
device_ctx.EMPTY_PHYSICAL_TILE_TYPE = &type;
119-
} else {
120-
for (const auto& equivalent_site : type.equivalent_sites) {
121-
if (block_type_contains_blif_model(equivalent_site, MODEL_INPUT)) {
122-
device_ctx.input_types.insert(&type);
123-
break;
124-
}
125-
}
121+
}
126122

127-
for (const auto& equivalent_site : type.equivalent_sites) {
128-
if (block_type_contains_blif_model(equivalent_site, MODEL_OUTPUT)) {
129-
device_ctx.output_types.insert(&type);
130-
break;
131-
}
132-
}
123+
if (type.is_input_type) {
124+
num_inputs += 1;
125+
}
126+
127+
if (type.is_output_type) {
128+
num_outputs += 1;
133129
}
134130
}
135131

@@ -149,12 +145,12 @@ void SetupVPR(const t_options* Options,
149145
VTR_ASSERT(device_ctx.EMPTY_PHYSICAL_TILE_TYPE != nullptr);
150146
VTR_ASSERT(device_ctx.EMPTY_LOGICAL_BLOCK_TYPE != nullptr);
151147

152-
if (device_ctx.input_types.empty()) {
148+
if (num_inputs == 0) {
153149
VPR_ERROR(VPR_ERROR_ARCH,
154150
"Architecture contains no top-level block type containing '.input' models");
155151
}
156152

157-
if (device_ctx.output_types.empty()) {
153+
if (num_outputs == 0) {
158154
VPR_ERROR(VPR_ERROR_ARCH,
159155
"Architecture contains no top-level block type containing '.output' models");
160156
}

vpr/src/base/vpr_context.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,6 @@ struct DeviceContext : public Context {
117117
/* x and y dimensions of the FPGA itself */
118118
DeviceGrid grid; /* FPGA complex block grid [0 .. grid.width()-1][0 .. grid.height()-1] */
119119

120-
/* Special pointers to identify special blocks on an FPGA: I/Os, unused, and default */
121-
std::set<t_physical_tile_type_ptr> input_types;
122-
std::set<t_physical_tile_type_ptr> output_types;
123-
124120
/* Empty types */
125121
t_physical_tile_type_ptr EMPTY_PHYSICAL_TILE_TYPE;
126122
t_logical_block_type_ptr EMPTY_LOGICAL_BLOCK_TYPE;

vpr/src/util/vpr_utils.cpp

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ static AtomPinId find_atom_pin_for_pb_route_id(ClusterBlockId clb, int pb_route_
7272

7373
static bool block_type_contains_blif_model(t_logical_block_type_ptr type, const std::regex& blif_model_regex);
7474
static bool pb_type_contains_blif_model(const t_pb_type* pb_type, const std::regex& blif_model_regex);
75-
7675
/******************** Subroutine definitions *********************************/
7776

7877
const t_model* find_model(const t_model* models, const std::string& name, bool required) {
@@ -545,15 +544,11 @@ bool is_opin(int ipin, t_physical_tile_type_ptr type) {
545544
}
546545

547546
bool is_input_type(t_physical_tile_type_ptr type) {
548-
auto& device_ctx = g_vpr_ctx.device();
549-
550-
return device_ctx.input_types.count(type);
547+
return type->is_input_type;
551548
}
552549

553550
bool is_output_type(t_physical_tile_type_ptr type) {
554-
auto& device_ctx = g_vpr_ctx.device();
555-
556-
return device_ctx.output_types.count(type);
551+
return type->is_output_type;
557552
}
558553

559554
bool is_io_type(t_physical_tile_type_ptr type) {
@@ -812,45 +807,9 @@ int find_pin(t_physical_tile_type_ptr type, std::string port_name, int pin_index
812807
return ipin;
813808
}
814809

815-
//Returns true if the specified block type contains the specified blif model name
816-
bool block_type_contains_blif_model(t_logical_block_type_ptr type, std::string blif_model_name) {
817-
return pb_type_contains_blif_model(type->pb_type, blif_model_name);
818-
}
819-
820810
static bool block_type_contains_blif_model(t_logical_block_type_ptr type, const std::regex& blif_model_regex) {
821811
return pb_type_contains_blif_model(type->pb_type, blif_model_regex);
822812
}
823-
824-
//Returns true of a pb_type (or it's children) contain the specified blif model name
825-
bool pb_type_contains_blif_model(const t_pb_type* pb_type, const std::string& blif_model_name) {
826-
if (!pb_type) {
827-
return false;
828-
}
829-
830-
if (pb_type->blif_model != nullptr) {
831-
//Leaf pb_type
832-
VTR_ASSERT(pb_type->num_modes == 0);
833-
if (blif_model_name == pb_type->blif_model
834-
|| ".subckt " + blif_model_name == pb_type->blif_model) {
835-
return true;
836-
} else {
837-
return false;
838-
}
839-
} else {
840-
for (int imode = 0; imode < pb_type->num_modes; ++imode) {
841-
const t_mode* mode = &pb_type->modes[imode];
842-
843-
for (int ichild = 0; ichild < mode->num_pb_type_children; ++ichild) {
844-
const t_pb_type* pb_type_child = &mode->pb_type_children[ichild];
845-
if (pb_type_contains_blif_model(pb_type_child, blif_model_name)) {
846-
return true;
847-
}
848-
}
849-
}
850-
}
851-
return false;
852-
}
853-
854813
static bool pb_type_contains_blif_model(const t_pb_type* pb_type, const std::regex& blif_model_regex) {
855814
if (!pb_type) {
856815
return false;

vpr/src/util/vpr_utils.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
#include <vector>
55
#include <string>
6-
#include <regex>
76

87
#include "vpr_types.h"
98
#include "atom_netlist.h"
@@ -113,12 +112,6 @@ int find_pin(t_physical_tile_type_ptr type, std::string port_name, int pin_index
113112
//Returns the block type which is most likely the logic block
114113
t_logical_block_type_ptr infer_logic_block_type(const DeviceGrid& grid);
115114

116-
//Returns true if the specified block type contains the specified blif model name
117-
bool block_type_contains_blif_model(t_logical_block_type_ptr type, std::string blif_model_name);
118-
119-
//Returns true of a pb_type (or it's children) contain the specified blif model name
120-
bool pb_type_contains_blif_model(const t_pb_type* pb_type, const std::string& blif_model_name);
121-
122115
int get_max_primitives_in_pb_type(t_pb_type* pb_type);
123116
int get_max_depth_of_pb_type(t_pb_type* pb_type);
124117
int get_max_nets_in_pb_type(const t_pb_type* pb_type);

0 commit comments

Comments
 (0)