[Tool] Extend bitstream setting to support mode bits overload from eblif file

This commit is contained in:
tangxifan 2021-03-10 20:45:48 -07:00
parent a6186db315
commit 85640a7403
10 changed files with 209 additions and 9 deletions

View File

@ -51,6 +51,17 @@ std::string BitstreamSetting::pb_type_bitstream_content(const BitstreamPbTypeSet
return pb_type_bitstream_contents_[pb_type_setting_id];
}
bool BitstreamSetting::is_mode_select_bitstream(const BitstreamPbTypeSettingId& pb_type_setting_id) const {
VTR_ASSERT(true == valid_bitstream_pb_type_setting_id(pb_type_setting_id));
return is_mode_select_bitstreams_[pb_type_setting_id];
}
size_t BitstreamSetting::bitstream_offset(const BitstreamPbTypeSettingId& pb_type_setting_id) const {
VTR_ASSERT(true == valid_bitstream_pb_type_setting_id(pb_type_setting_id));
return bitstream_offsets_[pb_type_setting_id];
}
/************************************************************************
* Public Mutators
***********************************************************************/
@ -66,10 +77,24 @@ BitstreamPbTypeSettingId BitstreamSetting::add_bitstream_pb_type_setting(const s
parent_mode_names_.push_back(parent_mode_names);
pb_type_bitstream_sources_.push_back(bitstream_source);
pb_type_bitstream_contents_.push_back(bitstream_content);
is_mode_select_bitstreams_.push_back(false);
bitstream_offsets_.push_back(0);
return pb_type_setting_id;
}
void BitstreamSetting::set_mode_select_bitstream(const BitstreamPbTypeSettingId& pb_type_setting_id,
const bool& is_mode_select_bitstream) {
VTR_ASSERT(true == valid_bitstream_pb_type_setting_id(pb_type_setting_id));
is_mode_select_bitstreams_[pb_type_setting_id] = is_mode_select_bitstream;
}
void BitstreamSetting::set_bitstream_offset(const BitstreamPbTypeSettingId& pb_type_setting_id,
const size_t& offset) {
VTR_ASSERT(true == valid_bitstream_pb_type_setting_id(pb_type_setting_id));
bitstream_offsets_[pb_type_setting_id] = offset;
}
/************************************************************************
* Public Validators
***********************************************************************/

View File

@ -39,12 +39,18 @@ class BitstreamSetting {
std::vector<std::string> parent_mode_names(const BitstreamPbTypeSettingId& pb_type_setting_id) const;
std::string pb_type_bitstream_source(const BitstreamPbTypeSettingId& pb_type_setting_id) const;
std::string pb_type_bitstream_content(const BitstreamPbTypeSettingId& pb_type_setting_id) const;
bool is_mode_select_bitstream(const BitstreamPbTypeSettingId& pb_type_setting_id) const;
size_t bitstream_offset(const BitstreamPbTypeSettingId& pb_type_setting_id) const;
public: /* Public Mutators */
BitstreamPbTypeSettingId add_bitstream_pb_type_setting(const std::string& pb_type_name,
const std::vector<std::string>& parent_pb_type_names,
const std::vector<std::string>& parent_mode_names,
const std::string& bitstream_source,
const std::string& bitstream_content);
void set_mode_select_bitstream(const BitstreamPbTypeSettingId& pb_type_setting_id,
const bool& is_mode_select_bitstream);
void set_bitstream_offset(const BitstreamPbTypeSettingId& pb_type_setting_id,
const size_t& offset);
public: /* Public Validators */
bool valid_bitstream_pb_type_setting_id(const BitstreamPbTypeSettingId& pb_type_setting_id) const;
private: /* Internal data */
@ -54,6 +60,10 @@ class BitstreamSetting {
vtr::vector<BitstreamPbTypeSettingId, std::vector<std::string>> parent_mode_names_;
vtr::vector<BitstreamPbTypeSettingId, std::string> pb_type_bitstream_sources_;
vtr::vector<BitstreamPbTypeSettingId, std::string> pb_type_bitstream_contents_;
/* Indicate if the bitstream is applied to mode selection bits of a pb_type */
vtr::vector<BitstreamPbTypeSettingId, bool> is_mode_select_bitstreams_;
/* The offset that the bitstream is applied to the original bitstream of a pb_type */
vtr::vector<BitstreamPbTypeSettingId, size_t> bitstream_offsets_;
};
} /* namespace openfpga ends */

View File

@ -36,11 +36,18 @@ void read_xml_bitstream_pb_type_setting(pugi::xml_node& xml_pb_type,
openfpga::PbParser operating_pb_parser(name_attr);
/* Add to bitstream setting */
bitstream_setting.add_bitstream_pb_type_setting(operating_pb_parser.leaf(),
BitstreamPbTypeSettingId bitstream_pb_type_id = bitstream_setting.add_bitstream_pb_type_setting(operating_pb_parser.leaf(),
operating_pb_parser.parents(),
operating_pb_parser.modes(),
source_attr,
content_attr);
/* Parse if the bitstream overwritting is applied to mode bits of a pb_type */
const bool& is_mode_select_bitstream = get_attribute(xml_pb_type, "is_mode_select_bitstream", loc_data).as_bool(false);
bitstream_setting.set_mode_select_bitstream(bitstream_pb_type_id, is_mode_select_bitstream);
const int& offset = get_attribute(xml_pb_type, "bitstream_offset", loc_data).as_int(0);
bitstream_setting.set_bitstream_offset(bitstream_pb_type_id, offset);
}
/********************************************************************

View File

@ -57,6 +57,8 @@ void write_xml_bitstream_pb_type_setting(std::fstream& fp,
write_xml_attribute(fp, "source", bitstream_setting.pb_type_bitstream_source(bitstream_pb_type_setting_id).c_str());
write_xml_attribute(fp, "content", bitstream_setting.pb_type_bitstream_content(bitstream_pb_type_setting_id).c_str());
write_xml_attribute(fp, "is_mode_select_bitstream", bitstream_setting.is_mode_select_bitstream(bitstream_pb_type_setting_id));
write_xml_attribute(fp, "bitstream_offset", bitstream_setting.bitstream_offset(bitstream_pb_type_setting_id));
fp << "/>" << "\n";
}

View File

@ -38,6 +38,36 @@ std::string VprBitstreamAnnotation::pb_type_bitstream_content(t_pb_type* pb_type
return std::string();
}
bool VprBitstreamAnnotation::pb_type_contain_mode_select_bitstream(t_pb_type* pb_type) const {
auto result = contain_mode_select_bitstreams_.find(pb_type);
if (result != contain_mode_select_bitstreams_.end()) {
return result->second;
}
/* Not found, return false as default */
return false;
}
size_t VprBitstreamAnnotation::pb_type_bitstream_offset(t_pb_type* pb_type) const {
auto result = bitstream_offsets_.find(pb_type);
if (result != bitstream_offsets_.end()) {
return result->second;
}
/* Not found, return an zero offset */
return 0;
}
size_t VprBitstreamAnnotation::pb_type_mode_select_bitstream_offset(t_pb_type* pb_type) const {
auto result = mode_select_bitstream_offsets_.find(pb_type);
if (result != mode_select_bitstream_offsets_.end()) {
return result->second;
}
/* Not found, return an zero offset */
return 0;
}
/************************************************************************
* Public mutators
***********************************************************************/
@ -45,10 +75,25 @@ void VprBitstreamAnnotation::set_pb_type_bitstream_source(t_pb_type* pb_type,
const e_bitstream_source_type& bitstream_source) {
bitstream_sources_[pb_type] = bitstream_source;
}
void VprBitstreamAnnotation::set_pb_type_bitstream_content(t_pb_type* pb_type,
const std::string& bitstream_content) {
bitstream_contents_[pb_type] = bitstream_content;
}
void VprBitstreamAnnotation::set_pb_type_contain_mode_select_bitstream(t_pb_type* pb_type,
const bool& contain_mode_select_bitstream) {
contain_mode_select_bitstreams_[pb_type] = contain_mode_select_bitstream;
}
void VprBitstreamAnnotation::set_pb_type_bitstream_offset(t_pb_type* pb_type,
const size_t& offset) {
bitstream_offsets_[pb_type] = offset;
}
void VprBitstreamAnnotation::set_pb_type_mode_select_bitstream_offset(t_pb_type* pb_type,
const size_t& offset) {
mode_select_bitstream_offsets_[pb_type] = offset;
}
} /* End namespace openfpga*/

View File

@ -33,16 +33,31 @@ class VprBitstreamAnnotation {
public: /* Public accessors */
e_bitstream_source_type pb_type_bitstream_source(t_pb_type* pb_type) const;
std::string pb_type_bitstream_content(t_pb_type* pb_type) const;
bool pb_type_contain_mode_select_bitstream(t_pb_type* pb_type) const;
size_t pb_type_bitstream_offset(t_pb_type* pb_type) const;
size_t pb_type_mode_select_bitstream_offset(t_pb_type* pb_type) const;
public: /* Public mutators */
void set_pb_type_bitstream_source(t_pb_type* pb_type,
const e_bitstream_source_type& bitstream_source);
void set_pb_type_bitstream_content(t_pb_type* pb_type,
const std::string& bitstream_content);
void set_pb_type_contain_mode_select_bitstream(t_pb_type* pb_type,
const bool& contain_mode_select_bitstream);
void set_pb_type_bitstream_offset(t_pb_type* pb_type,
const size_t& offset);
void set_pb_type_mode_select_bitstream_offset(t_pb_type* pb_type,
const size_t& offset);
private: /* Internal data */
/* A look up for pb type to find bitstream source type */
std::map<t_pb_type*, e_bitstream_source_type> bitstream_sources_;
/* Binding from pb type to bitstream content */
std::map<t_pb_type*, std::string> bitstream_contents_;
/* A flag to identify if the pb_type has an external mode-select bitstream */
std::map<t_pb_type*, bool> contain_mode_select_bitstreams_;
/* Offset to be applied to bitstream */
std::map<t_pb_type*, size_t> bitstream_offsets_;
/* Offset to be applied to mode-select bitstream */
std::map<t_pb_type*, size_t> mode_select_bitstream_offsets_;
};
} /* End namespace openfpga*/

View File

@ -448,15 +448,19 @@ void build_lut_bitstream(BitstreamManager& bitstream_manager,
/* If the physical pb contains fixed bitstream, overload here */
if (false == physical_pb.fixed_bitstream(lut_pb_id).empty()) {
std::string fixed_bitstream = physical_pb.fixed_bitstream(lut_pb_id);
size_t start_index = physical_pb.fixed_bitstream_offset(lut_pb_id);
/* Ensure the length matches!!! */
if (lut_bitstream.size() != fixed_bitstream.size()) {
if (lut_bitstream.size() - start_index != fixed_bitstream.size()) {
VTR_LOG_ERROR("Unmatched length of fixed bitstream %s!Expected to be %ld bits\n",
fixed_bitstream.c_str(),
lut_bitstream.size());
exit(1);
}
/* Overload here */
lut_bitstream.clear();
/* Overload here
* - if there is a non-zero offset, we just erase part of the bitstream
* - otherwise, overwrite the whole bitstream
*/
lut_bitstream.erase(lut_bitstream.begin() + start_index, lut_bitstream.end());
for (const char& fixed_bit : fixed_bitstream) {
VTR_ASSERT('0' == fixed_bit || '1' == fixed_bit);
lut_bitstream.push_back('1' == fixed_bit);
@ -472,6 +476,29 @@ void build_lut_bitstream(BitstreamManager& bitstream_manager,
} else { /* get default mode_bits */
mode_select_bitstream = generate_mode_select_bitstream(device_annotation.pb_type_mode_bits(lut_pb_type));
}
/* If the physical pb contains fixed mode-select bitstream, overload here */
if (false == physical_pb.fixed_mode_select_bitstream(lut_pb_id).empty()) {
std::string fixed_mode_select_bitstream = physical_pb.fixed_mode_select_bitstream(lut_pb_id);
size_t mode_bits_start_index = physical_pb.fixed_mode_select_bitstream_offset(lut_pb_id);
/* Ensure the length matches!!! */
if (mode_select_bitstream.size() - mode_bits_start_index != fixed_mode_select_bitstream.size()) {
VTR_LOG_ERROR("Unmatched length of fixed mode_select_bitstream %s!Expected to be %ld bits\n",
fixed_mode_select_bitstream.c_str(),
mode_select_bitstream.size());
exit(1);
}
/* Overload here
* - if there is a non-zero offset, we just erase part of the bitstream
* - otherwise, overwrite the whole bitstream
*/
mode_select_bitstream.erase(mode_select_bitstream.begin() + mode_bits_start_index, mode_select_bitstream.end());
for (const char& fixed_bit : fixed_mode_select_bitstream) {
VTR_ASSERT('0' == fixed_bit || '1' == fixed_bit);
mode_select_bitstream.push_back('1' == fixed_bit);
}
}
/* Conjunct the mode-select bitstream to the lut bitstream */
for (const bool& bit : mode_select_bitstream) {
lut_bitstream.push_back(bit);

View File

@ -107,6 +107,21 @@ std::string PhysicalPb::fixed_bitstream(const PhysicalPbId& pb) const {
return fixed_bitstreams_[pb];
}
size_t PhysicalPb::fixed_bitstream_offset(const PhysicalPbId& pb) const {
VTR_ASSERT(true == valid_pb_id(pb));
return fixed_bitstream_offsets_[pb];
}
std::string PhysicalPb::fixed_mode_select_bitstream(const PhysicalPbId& pb) const {
VTR_ASSERT(true == valid_pb_id(pb));
return fixed_mode_select_bitstreams_[pb];
}
size_t PhysicalPb::fixed_mode_select_bitstream_offset(const PhysicalPbId& pb) const {
VTR_ASSERT(true == valid_pb_id(pb));
return fixed_mode_select_bitstream_offsets_[pb];
}
/******************************************************************************
* Private Mutators
******************************************************************************/
@ -133,7 +148,11 @@ PhysicalPbId PhysicalPb::create_pb(const t_pb_graph_node* pb_graph_node) {
truth_tables_.emplace_back();
mode_bits_.emplace_back();
fixed_bitstreams_.emplace_back();
fixed_bitstream_offsets_.push_back(0);
fixed_mode_select_bitstreams_.emplace_back();
fixed_mode_select_bitstream_offsets_.push_back(0);
/* Register in the name2id map */
type2id_map_[pb_graph_node] = pb;
@ -218,6 +237,24 @@ void PhysicalPb::set_fixed_bitstream(const PhysicalPbId& pb,
fixed_bitstreams_[pb] = fixed_bitstream;
}
void PhysicalPb::set_fixed_bitstream_offset(const PhysicalPbId& pb,
const size_t& offset) {
VTR_ASSERT(true == valid_pb_id(pb));
fixed_bitstream_offsets_[pb] = offset;
}
void PhysicalPb::set_fixed_mode_select_bitstream(const PhysicalPbId& pb,
const std::string& fixed_bitstream) {
VTR_ASSERT(true == valid_pb_id(pb));
fixed_mode_select_bitstreams_[pb] = fixed_bitstream;
}
void PhysicalPb::set_fixed_mode_select_bitstream_offset(const PhysicalPbId& pb,
const size_t& offset) {
VTR_ASSERT(true == valid_pb_id(pb));
fixed_mode_select_bitstream_offsets_[pb] = offset;
}
/******************************************************************************
* Private validators/invalidators
******************************************************************************/

View File

@ -55,6 +55,9 @@ class PhysicalPb {
std::map<const t_pb_graph_pin*, AtomNetlist::TruthTable> truth_tables(const PhysicalPbId& pb) const;
std::vector<size_t> mode_bits(const PhysicalPbId& pb) const;
std::string fixed_bitstream(const PhysicalPbId& pb) const;
size_t fixed_bitstream_offset(const PhysicalPbId& pb) const;
std::string fixed_mode_select_bitstream(const PhysicalPbId& pb) const;
size_t fixed_mode_select_bitstream_offset(const PhysicalPbId& pb) const;
public: /* Public mutators */
PhysicalPbId create_pb(const t_pb_graph_node* pb_graph_node);
void add_child(const PhysicalPbId& parent,
@ -75,6 +78,12 @@ class PhysicalPb {
const bool& wire_lut_output);
void set_fixed_bitstream(const PhysicalPbId& pb,
const std::string& fixed_bitstream);
void set_fixed_bitstream_offset(const PhysicalPbId& pb,
const size_t& offset);
void set_fixed_mode_select_bitstream(const PhysicalPbId& pb,
const std::string& fixed_bitstream);
void set_fixed_mode_select_bitstream_offset(const PhysicalPbId& pb,
const size_t& offset);
public: /* Public validators/invalidators */
bool valid_pb_id(const PhysicalPbId& pb_id) const;
bool empty() const;
@ -98,6 +107,10 @@ class PhysicalPb {
vtr::vector<PhysicalPbId, std::vector<size_t>> mode_bits_;
vtr::vector<PhysicalPbId, std::string> fixed_bitstreams_;
vtr::vector<PhysicalPbId, size_t> fixed_bitstream_offsets_;
vtr::vector<PhysicalPbId, std::string> fixed_mode_select_bitstreams_;
vtr::vector<PhysicalPbId, size_t> fixed_mode_select_bitstream_offsets_;
/* Fast lookup */
std::map<const t_pb_graph_node*, PhysicalPbId> type2id_map_;

View File

@ -313,16 +313,35 @@ void rec_update_physical_pb_from_operating_pb(PhysicalPb& phy_pb,
std::vector<std::string> tokens = tokenizer.split(" ");
/* FIXME: The token-level check should be done much earlier!!! */
VTR_ASSERT(2 == tokens.size());
/* The token is typically organized as <.param|.attr> <identifier string> */
if (std::string(".param") == tokens[0]) {
for (const auto& param_search : atom_ctx.nlist.block_params(atom_blk)) {
if (param_search.first == tokens[1]) {
/* Bypass unmatched parameter identifier */
if (param_search.first != tokens[1]) {
continue;
}
if (false == bitstream_annotation.pb_type_contain_mode_select_bitstream(pb_type)) {
phy_pb.set_fixed_bitstream(physical_pb, param_search.second);
phy_pb.set_fixed_bitstream_offset(physical_pb, bitstream_annotation.pb_type_bitstream_offset(pb_type));
} else {
VTR_ASSERT_SAFE(true == bitstream_annotation.pb_type_contain_mode_select_bitstream(pb_type));
phy_pb.set_fixed_mode_select_bitstream(physical_pb, param_search.second);
phy_pb.set_fixed_mode_select_bitstream_offset(physical_pb, bitstream_annotation.pb_type_mode_select_bitstream_offset(pb_type));
}
}
} else if (std::string(".attr") == tokens[0]) {
for (const auto& attr_search : atom_ctx.nlist.block_attrs(atom_blk)) {
/* Bypass unmatched parameter identifier */
if (attr_search.first == tokens[1]) {
continue;
}
if (false == bitstream_annotation.pb_type_contain_mode_select_bitstream(pb_type)) {
phy_pb.set_fixed_bitstream(physical_pb, attr_search.second);
phy_pb.set_fixed_bitstream_offset(physical_pb, bitstream_annotation.pb_type_bitstream_offset(pb_type));
} else {
VTR_ASSERT_SAFE(true == bitstream_annotation.pb_type_contain_mode_select_bitstream(pb_type));
phy_pb.set_fixed_mode_select_bitstream(physical_pb, attr_search.second);
phy_pb.set_fixed_mode_select_bitstream_offset(physical_pb, bitstream_annotation.pb_type_mode_select_bitstream_offset(pb_type));
}
}
}