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: Use boost flat hashmap when beneficial #6253

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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.86
boostVersionSmall=${boostVersionBig}.0
boostChecksum="077f074743ea7b0cb49c6ed43953ae95"
boostChecksum="ac857d73bb754b718a039830b07b9624"
eigenVersion=3.4
cuddVersion=3.0.0
lemonVersion=1.3.1
Expand Down
5 changes: 4 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,11 @@ if (SWIG_VERSION VERSION_GREATER_EQUAL "4.1.0")
endif()
include(UseSWIG)

find_package(Boost REQUIRED)
find_package(Boost 1.81.0)
Copy link
Member

Choose a reason for hiding this comment

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

any reason to drop REQUIRED?

Copy link
Author

Choose a reason for hiding this comment

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

I did it order to provide custom error message with suggestion about rerunning dependency installer.

message(STATUS "boost: ${Boost_VERSION}")
if(NOT Boost_FOUND)
message(FATAL_ERROR "No suitable version of boost found. Consider (re)running `<OpenROAD-dir>/etc/DependencyInstaller.sh -common`")
endif()

if (ENABLE_TESTS)
find_package(GTest REQUIRED)
Expand Down
8 changes: 8 additions & 0 deletions src/drt/src/db/infra/frPoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ class Point3D : public Point
return z_ < rhs.z_;
}

friend std::size_t hash_value(Point3D const& p)
{
std::size_t seed = 0;
boost::hash_combine(seed, hash_value(((Point) p)));
boost::hash_combine(seed, p.getZ());
return seed;
}

private:
int z_{0};
template <class Archive>
Expand Down
16 changes: 11 additions & 5 deletions src/drt/src/gc/FlexGC_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#pragma once

#include <boost/unordered/unordered_flat_set.hpp>
#include <memory>

#include "db/gcObj/gcNet.h"
Expand Down Expand Up @@ -191,31 +192,36 @@ class FlexGCWorker::Impl
void initNet_pins_polygonEdges(gcNet* net);
void initNet_pins_polygonEdges_getFixedPolygonEdges(
gcNet* net,
std::vector<std::set<std::pair<Point, Point>>>& fixedPolygonEdges);
std::vector<boost::unordered_flat_set<std::pair<Point, Point>>>&
fixedPolygonEdges);
void initNet_pins_polygonEdges_helper_outer(
gcNet* net,
gcPin* pin,
gcPolygon* poly,
frLayerNum i,
const std::vector<std::set<std::pair<Point, Point>>>& fixedPolygonEdges);
const std::vector<boost::unordered_flat_set<std::pair<Point, Point>>>&
fixedPolygonEdges);
void initNet_pins_polygonEdges_helper_inner(
gcNet* net,
gcPin* pin,
const gtl::polygon_90_data<frCoord>& hole_poly,
frLayerNum i,
const std::vector<std::set<std::pair<Point, Point>>>& fixedPolygonEdges);
const std::vector<boost::unordered_flat_set<std::pair<Point, Point>>>&
fixedPolygonEdges);
void initNet_pins_polygonCorners(gcNet* net);
void initNet_pins_polygonCorners_helper(gcNet* net, gcPin* pin);
void initNet_pins_maxRectangles(gcNet* net);
void initNet_pins_maxRectangles_getFixedMaxRectangles(
gcNet* net,
std::vector<std::set<std::pair<Point, Point>>>& fixedMaxRectangles);
std::vector<boost::unordered_flat_set<std::pair<Point, Point>>>&
fixedMaxRectangles);
void initNet_pins_maxRectangles_helper(
gcNet* net,
gcPin* pin,
const gtl::rectangle_data<frCoord>& rect,
frLayerNum i,
const std::vector<std::set<std::pair<Point, Point>>>& fixedMaxRectangles);
const std::vector<boost::unordered_flat_set<std::pair<Point, Point>>>&
fixedMaxRectangles);

void initRegionQuery();

Expand Down
21 changes: 14 additions & 7 deletions src/drt/src/gc/FlexGC_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,8 @@ void FlexGCWorker::Impl::initNet_pins_polygon(gcNet* net)

void FlexGCWorker::Impl::initNet_pins_polygonEdges_getFixedPolygonEdges(
gcNet* net,
std::vector<std::set<std::pair<Point, Point>>>& fixedPolygonEdges)
std::vector<boost::unordered_flat_set<std::pair<Point, Point>>>&
fixedPolygonEdges)
{
int numLayers = getTech()->getLayers().size();
std::vector<gtl::polygon_90_with_holes_data<frCoord>> polys;
Expand Down Expand Up @@ -552,7 +553,8 @@ void FlexGCWorker::Impl::initNet_pins_polygonEdges_helper_outer(
gcPin* pin,
gcPolygon* poly,
frLayerNum i,
const std::vector<std::set<std::pair<Point, Point>>>& fixedPolygonEdges)
const std::vector<boost::unordered_flat_set<std::pair<Point, Point>>>&
fixedPolygonEdges)
{
Point bp, ep, firstPt;
gtl::point_data<frCoord> bp1, ep1, firstPt1;
Expand Down Expand Up @@ -626,7 +628,8 @@ void FlexGCWorker::Impl::initNet_pins_polygonEdges_helper_inner(
gcPin* pin,
const gtl::polygon_90_data<frCoord>& hole_poly,
frLayerNum i,
const std::vector<std::set<std::pair<Point, Point>>>& fixedPolygonEdges)
const std::vector<boost::unordered_flat_set<std::pair<Point, Point>>>&
fixedPolygonEdges)
{
Point bp, ep, firstPt;
gtl::point_data<frCoord> bp1, ep1, firstPt1;
Expand Down Expand Up @@ -698,7 +701,8 @@ void FlexGCWorker::Impl::initNet_pins_polygonEdges_helper_inner(
void FlexGCWorker::Impl::initNet_pins_polygonEdges(gcNet* net)
{
int numLayers = getTech()->getLayers().size();
std::vector<std::set<std::pair<Point, Point>>> fixedPolygonEdges(numLayers);
std::vector<boost::unordered_flat_set<std::pair<Point, Point>>>
fixedPolygonEdges(numLayers);
// get all fixed polygon edges
initNet_pins_polygonEdges_getFixedPolygonEdges(net, fixedPolygonEdges);

Expand Down Expand Up @@ -852,7 +856,8 @@ void FlexGCWorker::Impl::initNet_pins_polygonCorners(gcNet* net)

void FlexGCWorker::Impl::initNet_pins_maxRectangles_getFixedMaxRectangles(
gcNet* net,
std::vector<std::set<std::pair<Point, Point>>>& fixedMaxRectangles)
std::vector<boost::unordered_flat_set<std::pair<Point, Point>>>&
fixedMaxRectangles)
{
int numLayers = getTech()->getLayers().size();
std::vector<gtl::rectangle_data<frCoord>> rects;
Expand All @@ -878,7 +883,8 @@ void FlexGCWorker::Impl::initNet_pins_maxRectangles_helper(
gcPin* pin,
const gtl::rectangle_data<frCoord>& rect,
frLayerNum i,
const std::vector<std::set<std::pair<Point, Point>>>& fixedMaxRectangles)
const std::vector<boost::unordered_flat_set<std::pair<Point, Point>>>&
fixedMaxRectangles)
{
auto rectangle = std::make_unique<gcRect>();
rectangle->setRect(rect);
Expand Down Expand Up @@ -916,7 +922,8 @@ void FlexGCWorker::Impl::initNet_pins_maxRectangles_helper(
void FlexGCWorker::Impl::initNet_pins_maxRectangles(gcNet* net)
{
int numLayers = getTech()->getLayers().size();
std::vector<std::set<std::pair<Point, Point>>> fixedMaxRectangles(numLayers);
std::vector<boost::unordered_flat_set<std::pair<Point, Point>>>
fixedMaxRectangles(numLayers);
// get all fixed max rectangles
initNet_pins_maxRectangles_getFixedMaxRectangles(net, fixedMaxRectangles);

Expand Down
12 changes: 6 additions & 6 deletions src/drt/src/io/GuideProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,7 @@ void addSplitRect(const frCoord track_idx,
void GuideProcessor::genGuides_split(
std::vector<frRect>& rects,
const TrackIntervalsByLayer& intvs,
const std::map<Point3D, frBlockObjectSet>& gcell_pin_map,
const boost::unordered_flat_map<Point3D, frBlockObjectSet>& gcell_pin_map,
frBlockObjectMap<std::set<Point3D>>& pin_gcell_map,
bool via_access_only) const
{
Expand Down Expand Up @@ -1262,7 +1262,7 @@ void GuideProcessor::genGuides_split(
}

void GuideProcessor::mapPinShapesToGCells(
std::map<Point3D, frBlockObjectSet>& gcell_pin_map,
boost::unordered_flat_map<Point3D, frBlockObjectSet>& gcell_pin_map,
frBlockObject* term) const
{
const auto pin_shapes = getPinShapes(term);
Expand All @@ -1283,7 +1283,7 @@ void GuideProcessor::mapPinShapesToGCells(

void GuideProcessor::initGCellPinMap(
const frNet* net,
std::map<Point3D, frBlockObjectSet>& gcell_pin_map) const
boost::unordered_flat_map<Point3D, frBlockObjectSet>& gcell_pin_map) const
{
for (auto instTerm : net->getInstTerms()) {
mapTermAccessPointsToGCells(gcell_pin_map, instTerm);
Expand All @@ -1294,7 +1294,7 @@ void GuideProcessor::initGCellPinMap(
}

void GuideProcessor::mapTermAccessPointsToGCells(
std::map<Point3D, frBlockObjectSet>& gcell_pin_map,
boost::unordered_flat_map<Point3D, frBlockObjectSet>& gcell_pin_map,
frBlockObject* pin) const
{
for (const auto& ap_loc : getAccessPoints(pin)) {
Expand Down Expand Up @@ -1376,7 +1376,7 @@ std::vector<std::pair<frBlockObject*, Point>> GuideProcessor::genGuides(
}
genGuides_prep(rects, intvs);

std::map<Point3D, frBlockObjectSet> gcell_pin_map;
boost::unordered_flat_map<Point3D, frBlockObjectSet> gcell_pin_map;
frBlockObjectMap<std::set<Point3D>> pin_gcell_map;
initGCellPinMap(net, gcell_pin_map);
initPinGCellMap(net, pin_gcell_map);
Expand Down Expand Up @@ -2024,4 +2024,4 @@ void GuideProcessor::processGuides()
}
}

} // namespace drt::io
} // namespace drt::io
27 changes: 15 additions & 12 deletions src/drt/src/io/GuideProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
///////////////////////////////////////////////////////////////////////////////
#pragma once
#include <boost/icl/interval_set.hpp>
#include <boost/unordered/unordered_flat_map.hpp>

#include "db/tech/frTechObject.h"
#include "frDesign.h"
Expand Down Expand Up @@ -175,11 +176,12 @@ class GuideProcessor
* guides only.
*
*/
void genGuides_split(std::vector<frRect>& rects,
const TrackIntervalsByLayer& intvs,
const std::map<Point3D, frBlockObjectSet>& gcell_pin_map,
frBlockObjectMap<std::set<Point3D>>& pin_gcell_map,
bool via_access_only) const;
void genGuides_split(
std::vector<frRect>& rects,
const TrackIntervalsByLayer& intvs,
const boost::unordered_flat_map<Point3D, frBlockObjectSet>& gcell_pin_map,
frBlockObjectMap<std::set<Point3D>>& pin_gcell_map,
bool via_access_only) const;
/**
* Initializes a map of gcell location to set of pins
*
Expand All @@ -190,9 +192,9 @@ class GuideProcessor
* considered by this function.
* @param gcell_pin_map A map to be populated by the result of this function.
*/
void initGCellPinMap(
const frNet* net,
std::map<Point3D, frBlockObjectSet>& gcell_pin_map) const;
void initGCellPinMap(const frNet* net,
boost::unordered_flat_map<Point3D, frBlockObjectSet>&
gcell_pin_map) const;
/**
* Populates gcell_pin_map with the values associated with the passed term
* based on pin shapes.
Expand All @@ -204,8 +206,9 @@ class GuideProcessor
* @param gcell_pin_map The map to be populated with the results.
* @param term The current pin we are processing.
*/
void mapPinShapesToGCells(std::map<Point3D, frBlockObjectSet>& gcell_pin_map,
frBlockObject* term) const;
void mapPinShapesToGCells(
boost::unordered_flat_map<Point3D, frBlockObjectSet>& gcell_pin_map,
frBlockObject* term) const;
/**
* Populates gcell_pin_map with the values associated with the passed pin
* based on access points.
Expand All @@ -218,7 +221,7 @@ class GuideProcessor
* @param term The current pin we are processing.
*/
void mapTermAccessPointsToGCells(
std::map<Point3D, frBlockObjectSet>& gcell_pin_map,
boost::unordered_flat_map<Point3D, frBlockObjectSet>& gcell_pin_map,
frBlockObject* pin) const;

void initPinGCellMap(frNet* net,
Expand Down Expand Up @@ -441,4 +444,4 @@ class GuidePathFinder
frBlockObjectMap<std::set<Point3D>> pin_gcell_map_;
std::vector<frRect> rects_;
};
} // namespace drt::io
} // namespace drt::io
4 changes: 3 additions & 1 deletion src/drt/src/pa/FlexPA_unique.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

#pragma once

#include <boost/unordered/unordered_flat_map.hpp>

#include "frDesign.h"

namespace drt {
Expand Down Expand Up @@ -158,7 +160,7 @@ class UniqueInsts
// Mapp all instances to their representative unique instance
std::map<frInst*, frInst*, frBlockObjectComp> inst_to_unique_;
// Maps all instances to the set of instances with the same unique inst
std::unordered_map<frInst*, InstSet*> inst_to_class_;
boost::unordered_flat_map<frInst*, InstSet*> inst_to_class_;
// Maps a unique instance to its pin access index
std::map<frInst*, int, frBlockObjectComp> unique_to_pa_idx_;
// Maps a unique instance to its index in unique_
Expand Down
15 changes: 15 additions & 0 deletions src/odb/include/odb/geom.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#pragma once

#include <algorithm>
#include <boost/functional/hash.hpp>
#include <iosfwd>
#include <tuple>
#include <vector>
Expand Down Expand Up @@ -90,6 +91,20 @@ class Point
int y_ = 0;
};

inline std::size_t hash_value(Point const& p)
{
size_t hash = 0;
if constexpr (sizeof(size_t) == 8 && sizeof(size_t) == 2 * sizeof(int)) {
// Use fast identity hash if possible. We don't care about avalanching since
// it will be mixed later by flat_map anyway
return ((size_t) p.getX() << 32) | p.getY();
} else {
boost::hash_combine(hash, p.x());
boost::hash_combine(hash, p.y());
}
return hash;
}

std::ostream& operator<<(std::ostream& os, const Point& pIn);

/*
Expand Down