Skip to content

gpl: modernize density parallelization - #11086

Open
oharboe wants to merge 1 commit into
The-OpenROAD-Project:masterfrom
oharboe:gpl-parallelize-density
Open

gpl: modernize density parallelization#11086
oharboe wants to merge 1 commit into
The-OpenROAD-Project:masterfrom
oharboe:gpl-parallelize-density

Conversation

@oharboe

@oharboe oharboe commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

gpl: modernize density parallelization

Replace old OpenMP raw iterators and unchunked bounds in updateBinsGCellDensityArea and updateDensityFieldBin with modern indexed arrays and explicitly enforce schedule(static) across all phases of the loop.

This removes sequential clear bottlenecks per Nesterov iteration and eliminates heavy kmp_flag_64::wait OpenMP spin-wait barriers during density field evaluation because static scheduling forces threads to take the identical bin distribution across all loops without dynamic work-stealing overhead.

Dogfooding Results:
Combined with the #11084 vectorized forces patch, running the end-to-end global placement flow on a 2.4M-net commercial testcase drops runtime by an additional 100 seconds (1.8%), from 5,511s down to 5,411s. Output placement convergence and metrics remain perfectly 100% bit-identical.

@oharboe
oharboe requested a review from a team as a code owner August 6, 2026 09:02
@oharboe
oharboe requested a review from gudeh August 6, 2026 09:02
@github-actions github-actions Bot added the size/S label Aug 6, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request refactors loops in nesterovBase.cpp to use index-based iteration parallelized with OpenMP (#pragma omp parallel for schedule(static)) instead of range-based or iterator-based loops. The feedback recommends caching the reference to the bins vector returned by getBins() before entering the parallel loops to avoid the overhead of repeated method calls in these performance-critical sections.

Comment thread src/gpl/src/nesterovBase.cpp Outdated
Comment thread src/gpl/src/nesterovBase.cpp Outdated
@oharboe
oharboe force-pushed the gpl-parallelize-density branch from 79c57d9 to d1721de Compare August 6, 2026 09:10
@oharboe

oharboe commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request parallelizes several loops in nesterovBase.cpp using OpenMP with static scheduling and index-based iteration. However, a compilation error is introduced in NesterovBase::updateDensityFieldBin because the variable bins is declared twice within the same function scope.

Comment thread src/gpl/src/nesterovBase.cpp Outdated
@oharboe
oharboe force-pushed the gpl-parallelize-density branch from d1721de to 89f0692 Compare August 6, 2026 09:17
@oharboe

oharboe commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request refactors several loops in nesterovBase.cpp to use index-based iteration parallelized with OpenMP static scheduling instead of range-based or iterator-based loops. The review feedback recommends adding conditional clauses (if) to the OpenMP directives to prevent parallelization overhead and potential runtime issues when the thread count is one or less.

Comment thread src/gpl/src/nesterovBase.cpp Outdated
Comment thread src/gpl/src/nesterovBase.cpp
Comment thread src/gpl/src/nesterovBase.cpp Outdated
@oharboe
oharboe force-pushed the gpl-parallelize-density branch from 89f0692 to 0c827a9 Compare August 6, 2026 09:23
@oharboe

oharboe commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request parallelizes several loops over bins in nesterovBase.cpp using OpenMP with static scheduling. The review feedback highlights potential undefined behavior in OpenMP if the thread count evaluates to zero or a negative number, and suggests using std::max to guarantee a positive thread count for the num_threads clause.

Comment thread src/gpl/src/nesterovBase.cpp Outdated
Comment thread src/gpl/src/nesterovBase.cpp Outdated
Comment thread src/gpl/src/nesterovBase.cpp Outdated
@oharboe
oharboe force-pushed the gpl-parallelize-density branch from 0c827a9 to cf84f0b Compare August 6, 2026 09:27
@oharboe

oharboe commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request refactors loops in nesterovBase.cpp to use index-based iteration, allowing for cleaner OpenMP parallelization with static scheduling. The reviewer suggested improving readability and consistency in BinGrid::updateBinsGCellDensityArea by defining a local thread_count variable instead of using a multi-line preprocessor directive.

Comment thread src/gpl/src/nesterovBase.cpp Outdated
@oharboe
oharboe force-pushed the gpl-parallelize-density branch from cf84f0b to f958d18 Compare August 6, 2026 09:30
@oharboe

oharboe commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request refactors several loops in nesterovBase.cpp to use index-based iteration and conditional OpenMP parallelization with a safe thread count. The review feedback points out that performing an OpenMP reduction directly on the class member variable sumPhi_ can lead to compilation errors or undefined behavior on certain compilers, and recommends using a local variable for the reduction instead.

Comment thread src/gpl/src/nesterovBase.cpp Outdated
@oharboe
oharboe force-pushed the gpl-parallelize-density branch from f958d18 to 41cba78 Compare August 6, 2026 09:37
@oharboe

oharboe commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request modernizes OpenMP parallel loops in src/gpl/src/nesterovBase.cpp by replacing old-style iterator loops with index-based loops, adding schedule(static) directives, and using local variables for reductions. Feedback suggests also updating a third loop in updateBinsGCellDensityArea to use index-based iteration and static scheduling to ensure consistency and maximize cache locality.

Comment thread src/gpl/src/nesterovBase.cpp
@oharboe
oharboe force-pushed the gpl-parallelize-density branch from 41cba78 to c735225 Compare August 6, 2026 09:41
@oharboe

oharboe commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request modernizes several OpenMP loops in nesterovBase.cpp by replacing iterator-based loops with index-based loops, adding static scheduling, and avoiding parallel region overhead for single-threaded execution. Additionally, it refactors the reduction on the class member sumPhi_ to use a local variable for better portability. The review feedback suggests further optimizing the loop in updateBinsGCellDensityArea by adding an if (num_threads_ > 1) clause and refactoring class member reductions to local variables to prevent potential compilation issues.

Comment thread src/gpl/src/nesterovBase.cpp Outdated
@oharboe
oharboe force-pushed the gpl-parallelize-density branch from c735225 to b15f0ec Compare August 6, 2026 09:45
@oharboe

oharboe commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request parallelizes bin-area clearing, density updates, and electro-phi updates using OpenMP, introducing local accumulation variables for reduction. The feedback highlights potential floating-point precision loss when accumulating values over a large number of bins using float precision. It is recommended to use double for local accumulation variables (local_sum_overflow_area, local_sum_overflow_area_unscaled, and local_sum_phi) and then cast or round them appropriately when assigning them back to the class member variables.

Comment thread src/gpl/src/nesterovBase.cpp Outdated
Comment thread src/gpl/src/nesterovBase.cpp
Comment thread src/gpl/src/nesterovBase.cpp
Comment thread src/gpl/src/nesterovBase.cpp
@oharboe
oharboe force-pushed the gpl-parallelize-density branch from b15f0ec to 612afff Compare August 6, 2026 09:48
@oharboe

oharboe commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request parallelizes and optimizes bin-area clearing and density updates in nesterovBase.cpp using OpenMP. It introduces local reduction variables to avoid direct reductions on member variables and replaces iterator-based loops with index-based loops. The reviewer identified an inconsistency in BinGrid::updateBinsGCellDensityArea where the second parallel loop uses num_threads_ instead of the local thread_count variable, which bypasses the caller's thread configuration and can lead to synchronization overhead.

Comment thread src/gpl/src/nesterovBase.cpp Outdated
@oharboe
oharboe force-pushed the gpl-parallelize-density branch from 612afff to 806e47c Compare August 6, 2026 09:54
@oharboe

oharboe commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request parallelizes the bin-area clearing loop and refactors OpenMP loops in nesterovBase.cpp to use index-based iteration and local variables for reductions instead of member variables. The feedback suggests using thread_count instead of parallel_threads in the OpenMP if clause of the first loop to maintain consistency with other parallel loops in the file.

Comment thread src/gpl/src/nesterovBase.cpp
@oharboe
oharboe force-pushed the gpl-parallelize-density branch from 806e47c to cee56d8 Compare August 6, 2026 09:58
@oharboe

oharboe commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request modernizes several OpenMP loops in nesterovBase.cpp by converting iterator-based loops to index-based loops, introducing safe thread-count checks, and specifying static scheduling. It also refactors reduction operations to use local variables instead of directly modifying class member variables within parallel regions. The reviewer suggests adding schedule(static) to one of the parallel loops for consistency and to explicitly enforce the scheduling policy.

Comment thread src/gpl/src/nesterovBase.cpp Outdated
@oharboe
oharboe force-pushed the gpl-parallelize-density branch from cee56d8 to cad56ac Compare August 6, 2026 10:09
@oharboe

oharboe commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request refactors OpenMP parallelization in src/gpl/src/nesterovBase.cpp by replacing iterator-based loops with index-based loops and introducing local variables for reduction operations to safely update member variables. It also ensures thread safety by guarding parallel regions with a validated thread_count. The review feedback suggests improving the readability and consistency of the OpenMP pragmas by reordering and formatting their clauses.

Comment thread src/gpl/src/nesterovBase.cpp Outdated
Comment thread src/gpl/src/nesterovBase.cpp Outdated
@oharboe
oharboe force-pushed the gpl-parallelize-density branch from cad56ac to 27286d2 Compare August 6, 2026 10:29
@oharboe

oharboe commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request refactors OpenMP parallel loops in nesterovBase.cpp to improve thread safety and precision by replacing direct reductions on class member variables with local double accumulators and switching to index-based loops. The reviewer noted a potential precision loss in the calculation of local_sum_phi where casting the bin area sum to float instead of double can introduce truncation errors, and suggested performing the entire calculation in double precision.

Comment thread src/gpl/src/nesterovBase.cpp
Replace old OpenMP raw iterators and unchunked bounds in `updateBinsGCellDensityArea` and `updateDensityFieldBin` with modern indexed arrays and explicitly enforce `schedule(static)` across all phases of the loop.

This removes sequential clear bottlenecks per Nesterov iteration and eliminates heavy `kmp_flag_64::wait` OpenMP spin-wait barriers during density field evaluation because static scheduling forces threads to take the identical `bin` distribution across all loops without dynamic work-stealing overhead.

**Dogfooding Results**:
Combined with the The-OpenROAD-Project#11084 vectorized forces patch, running the end-to-end global placement flow on a 2.4M-net commercial testcase drops runtime by an additional **100 seconds (1.8%)**, from 5,511s down to **5,411s**. Output placement convergence and metrics remain perfectly 100% bit-identical.

Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
@oharboe
oharboe force-pushed the gpl-parallelize-density branch from 27286d2 to 58cb8ee Compare August 6, 2026 10:54
@oharboe

oharboe commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator Author

@gudeh @maliberty gemini doesn't converge and it gets things wrong, hence the numerous iteraitons here.

@gudeh
gudeh requested review from LucasYuki and removed request for gudeh August 6, 2026 19:41
@gudeh

gudeh commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

@LucasYuki has been working with MT related changes in gpl

@oharboe

oharboe commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator Author

@LucasYuki has been working with MT related changes in gpl

Great! My finding here is that there is some performance on the table here. the code is unremarkable.

Should I close this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants