Skip to content

Commit

Permalink
Expose net weights in the circuit and take them into account in the m…
Browse files Browse the repository at this point in the history
…odel
  • Loading branch information
Coloquinte committed Sep 29, 2023
1 parent 3f9de0f commit 0e6b6d0
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 20 deletions.
4 changes: 3 additions & 1 deletion pycoloquinte/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,9 @@ Construct a circuit.
"Standard-cell row height")
.def_property("rows", &Circuit::rows, &Circuit::setRows,
"Standard cell rows")
.def("add_net", &Circuit::addNet, "Add a net to the circuit")
.def("add_net", &Circuit::addNet, py::arg("cells"), py::arg("x_offsets"),
py::arg("y_offsets"), py::arg("weight") = 1.0,
"Add a net to the circuit")
.def("hpwl", &Circuit::hpwl, "Compute the half-perimeter wirelength")
.def("setup_rows", &Circuit::setupRows,
"Setup the rows from a placement area")
Expand Down
27 changes: 22 additions & 5 deletions src/coloquinte.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Circuit::Circuit(int nbCells) {

void Circuit::addNet(const std::vector<int> &cells,
const std::vector<int> &xOffsets,
const std::vector<int> &yOffsets) {
const std::vector<int> &yOffsets, float weight) {
if (cells.size() != xOffsets.size() || cells.size() != yOffsets.size()) {
throw std::runtime_error("Inconsistent number of pins for the net");
}
Expand All @@ -44,6 +44,7 @@ void Circuit::addNet(const std::vector<int> &cells,
return;
}
netLimits_.push_back(netLimits_.back() + cells.size());
netWeights_.push_back(weight);
pinCells_.insert(pinCells_.end(), cells.begin(), cells.end());
pinXOffsets_.insert(pinXOffsets_.end(), xOffsets.begin(), xOffsets.end());
pinYOffsets_.insert(pinYOffsets_.end(), yOffsets.begin(), yOffsets.end());
Expand All @@ -52,17 +53,30 @@ void Circuit::addNet(const std::vector<int> &cells,
void Circuit::setNets(const std::vector<int> &limits,
const std::vector<int> &cells,
const std::vector<int> &xOffsets,
const std::vector<int> &yOffsets) {
const std::vector<int> &yOffsets,
const std::vector<float> &weights) {
checkNotInUse();
assert(!limits.empty());
assert(limits.front() == 0);
assert(limits.back() == cells.size());
assert(limits.back() == xOffsets.size());
assert(limits.back() == yOffsets.size());
assert(limits.size() == weights.size() + 1 || weights.empty());
netLimits_ = limits;
pinCells_ = cells;
pinXOffsets_ = xOffsets;
pinYOffsets_ = yOffsets;
netWeights_ = weights;
netWeights_.resize(netLimits_.size() - 1, 1.0f);
}

void Circuit::setNetWeights(const std::vector<float> &w) {
if (w.size() != nbNets()) {
throw std::runtime_error(
"Number of weights is not the same as the number of nets of the "
"circuit");
}
netWeights_ = w;
}

void Circuit::setCellX(const std::vector<int> &x) {
Expand Down Expand Up @@ -346,6 +360,9 @@ void Circuit::check() const {
if (netLimits_.front() != 0) {
throw std::runtime_error("Size mismatch");
}
if (netWeights_.size() != nbNets()) {
throw std::runtime_error("Size mismatch");
}
if (pinCells_.size() != nbPins()) {
throw std::runtime_error("Size mismatch");
}
Expand Down Expand Up @@ -591,7 +608,7 @@ void Circuit::placeDetailed(const ColoquinteParameters &params,
clearInUse();
}

long long Circuit::computePlacementArea(double rowSideMargin) const {
long long Circuit::computeRowPlacementArea(double rowSideMargin) const {
// Compute row area
long long rowArea = 0LL;
for (Row r : computeRows()) {
Expand All @@ -616,7 +633,7 @@ void Circuit::expandCellsToDensity(double targetDensity, double rowSideMargin) {
}
}

long long rowArea = computePlacementArea(rowSideMargin);
long long rowArea = computeRowPlacementArea(rowSideMargin);

// Compute the density and return if no further work is needed
if (cellArea == 0LL || rowArea == 0LL) {
Expand Down Expand Up @@ -675,7 +692,7 @@ void Circuit::expandCellsByFactor(const std::vector<float> &expansionFactor,
}
}

long long rowArea = computePlacementArea(rowSideMargin);
long long rowArea = computeRowPlacementArea(rowSideMargin);

// Compute the density and return if no further work is needed
if (cellArea == 0LL || rowArea == 0LL) {
Expand Down
38 changes: 26 additions & 12 deletions src/coloquinte.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -787,14 +787,20 @@ class Circuit {
* @brief Add a single net
*/
void addNet(const std::vector<int> &cells, const std::vector<int> &xOffsets,
const std::vector<int> &yOffsets);
const std::vector<int> &yOffsets, float weight = 1.0f);

/**
* @brief Set all nets
*/
void setNets(const std::vector<int> &limits, const std::vector<int> &cells,
const std::vector<int> &xOffsets,
const std::vector<int> &yOffsets);
const std::vector<int> &yOffsets,
const std::vector<float> &weights = std::vector<float>());

/**
* @brief Set the net weights
*/
void setNetWeights(const std::vector<float> &weights);

/**
* @brief Return a bounding box of the placement area
Expand Down Expand Up @@ -905,13 +911,20 @@ class Circuit {

/**
* @brief Return the number of pins for a given net
*
*/
int nbPinsNet(int net) const {
assert(net < nbNets());
return netLimits_[net + 1] - netLimits_[net];
}

/**
* @brief Return the weight associated with a net
*/
float netWeight(int net) const {
assert(net < nbNets());
return netWeights_[net];
}

/**
* @brief Return the cell associated with a given pin
*/
Expand Down Expand Up @@ -978,14 +991,6 @@ class Circuit {
void placeDetailed(const ColoquinteParameters &params,
const std::optional<PlacementCallback> &callback = {});

/**
* @brief Compute the area available for placement
*
* @param rowSideMargin Margin applied to each row before computing available
* area, in standard cell heights
*/
long long computePlacementArea(double rowSideMargin = 0.0) const;

/**
* @brief Apply cell size modifications to ensure that the circuit is spread
* uniformly, or as if it was a target density
Expand Down Expand Up @@ -1084,12 +1089,21 @@ class Circuit {
LegalizationModel costModel);

/**
* Check that the circuit is not being worked on right now
* @brief Check that the circuit is not being worked on right now
*/
void checkNotInUse() const;

/**
* @brief Compute the area available for placement
*
* @param rowSideMargin Margin applied to each row before computing available
* area, in standard cell heights
*/
long long computeRowPlacementArea(double rowSideMargin = 0.0) const;

public:
std::vector<int> netLimits_;
std::vector<float> netWeights_;
std::vector<int> pinCells_;
std::vector<int> pinXOffsets_;
std::vector<int> pinYOffsets_;
Expand Down
4 changes: 2 additions & 2 deletions src/place_global/net_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ NetModel NetModel::xTopology(const Circuit &circuit) {
offsets.push_back(offset - 0.5f * circuit.placedWidth(cell));
}
}
ret.addNet(cells, offsets, minPos, maxPos);
ret.addNet(cells, offsets, minPos, maxPos, circuit.netWeight(i));
}
ret.check();
return ret;
Expand All @@ -60,7 +60,7 @@ NetModel NetModel::yTopology(const Circuit &circuit) {
offsets.push_back(offset - 0.5f * circuit.placedHeight(cell));
}
}
ret.addNet(cells, offsets, minPos, maxPos);
ret.addNet(cells, offsets, minPos, maxPos, circuit.netWeight(i));
}
ret.check();
return ret;
Expand Down

0 comments on commit 0e6b6d0

Please sign in to comment.