Skip to content
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
396 changes: 376 additions & 20 deletions src/gui/src/chiplet3DWidget.cpp

Large diffs are not rendered by default.

23 changes: 21 additions & 2 deletions src/gui/src/chiplet3DWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
#include <cstdint>
#include <vector>

#include "gui/gui.h"

namespace odb {
class dbChip;
}
class dbObject;
} // namespace odb
namespace utl {
class Logger;
}
Expand All @@ -30,6 +33,10 @@ class Chiplet3DWidget : public QWidget
void setChip(odb::dbChip* chip);
void setLogger(utl::Logger* logger);

public slots:
void setSelection(const SelectionSet& selection);
void selectionFocus(const Selected& focus);

protected:
void paintEvent(QPaintEvent* event) override;
void mousePressEvent(QMouseEvent* event) override;
Expand All @@ -49,6 +56,13 @@ class Chiplet3DWidget : public QWidget
const QMatrix4x4& projection,
const QRect& viewport);

void drawFace3D(QPainter& painter,
const std::vector<QVector3D>& face_verts_world,
const QColor& color,
const QMatrix4x4& modelView,
const QMatrix4x4& projection,
const QRect& viewport);

odb::dbChip* chip_ = nullptr;
utl::Logger* logger_ = nullptr;

Expand All @@ -70,7 +84,12 @@ class Chiplet3DWidget : public QWidget
};

std::vector<VertexData> vertices_;
std::vector<uint32_t> indices_lines_;
std::vector<uint32_t> indices_faces_;

SelectionSet selection_;
Selected focus_;
std::vector<const odb::dbObject*> chip_objects_;
std::vector<int> face_to_chip_index_;
};

} // namespace gui
11 changes: 11 additions & 0 deletions src/gui/src/mainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ MainWindow::MainWindow(bool load_settings, QWidget* parent)
&MainWindow::chipLoaded,
chiplet_viewer_,
&Chiplet3DWidget::setChip);
connect(this, &MainWindow::selectionChanged, [this]() {
chiplet_viewer_->setSelection(selected_);
});
connect(this, &MainWindow::redraw, viewers_, &LayoutTabs::fullRepaint);
connect(
this, &MainWindow::blockLoaded, controls_, &DisplayControls::blockLoaded);
Expand Down Expand Up @@ -256,8 +259,16 @@ MainWindow::MainWindow(bool load_settings, QWidget* parent)
&MainWindow::updateSelectedStatus);
connect(inspector_, &Inspector::selection, viewers_, &LayoutTabs::selection);
connect(inspector_, &Inspector::focus, viewers_, &LayoutTabs::selectionFocus);
connect(inspector_,
&Inspector::focus,
chiplet_viewer_,
&Chiplet3DWidget::selectionFocus);
connect(
drc_viewer_, &DRCWidget::focus, viewers_, &LayoutTabs::selectionFocus);
connect(drc_viewer_,
&DRCWidget::focus,
chiplet_viewer_,
&Chiplet3DWidget::selectionFocus);
connect(
this, &MainWindow::highlightChanged, inspector_, &Inspector::loadActions);
connect(viewers_,
Expand Down
6 changes: 3 additions & 3 deletions src/gui/src/renderThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1548,11 +1548,11 @@ void RenderThread::drawModuleView(QPainter* painter,
continue;
}

const auto& setting = viewer_->modules_.at(module);

if (!setting.visible) {
auto setting_it = viewer_->modules_.find(module);
if (setting_it == viewer_->modules_.end() || !setting_it->second.visible) {
continue;
}
const auto& setting = setting_it->second;

odb::Rect inst_outline = inst->getBBox()->getBox();

Expand Down
127 changes: 53 additions & 74 deletions src/mpl/src/SACoreSoftMacro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ void SACoreSoftMacro::fillCoordsLists(std::vector<int>& x_coords,
std::vector<int> y_point;

for (auto& macro : macros_) {
if (!macro.isMacroCluster() && !macro.isMixedCluster()) {
if (macro.isStdCellCluster()) {
continue;
}
x_point.push_back(macro.getX());
Expand All @@ -647,98 +647,86 @@ void SACoreSoftMacro::fillCoordsLists(std::vector<int>& x_coords,
std::ranges::sort(x_point);
std::ranges::sort(y_point);

// getSegmentIndex requires the bigger value
// from points within the same epsilon to work properly
int epsilon = outline_.dx() / 100;
x_coords.push_back(x_point.back());
for (int i = x_point.size() - 2; i >= 0; i--) {
if (x_coords.back() - x_point[i] > epsilon) {
x_coords.push_back(x_point[i]);
for (int i = 0; i < x_point.size(); i++) {
if (i + 1 < x_point.size()
&& std::abs(x_point[i + 1] - x_point[i]) <= epsilon) {
continue;
}
x_coords.push_back(x_point[i]);
}
std::ranges::reverse(x_coords);

epsilon = outline_.dy() / 100;
y_coords.push_back(y_point.back());

for (int i = y_point.size() - 2; i >= 0; i--) {
if (y_coords.back() - y_point[i] > epsilon) {
y_coords.push_back(y_point[i]);
for (int i = 0; i < y_point.size(); i++) {
if (i + 1 < y_point.size()
&& std::abs(y_point[i + 1] - y_point[i]) <= epsilon) {
continue;
}
y_coords.push_back(y_point[i]);
}
std::ranges::reverse(y_coords);
}

SACoreSoftMacro::NotchVicinity SACoreSoftMacro::checkNotchVicinity(
const std::vector<std::vector<bool>>& grid,
const int start_row,
const int start_col,
const int end_row,
const int end_col)
SACoreSoftMacro::Neighbors SACoreSoftMacro::findNeighbors(
std::vector<std::vector<bool>>& grid,
int start_row,
int start_col,
int end_row,
int end_col)
{
int num_y = grid.size();
int num_x = grid.front().size();

NotchVicinity vicinity;
Neighbors neighbors;
if (start_row > 0) {
for (int i = start_col; i <= end_col; i++) {
if (!grid[start_row - 1][i]) {
vicinity.bottom = false;
neighbors.bottom = false;
break;
}
}
}
if (end_row < num_y - 1) {
for (int i = start_col; i <= end_col; i++) {
if (!grid[end_row + 1][i]) {
vicinity.top = false;
neighbors.top = false;
break;
}
}
}
if (start_col > 0) {
for (int i = start_row; i <= end_row; i++) {
if (!grid[i][start_col - 1]) {
vicinity.left = false;
neighbors.left = false;
break;
}
}
}
if (end_col < num_x - 1) {
for (int i = start_row; i <= end_row; i++) {
if (!grid[i][end_col + 1]) {
vicinity.right = false;
neighbors.right = false;
break;
}
}
}

return vicinity;
return neighbors;
}

bool SACoreSoftMacro::isRowEmpty(const std::vector<std::vector<bool>>& grid,
const int row,
const int start_col,
const int end_col)
bool SACoreSoftMacro::isSegmentEmpty(std::vector<std::vector<bool>>& grid,
int start_row,
int start_col,
int end_row,
int end_col)
{
for (int col = start_col; col <= end_col; col++) {
if (grid[row][col]) {
return false;
for (int i = start_row; i <= end_row; i++) {
for (int j = start_col; j <= end_col; j++) {
if (grid[i][j]) {
return false;
}
}
}
return true;
}

bool SACoreSoftMacro::isColEmpty(const std::vector<std::vector<bool>>& grid,
const int col,
const int start_row,
const int end_row)
{
for (int row = start_row; row <= end_row; row++) {
if (grid[row][col]) {
return false;
}
}
return true;
}

Expand Down Expand Up @@ -791,7 +779,7 @@ void SACoreSoftMacro::calNotchPenalty()

std::vector<std::vector<bool>> grid(num_y, std::vector<bool>(num_x, false));
for (auto& macro : macros_) {
if (!macro.isMacroCluster() && !macro.isMixedCluster()) {
if (macro.isStdCellCluster()) {
continue;
}
int x_start = getSegmentIndex(macro.getX(), x_coords);
Expand All @@ -805,33 +793,30 @@ void SACoreSoftMacro::calNotchPenalty()
}
}

std::vector<std::vector<bool>> visited(num_y,
std::vector<bool>(num_x, false));

for (int start_row = 0; start_row < num_y; start_row++) {
for (int start_col = 0; start_col < num_x; start_col++) {
if (grid[start_row][start_col] || visited[start_row][start_col]) {
if (grid[start_row][start_col]) {
continue;
}

int end_row = start_row;
int end_col = start_col;

NotchVicinity current_vicinity
= checkNotchVicinity(grid, start_row, start_col, end_row, end_col);
Neighbors current_neighbors
= findNeighbors(grid, start_row, start_col, end_row, end_col);
bool expand_rows = true;
bool expand_cols = true;

while (expand_rows || expand_cols) {
if (expand_rows) {
end_row += 1;
if (end_row < num_y
&& isRowEmpty(grid, end_row, start_col, end_col)) {
NotchVicinity expanded_vicinity = checkNotchVicinity(
grid, start_row, start_col, end_row, end_col);
if (expanded_vicinity.total() > current_vicinity.total()
|| expanded_vicinity == current_vicinity) {
current_vicinity = expanded_vicinity;
&& isSegmentEmpty(grid, start_row, start_col, end_row, end_col)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Checking the entire segment from start_row to end_row is redundant because the previous rows were already verified to be empty in previous iterations of the while loop. Only the new row end_row needs to be checked for efficiency.

Suggested change
&& isSegmentEmpty(grid, start_row, start_col, end_row, end_col)) {
&& isSegmentEmpty(grid, end_row, start_col, end_row, end_col)) {
References
  1. When analyzing code within a loop, consider the entire loop structure. Operations at the beginning of the loop (e.g., journalBegin) can affect the logic within the loop body, potentially making similar calls inside the loop redundant.

Neighbors expanded_neighbors
= findNeighbors(grid, start_row, start_col, end_row, end_col);
if (expanded_neighbors.total() > current_neighbors.total()
|| expanded_neighbors == current_neighbors) {
current_neighbors = expanded_neighbors;
} else {
expand_rows = false;
end_row -= 1;
Expand All @@ -845,12 +830,12 @@ void SACoreSoftMacro::calNotchPenalty()
if (expand_cols) {
end_col += 1;
if (end_col < num_x
&& isColEmpty(grid, end_col, start_row, end_row)) {
NotchVicinity expanded_vicinity = checkNotchVicinity(
grid, start_row, start_col, end_row, end_col);
if (expanded_vicinity.total() > current_vicinity.total()
|| expanded_vicinity == current_vicinity) {
current_vicinity = expanded_vicinity;
&& isSegmentEmpty(grid, start_row, start_col, end_row, end_col)) {
Neighbors expanded_neighbors
= findNeighbors(grid, start_row, start_col, end_row, end_col);
if (expanded_neighbors.total() > current_neighbors.total()
|| expanded_neighbors == current_neighbors) {
current_neighbors = expanded_neighbors;
} else {
expand_cols = false;
end_col -= 1;
Expand All @@ -862,23 +847,17 @@ void SACoreSoftMacro::calNotchPenalty()
}
}

for (int i = start_row; i < end_row + 1; i++) {
for (int j = start_col; j < end_col + 1; j++) {
visited[i][j] = true;
}
}

width = x_coords[end_col + 1] - x_coords[start_col];
height = y_coords[end_row + 1] - y_coords[start_row];

bool is_notch = false;
if (current_vicinity.top && current_vicinity.bottom) {
if (current_neighbors.total() == 4) {
is_notch = true;
} else if (current_neighbors.top && current_neighbors.bottom) {
if (height < notch_h_th_) {
is_notch = true;
}
}

if (current_vicinity.left && current_vicinity.right) {
} else if (current_neighbors.left && current_neighbors.right) {
if (width < notch_v_th_) {
is_notch = true;
}
Expand Down
30 changes: 13 additions & 17 deletions src/mpl/src/SACoreSoftMacro.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ class SACoreSoftMacro : public SimulatedAnnealingCore<SoftMacro>
void forceCentralization() { force_centralization_ = true; }

private:
// Used to check the vicinity of candidate notches
struct NotchVicinity
// Used to calculate notches
struct Neighbors
{
bool top = true;
bool bottom = true;
Expand All @@ -84,7 +84,7 @@ class SACoreSoftMacro : public SimulatedAnnealingCore<SoftMacro>

int total() { return top + bottom + left + right; }

bool operator==(const NotchVicinity&) const = default;
bool operator==(const Neighbors&) const = default;
};

float calNormCost() const override;
Expand All @@ -100,20 +100,16 @@ class SACoreSoftMacro : public SimulatedAnnealingCore<SoftMacro>

void calBoundaryPenalty();
void fillCoordsLists(std::vector<int>& x_coords, std::vector<int>& y_coords);
static NotchVicinity checkNotchVicinity(
const std::vector<std::vector<bool>>& grid,
int start_row,
int start_col,
int end_row,
int end_col);
static bool isRowEmpty(const std::vector<std::vector<bool>>& grid,
int row,
int start_col,
int end_col);
static bool isColEmpty(const std::vector<std::vector<bool>>& grid,
int col,
int start_row,
int end_row);
Neighbors findNeighbors(std::vector<std::vector<bool>>& grid,
int start_row,
int start_col,
int end_row,
int end_col);
bool isSegmentEmpty(std::vector<std::vector<bool>>& grid,
int start_row,
int tart_col,
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Typo in parameter name: tart_col should be start_col to match the implementation and maintain consistency.

Suggested change
int tart_col,
int start_col,

int end_row,
int end_col);
float calSingleNotchPenalty(int width, int height);
void calNotchPenalty();
void calMacroBlockagePenalty();
Expand Down
Loading