|
| 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 |
0 commit comments