Try with vector
This commit is contained in:
parent
41e05c95aa
commit
e419b34027
@ -70,6 +70,20 @@ class SAPlacer
|
|||||||
fast_bels.at(type_idx).at(loc.x).at(loc.y).push_back(bel);
|
fast_bels.at(type_idx).at(loc.x).at(loc.y).push_back(bel);
|
||||||
}
|
}
|
||||||
diameter = std::max(max_x, max_y) + 1;
|
diameter = std::max(max_x, max_y) + 1;
|
||||||
|
|
||||||
|
curr_cost.reserve(ctx->nets.size());
|
||||||
|
new_cost.reserve(ctx->nets.size());
|
||||||
|
old_udata.reserve(ctx->nets.size());
|
||||||
|
decltype(NetInfo::udata) n = 0;
|
||||||
|
for (auto &net : ctx->nets) {
|
||||||
|
old_udata.emplace_back(net.second->udata);
|
||||||
|
net.second->udata = n++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
~SAPlacer() {
|
||||||
|
for (auto &net : ctx->nets)
|
||||||
|
net.second->udata = old_udata[net.second->udata];
|
||||||
}
|
}
|
||||||
|
|
||||||
bool place()
|
bool place()
|
||||||
@ -149,7 +163,8 @@ class SAPlacer
|
|||||||
curr_tns = 0;
|
curr_tns = 0;
|
||||||
for (auto &net : ctx->nets) {
|
for (auto &net : ctx->nets) {
|
||||||
wirelen_t wl = get_net_metric(ctx, net.second.get(), MetricType::COST, curr_tns);
|
wirelen_t wl = get_net_metric(ctx, net.second.get(), MetricType::COST, curr_tns);
|
||||||
metrics[net.first] = wl;
|
curr_cost[net.second->udata] = wl;
|
||||||
|
new_cost[net.second->udata] = -1;
|
||||||
curr_metric += wl;
|
curr_metric += wl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,7 +265,8 @@ class SAPlacer
|
|||||||
curr_tns = 0;
|
curr_tns = 0;
|
||||||
for (auto &net : ctx->nets) {
|
for (auto &net : ctx->nets) {
|
||||||
wirelen_t wl = get_net_metric(ctx, net.second.get(), MetricType::COST, curr_tns);
|
wirelen_t wl = get_net_metric(ctx, net.second.get(), MetricType::COST, curr_tns);
|
||||||
metrics[net.first] = wl;
|
curr_cost[net.second->udata] = wl;
|
||||||
|
new_cost[net.second->udata] = -1;
|
||||||
curr_metric += wl;
|
curr_metric += wl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -339,10 +355,8 @@ class SAPlacer
|
|||||||
// Attempt a SA position swap, return true on success or false on failure
|
// Attempt a SA position swap, return true on success or false on failure
|
||||||
bool try_swap_position(CellInfo *cell, BelId newBel)
|
bool try_swap_position(CellInfo *cell, BelId newBel)
|
||||||
{
|
{
|
||||||
static std::unordered_set<NetInfo *> update;
|
static std::vector<NetInfo*> updates;
|
||||||
static std::vector<std::pair<IdString, wirelen_t>> new_lengths;
|
updates.clear();
|
||||||
new_lengths.clear();
|
|
||||||
update.clear();
|
|
||||||
BelId oldBel = cell->bel;
|
BelId oldBel = cell->bel;
|
||||||
CellInfo *other_cell = ctx->getBoundBelCell(newBel);
|
CellInfo *other_cell = ctx->getBoundBelCell(newBel);
|
||||||
if (other_cell != nullptr && other_cell->belStrength > STRENGTH_WEAK) {
|
if (other_cell != nullptr && other_cell->belStrength > STRENGTH_WEAK) {
|
||||||
@ -358,14 +372,23 @@ class SAPlacer
|
|||||||
ctx->unbindBel(newBel);
|
ctx->unbindBel(newBel);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto &port : cell->ports)
|
for (const auto &port : cell->ports) {
|
||||||
if (port.second.net != nullptr)
|
if (port.second.net != nullptr) {
|
||||||
update.insert(port.second.net);
|
auto &cost = new_cost[port.second.net->udata];
|
||||||
|
if (cost == 0) continue;
|
||||||
|
cost = 0;
|
||||||
|
updates.emplace_back(port.second.net);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (other_cell != nullptr) {
|
if (other_cell != nullptr) {
|
||||||
for (const auto &port : other_cell->ports)
|
for (const auto &port : other_cell->ports)
|
||||||
if (port.second.net != nullptr)
|
if (port.second.net != nullptr) {
|
||||||
update.insert(port.second.net);
|
auto &cost = new_cost[port.second.net->udata];
|
||||||
|
if (cost == 0) continue;
|
||||||
|
cost = 0;
|
||||||
|
updates.emplace_back(port.second.net);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx->bindBel(newBel, cell, STRENGTH_WEAK);
|
ctx->bindBel(newBel, cell, STRENGTH_WEAK);
|
||||||
@ -383,12 +406,12 @@ class SAPlacer
|
|||||||
new_metric = curr_metric;
|
new_metric = curr_metric;
|
||||||
|
|
||||||
// Recalculate metrics for all nets touched by the peturbation
|
// Recalculate metrics for all nets touched by the peturbation
|
||||||
for (auto net : update) {
|
for (const auto &net : updates) {
|
||||||
new_metric -= metrics.at(net->name);
|
new_metric -= curr_cost[net->udata];
|
||||||
float temp_tns = 0;
|
float temp_tns = 0;
|
||||||
wirelen_t net_new_wl = get_net_metric(ctx, net, MetricType::COST, temp_tns);
|
wirelen_t net_new_wl = get_net_metric(ctx, net, MetricType::COST, temp_tns);
|
||||||
new_metric += net_new_wl;
|
new_metric += net_new_wl;
|
||||||
new_lengths.push_back(std::make_pair(net->name, net_new_wl));
|
new_cost[net->udata] = net_new_wl;
|
||||||
}
|
}
|
||||||
|
|
||||||
new_dist = get_constraints_distance(ctx, cell);
|
new_dist = get_constraints_distance(ctx, cell);
|
||||||
@ -407,8 +430,10 @@ class SAPlacer
|
|||||||
goto swap_fail;
|
goto swap_fail;
|
||||||
}
|
}
|
||||||
curr_metric = new_metric;
|
curr_metric = new_metric;
|
||||||
for (auto new_wl : new_lengths)
|
for (const auto &net : updates) {
|
||||||
metrics.at(new_wl.first) = new_wl.second;
|
curr_cost[net->udata] = new_cost[net->udata];
|
||||||
|
new_cost[net->udata] = -1;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
swap_fail:
|
swap_fail:
|
||||||
@ -416,6 +441,8 @@ class SAPlacer
|
|||||||
if (other_cell != nullptr) {
|
if (other_cell != nullptr) {
|
||||||
ctx->bindBel(newBel, other_cell, STRENGTH_WEAK);
|
ctx->bindBel(newBel, other_cell, STRENGTH_WEAK);
|
||||||
}
|
}
|
||||||
|
for (const auto &net : updates)
|
||||||
|
new_cost[net->udata] = -1;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -444,7 +471,6 @@ class SAPlacer
|
|||||||
}
|
}
|
||||||
|
|
||||||
Context *ctx;
|
Context *ctx;
|
||||||
std::unordered_map<IdString, wirelen_t> metrics;
|
|
||||||
wirelen_t curr_metric = std::numeric_limits<wirelen_t>::max();
|
wirelen_t curr_metric = std::numeric_limits<wirelen_t>::max();
|
||||||
float curr_tns = 0;
|
float curr_tns = 0;
|
||||||
float temp = 1000;
|
float temp = 1000;
|
||||||
@ -459,6 +485,10 @@ class SAPlacer
|
|||||||
const float post_legalise_temp = 10;
|
const float post_legalise_temp = 10;
|
||||||
const float post_legalise_dia_scale = 1.5;
|
const float post_legalise_dia_scale = 1.5;
|
||||||
Placer1Cfg cfg;
|
Placer1Cfg cfg;
|
||||||
|
|
||||||
|
std::vector<wirelen_t> curr_cost;
|
||||||
|
std::vector<wirelen_t> new_cost;
|
||||||
|
std::vector<decltype(NetInfo::udata)> old_udata;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool placer1(Context *ctx, Placer1Cfg cfg)
|
bool placer1(Context *ctx, Placer1Cfg cfg)
|
||||||
|
Loading…
Reference in New Issue
Block a user