Skip to content

Commit eebcc18

Browse files
authored
Merge pull request The-OpenROAD-Project#8710 from hongted/gpl-graphics-refactor
gpl: Factor out graphics use in gpl
2 parents ff6434e + 5c3fa7e commit eebcc18

20 files changed

+622
-244
lines changed

src/OpenRoad.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
#include "ord/OpenRoad.hh"
55

6+
#include <tcl.h>
7+
68
#include <cstdlib>
79
#include <cstring>
810
#include <filesystem>
@@ -267,6 +269,7 @@ void OpenRoad::init(Tcl_Interp* tcl_interp,
267269
rsz::initResizer(tcl_interp);
268270
ppl::initIoplacer(tcl_interp);
269271
gpl::initReplace(tcl_interp);
272+
gpl::initReplaceGraphics(replace_, logger_);
270273
dpl::initOpendp(tcl_interp);
271274
fin::initFinale(tcl_interp);
272275
ram::initRamGen(tcl_interp);

src/gpl/BUILD

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@ package(
1414
cc_library(
1515
name = "gpl",
1616
srcs = [
17+
"src/AbstractGraphics.cpp",
1718
"src/MakeReplace.cpp",
1819
"src/fft.cpp",
1920
"src/fft.h",
2021
"src/fftsg.cpp",
2122
"src/fftsg2d.cpp",
22-
"src/graphics.cpp",
23-
"src/graphics.h",
23+
"src/graphicsImpl.cpp",
24+
"src/graphicsImpl.h",
25+
"src/graphicsNone.cpp",
26+
"src/graphicsNone.h",
2427
"src/initialPlace.cpp",
2528
"src/initialPlace.h",
2629
"src/mbff.cpp",
@@ -43,6 +46,7 @@ cc_library(
4346
":tcl",
4447
],
4548
hdrs = [
49+
"include/gpl/AbstractGraphics.h",
4650
"include/gpl/MakeReplace.h",
4751
"include/gpl/Replace.h",
4852
],

src/gpl/CMakeLists.txt

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,34 +24,59 @@ swig_lib(NAME gpl
2424
SCRIPTS src/replace.tcl
2525
)
2626

27+
add_library(gpl_lib
28+
src/AbstractGraphics.cpp
29+
src/replace.cpp
30+
src/initialPlace.cpp
31+
src/nesterovPlace.cpp
32+
src/placerBase.cpp
33+
src/nesterovBase.cpp
34+
src/fft.cpp
35+
src/fftsg.cpp
36+
src/fftsg2d.cpp
37+
src/routeBase.cpp
38+
src/timingBase.cpp
39+
src/graphicsNone.cpp
40+
src/solver.cpp
41+
src/mbff.cpp
42+
)
43+
2744
target_sources(gpl
2845
PRIVATE
2946
src/MakeReplace.cpp
30-
src/replace.cpp
31-
src/initialPlace.cpp
32-
src/nesterovPlace.cpp
33-
src/placerBase.cpp
34-
src/nesterovBase.cpp
35-
src/fft.cpp
36-
src/fftsg.cpp
37-
src/fftsg2d.cpp
38-
src/routeBase.cpp
39-
src/timingBase.cpp
40-
src/graphics.cpp
41-
src/solver.cpp
42-
src/mbff.cpp
47+
src/graphicsImpl.cpp
4348
)
4449

4550
messages(TARGET gpl)
51+
messages(TARGET gpl_lib)
4652

4753
target_include_directories(gpl
54+
PUBLIC
55+
include
56+
)
57+
58+
target_include_directories(gpl_lib
4859
PUBLIC
4960
include
5061
${LEMON_INCLUDE_DIRS}
5162
)
5263

64+
target_link_libraries(gpl_lib
65+
PRIVATE
66+
utl_lib
67+
Eigen3::Eigen
68+
odb
69+
OpenSTA
70+
rsz_lib
71+
grt_lib
72+
ortools::ortools
73+
Threads::Threads
74+
OpenMP::OpenMP_CXX
75+
)
76+
5377
target_link_libraries(gpl
5478
PRIVATE
79+
gpl_lib
5580
utl_lib
5681
Eigen3::Eigen
5782
gui
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
// SPDX-License-Identifier: BSD-3-Clause
2+
// Copyright (c) 2020-2025, The OpenROAD Authors
3+
4+
#pragma once
5+
6+
#include <memory>
7+
#include <optional>
8+
#include <string_view>
9+
#include <utility>
10+
#include <vector>
11+
12+
#include "odb/db.h"
13+
#include "odb/geom.h"
14+
15+
namespace gpl {
16+
17+
class PlacerBaseCommon;
18+
class PlacerBase;
19+
class NesterovBase;
20+
class NesterovBaseCommon;
21+
class NesterovPlace;
22+
23+
// This is an abstract interface for gpl to draw debugging graphics on the
24+
// layout.
25+
class AbstractGraphics
26+
{
27+
public:
28+
using LineSeg = std::pair<odb::Point, odb::Point>;
29+
using LineSegs = std::vector<LineSeg>;
30+
31+
virtual ~AbstractGraphics();
32+
33+
// Create a new object of the same class.
34+
virtual std::unique_ptr<AbstractGraphics> MakeNew(utl::Logger* logger) const
35+
= 0;
36+
37+
// Turns debug on and sets mode to Mbff.
38+
virtual void debugForMbff() = 0;
39+
40+
// Turns debug on and sets mode to Initial(place).
41+
virtual void debugForInitialPlace(
42+
std::shared_ptr<PlacerBaseCommon> pbc,
43+
std::vector<std::shared_ptr<PlacerBase>>& pbVec)
44+
= 0;
45+
46+
// Turns debug on and sets mode to Nesterov(place)
47+
virtual void debugForNesterovPlace(
48+
NesterovPlace* np,
49+
std::shared_ptr<PlacerBaseCommon> pbc,
50+
std::shared_ptr<NesterovBaseCommon> nbc,
51+
std::vector<std::shared_ptr<PlacerBase>>& pbVec,
52+
std::vector<std::shared_ptr<NesterovBase>>& nbVec,
53+
bool draw_bins,
54+
odb::dbInst* inst)
55+
= 0;
56+
57+
// Draw the graphics; optionally pausing afterwards
58+
void cellPlot(bool pause = false) { cellPlotImpl(pause); }
59+
60+
// Update the chart for the current iter
61+
virtual void addIter(int iter, double overflow) = 0;
62+
virtual void addTimingDrivenIter(int iter) = 0;
63+
virtual void addRoutabilitySnapshot(int iter) = 0;
64+
virtual void addRoutabilityIter(int iter, bool revert) = 0;
65+
66+
// Draw the MBFF mapping
67+
virtual void mbffMapping(const LineSegs& segs) = 0;
68+
virtual void mbffFlopClusters(const std::vector<odb::dbInst*>& ffs) = 0;
69+
70+
// Show a message in the status bar
71+
virtual void status(std::string_view message) = 0;
72+
73+
// Is the graphics enabled or not.
74+
// Graphics could be disabled for
75+
//
76+
// 1. Debug not being on.
77+
// 2. Being used as a library (ex. in a test).
78+
// 3. The GUI is not displayed.
79+
virtual bool enabled() = 0;
80+
81+
// Set the debug condition to `set_on`.
82+
//
83+
// Note that even if set, the graphics may still be disabled under conditions
84+
// #2 and #3 of enabled() above.
85+
virtual void setDebugOn(bool set_on) = 0;
86+
87+
void addFrameLabel(const odb::Rect& bbox,
88+
std::string_view label,
89+
std::string_view label_name,
90+
int image_width_px = 500)
91+
{
92+
addFrameLabelImpl(bbox, label, label_name, image_width_px);
93+
}
94+
95+
void saveLabeledImage(std::string_view path,
96+
std::string_view label,
97+
bool select_buffers,
98+
std::string_view heatmap_control = "",
99+
int image_width_px = 500)
100+
{
101+
saveLabeledImageImpl(
102+
path, label, select_buffers, heatmap_control, image_width_px);
103+
}
104+
105+
// Gui functions.
106+
virtual void gifStart(std::string_view path) = 0;
107+
void gifAddFrame(const odb::Rect& region = odb::Rect(),
108+
int width_px = 0,
109+
double dbu_per_pixel = 0,
110+
std::optional<int> delay = std::nullopt)
111+
{
112+
gifAddFrameImpl(region, width_px, dbu_per_pixel, delay);
113+
}
114+
virtual void deleteLabel(std::string_view label_name) = 0;
115+
virtual void gifEnd() = 0;
116+
117+
protected:
118+
virtual void cellPlotImpl(bool pause) = 0;
119+
120+
virtual void addFrameLabelImpl(const odb::Rect& bbox,
121+
std::string_view label,
122+
std::string_view label_name,
123+
int image_width_px)
124+
= 0;
125+
virtual void saveLabeledImageImpl(std::string_view path,
126+
std::string_view label,
127+
bool select_buffers,
128+
std::string_view heatmap_control,
129+
int image_width_px)
130+
= 0;
131+
virtual void gifAddFrameImpl(const odb::Rect& region,
132+
int width_px,
133+
double dbu_per_pixel,
134+
std::optional<int> delay)
135+
= 0;
136+
};
137+
138+
} // namespace gpl

src/gpl/include/gpl/MakeReplace.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44
#pragma once
55

66
#include <tcl.h>
7+
namespace utl {
8+
class Logger;
9+
} // namespace utl
710

811
namespace gpl {
912

1013
class Replace;
1114

1215
void initReplace(Tcl_Interp* tcl_interp);
16+
void initReplaceGraphics(Replace* replace, utl::Logger* log);
1317

1418
} // namespace gpl

src/gpl/include/gpl/Replace.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include <string>
88
#include <vector>
99

10+
#include "AbstractGraphics.h"
11+
1012
namespace odb {
1113
class dbDatabase;
1214
class dbInst;
@@ -46,13 +48,21 @@ using Clusters = std::vector<Cluster>;
4648
class Replace
4749
{
4850
public:
51+
// Create a replace object with no graphics.
4952
Replace(odb::dbDatabase* odb,
5053
sta::dbSta* sta,
5154
rsz::Resizer* resizer,
5255
grt::GlobalRouter* router,
5356
utl::Logger* logger);
57+
5458
~Replace();
5559

60+
// Use the following class as a template for graphics interface.
61+
//
62+
// Note: no ownership is transfered as the object will create a new
63+
// graphics object of the same class.
64+
void setGraphicsInterface(const gpl::AbstractGraphics& graphics);
65+
5666
void reset();
5767

5868
void doIncrementalPlace(int threads);
@@ -130,6 +140,8 @@ class Replace
130140
grt::GlobalRouter* fr_ = nullptr;
131141
utl::Logger* log_ = nullptr;
132142

143+
std::unique_ptr<AbstractGraphics> graphics_;
144+
133145
std::shared_ptr<PlacerBaseCommon> pbc_;
134146
std::shared_ptr<NesterovBaseCommon> nbc_;
135147
std::vector<std::shared_ptr<PlacerBase>> pbVec_;

src/gpl/src/AbstractGraphics.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// SPDX-License-Identifier: BSD-3-Clause
2+
// Copyright (c) 2020-2025, The OpenROAD Authors
3+
4+
#include "gpl/AbstractGraphics.h"
5+
6+
namespace gpl {
7+
8+
AbstractGraphics::~AbstractGraphics() = default;
9+
10+
} // namespace gpl

src/gpl/src/MakeReplace.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include <tcl.h>
77

88
#include "gpl/Replace.h"
9+
#include "graphicsImpl.h"
10+
#include "utl/Logger.h"
911
#include "utl/decode.h"
1012

1113
extern "C" {
@@ -22,4 +24,9 @@ void initReplace(Tcl_Interp* tcl_interp)
2224
utl::evalTclInit(tcl_interp, gpl::gpl_tcl_inits);
2325
}
2426

27+
void initReplaceGraphics(Replace* replace, utl::Logger* log)
28+
{
29+
replace->setGraphicsInterface(gpl::GraphicsImpl(log));
30+
}
31+
2532
} // namespace gpl

0 commit comments

Comments
 (0)