Skip to content

Commit

Permalink
Parallelize other cost functions
Browse files Browse the repository at this point in the history
  • Loading branch information
kiryk committed Jan 16, 2024
1 parent c96b74d commit aa29037
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/mpl2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@

include("openroad")


set(THREADS_PREFER_PTHREAD_FLAG ON)

find_package(ortools REQUIRED)
find_package(OpenMP REQUIRED)

add_library(mpl2_lib
src/rtl_mp.cpp
Expand All @@ -60,6 +61,8 @@ target_link_libraries(mpl2_lib
ortools::ortools
dl
par_lib
Threads::Threads
OpenMP::OpenMP_CXX
)

swig_lib(NAME mpl2
Expand Down
7 changes: 5 additions & 2 deletions src/mpl2/src/SACoreSoftMacro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,13 +379,15 @@ void SACoreSoftMacro::calBoundaryPenalty()
}

int tot_num_macros = 0;
#pragma omp parallel for reduction(+:tot_num_macros)
for (const auto& macro : macros_) {
tot_num_macros += macro.getNumMacro();
}
if (tot_num_macros <= 0) {
return;
}

#pragma omp parallel for reduction(+:boundary_penalty_)
for (const auto& macro : macros_) {
if (macro.getNumMacro() > 0) {
const float lx = macro.getX();
Expand Down Expand Up @@ -419,6 +421,7 @@ void SACoreSoftMacro::calMacroBlockagePenalty()
return;
}

#pragma omp parallel for reduction(+:macro_blockage_penalty_)
for (auto& bbox : blockages_) {
for (const auto& macro : macros_) {
if (macro.getNumMacro() > 0) {
Expand All @@ -440,8 +443,8 @@ void SACoreSoftMacro::calMacroBlockagePenalty()
= std::abs((region_uy + region_ly) / 2.0 - (uy + ly) / 2.0);
x_dist = std::max(width - x_dist, 0.0f) / width;
y_dist = std::max(height - y_dist, 0.0f) / height;
macro_blockage_penalty_
+= (x_dist * x_dist + y_dist * y_dist) * macro.getNumMacro();
macro_blockage_penalty_ +=
(x_dist * x_dist + y_dist * y_dist) * macro.getNumMacro();
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/mpl2/src/SimulatedAnnealingCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ void SimulatedAnnealingCore<T>::calWirelength()

// calculate the total net weight
float tot_net_weight = 0.0;
#pragma omp parallel for reduction(+:tot_net_weight)
for (const auto& net : nets_) {
tot_net_weight += net.weight;
}
Expand All @@ -252,6 +253,7 @@ void SimulatedAnnealingCore<T>::calWirelength()
return;
}

#pragma omp parallel for reduction(+:wirelength_)
for (const auto& net : nets_) {
const float x1 = macros_[net.terminals.first].getPinX();
const float y1 = macros_[net.terminals.first].getPinY();
Expand Down Expand Up @@ -304,7 +306,7 @@ void SimulatedAnnealingCore<T>::calFencePenalty()
float height = y_dist <= max_y_dist ? 0.0 : (y_dist - max_y_dist);
width = width / outline_width_;
height = height / outline_height_;
fence_penalty_ += width * width + height * height;
fence_penalty_ = fence_penalty_ + width * width + height * height;
}
// normalization
fence_penalty_ = fence_penalty_ / fences_.size();
Expand Down Expand Up @@ -338,7 +340,7 @@ void SimulatedAnnealingCore<T>::calGuidancePenalty()
- (bbox.yMax() + bbox.yMin()) / 2.0);
x_dist = std::max(x_dist - width, 0.0f) / width;
y_dist = std::max(y_dist - height, 0.0f) / height;
guidance_penalty_ += x_dist * x_dist + y_dist * y_dist;
guidance_penalty_ = guidance_penalty_ + x_dist * x_dist + y_dist * y_dist;
}
guidance_penalty_ = guidance_penalty_ / guides_.size();
if (graphics_) {
Expand Down
2 changes: 1 addition & 1 deletion src/sta

0 comments on commit aa29037

Please sign in to comment.