-
Notifications
You must be signed in to change notification settings - Fork 162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add command to generate repack design constraints #1889
Draft
fkosar-ql
wants to merge
1
commit into
lnis-uofu:master
Choose a base branch
from
fkosar-ql:gen-repack-constraints
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
openfpga/src/base/openfpga_gen_repack_constraints_template.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
#pragma once | ||
|
||
#include "command.h" | ||
#include "command_context.h" | ||
#include "command_exit_codes.h" | ||
#include "openfpga_port.h" | ||
#include "openfpga_port_parser.h" | ||
#include "pcf_reader.h" | ||
#include "repack_design_constraints.h" | ||
#include "vtr_log.h" | ||
#include "write_xml_repack_design_constraints.h" | ||
#include "globals.h" | ||
|
||
/* begin namespace openfpga */ | ||
namespace openfpga { | ||
|
||
static inline RepackDesignConstraints gen_repack_constraints(openfpga::PcfData* pcf_data){ | ||
auto& cluster_ctx = g_vpr_ctx.clustering(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid to use any more global variables. Pass them through arguments (const reference). We have seen enough troubles by using global variables. Any new codes should be clean at the beginning. |
||
auto& atom_ctx = g_vpr_ctx.atom(); | ||
auto& clb_nlist = cluster_ctx.clb_nlist; | ||
|
||
/* 1. Get unique pb_types, clock pins and clock nets from clb_nlist.blocks */ | ||
std::set<std::string> pb_type_names; | ||
std::set<BasicPort> clock_pins; | ||
std::set<std::string> clock_nets; | ||
|
||
for (auto block_id : clb_nlist.blocks()) { | ||
auto pb = clb_nlist.block_pb(block_id); | ||
auto pb_type = pb->pb_graph_node->pb_type; | ||
pb_type_names.insert(pb_type->name); | ||
|
||
int port_index = 0; | ||
for (int i = 0; i < pb_type->num_ports; i++) { | ||
auto& port = pb_type->ports[i]; | ||
if(!port.is_clock) | ||
continue; | ||
for (int j = 0; j < port.num_pins; j++) { | ||
auto& pin = pb->pb_graph_node->clock_pins[port_index][j]; | ||
std::string pin_name = std::string(port.name) + "[" + std::to_string(j) + "]"; | ||
openfpga::PortParser port_parser(pin_name); | ||
clock_pins.insert(port_parser.port()); | ||
int node_index = pin.pin_count_in_cluster; | ||
if(pb->pb_route.count(node_index)){ | ||
AtomNetId net_id = pb->pb_route[node_index].atom_net_id; | ||
std::string net_name = atom_ctx.nlist.net_name(net_id); | ||
clock_nets.insert(net_name); | ||
} | ||
} | ||
port_index++; | ||
} | ||
} | ||
|
||
std::vector<std::pair<std::string, BasicPort>> matches; | ||
|
||
/* First match nets & pins from the pcf file */ | ||
if(pcf_data){ | ||
for (const PcfIoConstraintId& io_id : pcf_data->io_constraints()) { | ||
std::string net = pcf_data->io_net(io_id); | ||
BasicPort pin = pcf_data->io_pin(io_id); | ||
if(!(clock_nets.count(net) && clock_pins.count(pin))) | ||
continue; | ||
matches.push_back({net, pin}); | ||
clock_nets.erase(net); | ||
clock_pins.erase(pin); | ||
} | ||
} | ||
|
||
/* Match the rest in an arbitrary way */ | ||
for(auto net: clock_nets){ | ||
VTR_ASSERT_MSG(!clock_pins.empty(), "Not enough clock pins for clocks in the design"); | ||
auto first_available_pin = *clock_pins.begin(); | ||
matches.push_back({net, first_available_pin}); | ||
clock_pins.erase(first_available_pin); | ||
} | ||
|
||
/* 3. Create the design constraints */ | ||
RepackDesignConstraints out; | ||
for(auto pb_type: pb_type_names){ | ||
for(auto [net, pin]: matches){ | ||
auto id = out.create_design_constraint(RepackDesignConstraints::PIN_ASSIGNMENT); | ||
out.set_pb_type(id, pb_type); | ||
out.set_net(id, net); | ||
out.set_pin(id, pin); | ||
} | ||
} | ||
|
||
return out; | ||
} | ||
|
||
/******************************************************************** | ||
* Top-level function to generate a repack_design_constraints.xml file | ||
* from either a .pcf file or vpr context | ||
*******************************************************************/ | ||
template <class T> | ||
int gen_repack_constraints_template(const Command& cmd, | ||
const CommandContext& cmd_context) { | ||
CommandOptionId opt_pcf = cmd.option("pcf"); | ||
CommandOptionId opt_file = cmd.option("file"); | ||
|
||
std::string out_fname = cmd_context.option_value(cmd, opt_file); | ||
|
||
RepackDesignConstraints constraints; | ||
|
||
if (cmd_context.option_enable(cmd, opt_pcf)) { | ||
std::string pcf_fname = cmd_context.option_value(cmd, opt_pcf); | ||
|
||
openfpga::PcfData pcf_data; | ||
openfpga::read_pcf(pcf_fname.c_str(), pcf_data); | ||
VTR_LOG("[gen_repack_constraints] Read the design constraints from a pcf file: %s.\n", | ||
pcf_fname.c_str()); | ||
|
||
if (!pcf_data.validate()) { | ||
VTR_LOG_ERROR("[gen_repack_constraints] PCF contains invalid I/O assignment!\n"); | ||
return CMD_EXEC_FATAL_ERROR; | ||
} else { | ||
VTR_LOG("[gen_repack_constraints] PCF basic check passed\n"); | ||
} | ||
constraints = gen_repack_constraints(&pcf_data); | ||
} else { | ||
constraints = gen_repack_constraints(NULL); | ||
} | ||
|
||
write_xml_repack_design_constraints(out_fname.c_str(), constraints); | ||
return CMD_EXEC_SUCCESS; | ||
} | ||
|
||
} /* end namespace openfpga */ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use constant reference for PcfData
(const openfpga::PcfData& pcf_data)
as it is read-only in this function.