Skip to content
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

drt: Bidirectional A* #6486

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions etc/DependencyInstaller.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ _installCommonDev() {
pcreChecksum="37d2f77cfd411a3ddf1c64e1d72e43f7"
swigVersion=4.1.0
swigChecksum="794433378154eb61270a3ac127d9c5f3"
boostVersionBig=1.80
boostVersionBig=1.82
boostVersionSmall=${boostVersionBig}.0
boostChecksum="077f074743ea7b0cb49c6ed43953ae95"
boostChecksum="f7050f554a65f6a42ece221eaeec1660"
eigenVersion=3.4
cuddVersion=3.0.0
lemonVersion=1.3.1
Expand Down
2 changes: 1 addition & 1 deletion src/drt/src/dr/FlexGridGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void FlexGridGraph::initGrids(const frLayerCoordTrackPatternMap& xMap,
srcs_.clear();
dsts_.clear();

prevDirs_.resize(capacity * 3, false);
prevDirs_.resize(capacity * 4, false);
srcs_.resize(capacity, false);
dsts_.resize(capacity, false);
guides_.clear();
Expand Down
113 changes: 101 additions & 12 deletions src/drt/src/dr/FlexGridGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include <boost/container/flat_map.hpp>
#include <boost/container/flat_set.hpp>
#include <boost/unordered/unordered_flat_map.hpp>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: 'boost/unordered/unordered_flat_map.hpp' file not found [clang-diagnostic-error]

#include <boost/unordered/unordered_flat_map.hpp>
         ^

#include <cstdint>
#include <cstring>
#include <fstream>
Expand All @@ -45,6 +46,11 @@
#include "global.h"

namespace drt {
enum class ExpandDir
{
FORWARD,
BACKWARD,
};

using frLayerCoordTrackPatternMap = boost::container::
flat_map<frLayerNum, boost::container::flat_map<frCoord, frTrackPattern*>>;
Expand Down Expand Up @@ -112,6 +118,26 @@ class FlexGridGraph
return nodes_[getIdx(x, y, z)].hasGridCostUp;
}

void setPathCost(frMIdx x, frMIdx y, frMIdx z, frCost in)
{
path_costs_[getIdx(x, y, z)] = in;
}
void setPathCost(const FlexMazeIdx& mIdx, frCost in)
{
path_costs_[getIdx(mIdx.x(), mIdx.y(), mIdx.z())] = in;
}
frCost getPathCost(frMIdx x, frMIdx y, frMIdx z)
{
return path_costs_[getIdx(x, y, z)];
}
bool isClosed(frMIdx x, frMIdx y, frMIdx z, ExpandDir expandDir) const
{
auto baseIdx = 4 * getIdx(x, y, z);
return getPrevAstarNodeDir({x, y, z}) != frDirEnum::UNKNOWN
&& (prevDirs_[baseIdx + 3] ? expandDir == ExpandDir::FORWARD
: expandDir == ExpandDir::BACKWARD);
}

void getBBox(Rect& in) const
{
if (!xCoords_.empty() && !yCoords_.empty()) {
Expand Down Expand Up @@ -946,6 +972,11 @@ class FlexGridGraph
void resetPrevNodeDir();
void resetSrc();
void resetDst();
void traceBackPath(std::vector<FlexMazeIdx>& connComps,
std::vector<FlexMazeIdx>& path,
FlexMazeIdx& ccMazeIdx1,
FlexMazeIdx& ccMazeIdx2,
ExpandDir expandDir);
bool search(std::vector<FlexMazeIdx>& connComps,
drPin* nextPin,
std::vector<FlexMazeIdx>& path,
Expand Down Expand Up @@ -989,8 +1020,10 @@ class FlexGridGraph
yCoords_.shrink_to_fit();
yCoords_.clear();
yCoords_.shrink_to_fit();
wavefront_.cleanup();
wavefront_.fit();
wavefrontForward_.cleanup();
wavefrontForward_.fit();
wavefrontBackward_.cleanup();
wavefrontBackward_.fit();
}

void printNode(frMIdx x, frMIdx y, frMIdx z)
Expand Down Expand Up @@ -1095,6 +1128,7 @@ class FlexGridGraph
std::vector<bool> srcs_;
std::vector<bool> dsts_;
std::vector<bool> guides_;
boost::unordered_flat_map<frMIdx, frCost> path_costs_;
frVector<frCoord> xCoords_;
frVector<frCoord> yCoords_;
frVector<frLayerNum> zCoords_;
Expand All @@ -1105,7 +1139,15 @@ class FlexGridGraph
frUInt4 ggMarkerCost_ = 0;
frUInt4 ggFixedShapeCost_ = 0;
// temporary variables
FlexWavefront wavefront_;
FlexWavefront wavefrontForward_;
FlexWavefront wavefrontBackward_;
struct MeetingPoint
{
FlexWavefrontGrid wavefront;
ExpandDir wavefrontDir;
frCost mazeCost;
};
std::optional<MeetingPoint> meetingPoint_;
const std::vector<std::pair<frCoord, frCoord>>* halfViaEncArea_
= nullptr; // std::pair<layer1area, layer2area>
// ndr related
Expand All @@ -1122,32 +1164,39 @@ class FlexGridGraph
void printExpansion(const FlexWavefrontGrid& currGrid,
const std::string& keyword);
// unsafe access, no idx check
void setPrevAstarNodeDir(frMIdx x, frMIdx y, frMIdx z, frDirEnum dir)
void setPrevAstarNodeDir(frMIdx x,
frMIdx y,
frMIdx z,
ExpandDir expandDir,
frDirEnum dir)
{
auto baseIdx = 3 * getIdx(x, y, z);
auto baseIdx = 4 * getIdx(x, y, z);
prevDirs_[baseIdx] = ((uint16_t) dir >> 2) & 1;
prevDirs_[baseIdx + 1] = ((uint16_t) dir >> 1) & 1;
prevDirs_[baseIdx + 2] = ((uint16_t) dir) & 1;
prevDirs_[baseIdx + 3] = expandDir == ExpandDir::FORWARD;
}

// unsafe access, no check
frDirEnum getPrevAstarNodeDir(const FlexMazeIdx& idx) const
{
auto baseIdx = 3 * getIdx(idx.x(), idx.y(), idx.z());
auto baseIdx = 4 * getIdx(idx.x(), idx.y(), idx.z());
return (frDirEnum) (((uint16_t) (prevDirs_[baseIdx]) << 2)
+ ((uint16_t) (prevDirs_[baseIdx + 1]) << 1)
+ ((uint16_t) (prevDirs_[baseIdx + 2]) << 0));
}

// unsafe access, no check
bool isSrc(frMIdx x, frMIdx y, frMIdx z) const
bool isSrc(frMIdx x, frMIdx y, frMIdx z, ExpandDir expandDir) const
{
return srcs_[getIdx(x, y, z)];
auto& srcs = expandDir == ExpandDir::FORWARD ? srcs_ : dsts_;
return srcs[getIdx(x, y, z)];
}
// unsafe access, no check
bool isDst(frMIdx x, frMIdx y, frMIdx z) const
bool isDst(frMIdx x, frMIdx y, frMIdx z, ExpandDir expandDir) const
{
return dsts_[getIdx(x, y, z)];
auto& dsts = expandDir == ExpandDir::FORWARD ? dsts_ : srcs_;
return dsts[getIdx(x, y, z)];
}
bool isDst(frMIdx x, frMIdx y, frMIdx z, frDirEnum dir) const
{
Expand Down Expand Up @@ -1307,20 +1356,31 @@ class FlexGridGraph
std::vector<FlexMazeIdx>& path,
std::vector<FlexMazeIdx>& root,
FlexMazeIdx& ccMazeIdx1,
FlexMazeIdx& ccMazeIdx2) const;
FlexMazeIdx& ccMazeIdx2,
ExpandDir expandDir) const;
void traceBackPath(const FlexMazeIdx& currGrid,
std::vector<FlexMazeIdx>& path,
std::vector<FlexMazeIdx>& root,
FlexMazeIdx& ccMazeIdx1,
FlexMazeIdx& ccMazeIdx2,
ExpandDir expandDir) const;
void expandWavefront(FlexWavefrontGrid& currGrid,
const FlexMazeIdx& dstMazeIdx1,
const FlexMazeIdx& dstMazeIdx2,
const Point& centerPt,
ExpandDir expandDir,
bool route_with_jumpers);
bool isExpandable(const FlexWavefrontGrid& currGrid, frDirEnum dir) const;
bool isExpandable(const FlexWavefrontGrid& currGrid,
frDirEnum dir,
ExpandDir expandDir) const;
FlexMazeIdx getTailIdx(const FlexMazeIdx& currIdx,
const FlexWavefrontGrid& currGrid) const;
void expand(FlexWavefrontGrid& currGrid,
const frDirEnum& dir,
const FlexMazeIdx& dstMazeIdx1,
const FlexMazeIdx& dstMazeIdx2,
const Point& centerPt,
ExpandDir expandDir,
bool route_with_jumpers);
bool hasAlignedUpDefTrack(
frLayerNum layerNum,
Expand All @@ -1332,6 +1392,35 @@ class FlexGridGraph
bool hasOutOfDieViol(frMIdx x, frMIdx y, frMIdx z);
bool isWorkerBorder(frMIdx v, bool isVert);

template <class Archive>
void serialize(Archive& ar, const unsigned int version)
{
// The wavefront should always be empty here so we don't need to
// serialize it.
if (!wavefrontForward_.empty() || !wavefrontBackward_.empty()) {
throw std::logic_error("don't serialize non-empty wavefront");
}
if (is_loading(ar)) {
tech_ = ar.getDesign()->getTech();
}
(ar) & drWorker_;
(ar) & nodes_;
(ar) & prevDirs_;
(ar) & srcs_;
(ar) & dsts_;
(ar) & guides_;
(ar) & xCoords_;
(ar) & yCoords_;
(ar) & zCoords_;
(ar) & zHeights_;
(ar) & layerRouteDirections_;
(ar) & dieBox_;
(ar) & ggDRCCost_;
(ar) & ggMarkerCost_;
(ar) & halfViaEncArea_;
(ar) & ap_locs_;
}
friend class boost::serialization::access;
friend class FlexDRWorker;
};

Expand Down
Loading
Loading