Skip to content

undo prep for module swap#6911

Merged
maliberty merged 41 commits into
The-OpenROAD-Project:masterfrom
The-OpenROAD-Project-staging:secure-module-swap11
Apr 2, 2025
Merged

undo prep for module swap#6911
maliberty merged 41 commits into
The-OpenROAD-Project:masterfrom
The-OpenROAD-Project-staging:secure-module-swap11

Conversation

@openroad-ci
Copy link
Copy Markdown
Collaborator

@openroad-ci openroad-ci commented Mar 26, 2025

  1. old mod inst is now deleted and new one is created for module swap
  2. saved old module to a child block for future use after module swap
  3. added two tests to test ODB journal save/restore
    odb/test/replace_hier_mod_undo.tcl leads to a fatal
    odb/test/replace_hier_mod_undo2.tcl produces an error:
    [CRITICAL ODB-0417] No undo_deleteObject support for type dbBTerm
  4. fixed a few ODB bug fixes to avoid fatals with hierarchy
    a) dbModInst.cpp and dbModule.cc - save objects in vector before deleting them inside iterator loop
    b) dbNetwork.cc - add nullptr checks in visitConnectedPins
    c) EstimateWireParasitics.cc - skip mod pins and no net pins
  5. replaced delimeter with delimiter

precisionmoon and others added 16 commits March 20, 2025 05:42
1) saved old module into a child block for future use
2) replaced delimeter with delimiter
3) added replace_hier_mod_undo.tcl (not working yet)

Signed-off-by: Cho Moon <cmoon@precisioninno.com>
Signed-off-by: Cho Moon <cmoon@precisioninno.com>
Signed-off-by: Cho Moon <cmoon@precisioninno.com>
Signed-off-by: Cho Moon <cmoon@precisioninno.com>
This reverts commit b94845d.
…le-swap11"

This reverts commit 28bc612, reversing
changes made to 36a8c9c.
Signed-off-by: Cho Moon <cmoon@precisioninno.com>
Signed-off-by: Cho Moon <cmoon@precisioninno.com>
This works better in allow various parts of the code to correctly load
files without having to introduce an ord dependency.

Signed-off-by: Matt Liberty <mliberty@precisioninno.com>
…le-swap11"

This reverts commit 28bc612, reversing
changes made to 36a8c9c.
Signed-off-by: Cho Moon <cmoon@precisioninno.com>
@precisionmoon
Copy link
Copy Markdown
Contributor

@andyfox-rushc, this is a work in progress but it'd be great if you can review. I fixed all the fatals from regression tests but am not sure if the fixes are OK. dbModule::destroy() doesn't seem to remove the module from the block somehow.

@precisionmoon precisionmoon requested a review from maliberty March 26, 2025 03:37
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

Comment thread src/odb/src/db/dbModInst.cpp Outdated
Signed-off-by: Cho Moon <cmoon@precisioninno.com>
Comment thread src/odb/src/db/dbModule.cpp Outdated
Comment thread src/odb/src/db/dbModule.cpp Outdated
Comment thread src/odb/include/odb/db.h
Comment on lines +8001 to +8003
/// Returns new mod inst if the operations succeeds.
/// Old mod inst is deleted along with its child insts.
dbModInst* swapMaster(dbModule* module);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why delete the dbModInst rather than bind it to the new master (like dbInst::swapMaster)?

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.

The intent here (I think) is to make "undo" work in journalling. Because the journalling only works on atomic database operations (eg create/delete/connect) the swapping of the master (a pointer swap) is not recorded so journalling wont allow undo.
For this reason (I believe) the dbModInst is being recreated.
Another approach is to journal a command rather than an action. For example we could have a new class of journalling called "command". This might usefully have a sub-command type eg "swap master" and then in this case swap the id of the "master" dbModule in the dbModInst.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The high level operation is just composed of atomic operations. Why can't any "pointer swap" be recorded?

@andyfox-rushc
Copy link
Copy Markdown
Contributor

On the point about dbModule::destroy. What happens is the the dbModule is removed from the table of dbModules from the block and marked as free. It can be brought back to life if the delete is undo.

Comment thread src/rsz/src/EstimateWireParasitics.cc
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.

This looks very strange. During visitConnectedPins I think we require A dbModBTerm must always have a dbModule associated with it. How can modbterm ->getParent be null ? Likewise how can modInst not have a dbModule.

Am guessing this is possibly some intermediate state, but it looks a little odd.

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.

@andyfox-rushc , yes you are correct. This happens during dbModInst::swapMaster(). The old mod inst has been deleted but there are old bterms that remain. When old iterm is disconnected (line 632) via old_irterm->disconnectDbNet() API, the fatal happens because of intermediate nature of old modbterm, old module and old modinst. assert() won't work. We need null checks.

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.

Thank you for the explanation.

Please can we agree that the legal intermediate state is the dbModule might have been swapped out so the dbModInst might have a null dbModule "master". For example when killing the dbModInst after swapping. However, please note that this api is the visitConnectedPins iterator -- ie traversing the pins on a net. Doing that on an intermediate state seems strange.

Please can we also agree that the dbModBTerms must always have a dbModule (master). Likewise the dbModITerms must always have an owning dbModInst. Disconnecting the net from the dbModITerm of dbModBTerm should not corrupt the parent relationship of the pins/ports (ie a dbModBTerm must always have a parent dbModule and likewise a dbModITerm must always have a parent dbModInst). Disconnect merely removes the the dbModITerm/dbModBTerm from the corresponding dbModNet.

I understand that this is an intermediate state issue (thank you again for the explanation and forgive me I have misunderstood). I respectfully suggest issuing an error if the dbModBTerm does not have a parent dbModule and likewise if the dbModITerm does not have a parent dbModInst.

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.

Yes, I agree that in legal state mod bterm should have module and mod iterm, mod inst. However, we don't want to issue errors during transient state. I'm not sure why disconnectDbNet() API needs visitConnectedPins.

#7 0x000055555dcb4ed4 in sta::dbNetwork::visitConnectedPins (this=0x55556197dfc0, net=0x5555638dd7c0, visitor=..., visited_nets=...) at /home/cmoon/OR/OpenROAD/src/dbSta/src/dbNetwork.cc:1787
#8 0x000055555aa081e7 in sta::Network::visitConnectedPins (this=0x55556197dfc0, net=0x5555638dd7c0, visitor=...) at /home/cmoon/OR/OpenROAD/src/sta/network/Network.cc:1330
#9 0x000055555aa091d3 in sta::Network::drivers (this=0x55556197dfc0, net=0x5555638dd7c0) at /home/cmoon/OR/OpenROAD/src/sta/network/Network.cc:1627
#10 0x000055555aa090f9 in sta::Network::drivers (this=0x55556197dfc0, pin=0x5555638bc0e0) at /home/cmoon/OR/OpenROAD/src/sta/network/Network.cc:1609
#11 0x000055555ac4c4d4 in sta::ConcreteParasitics::deleteReducedParasitics (this=0x555561898df0, pin=0x5555638bc0e0) at /home/cmoon/OR/OpenROAD/src/sta/parasitics/ConcreteParasitics.cc:907
#12 0x000055555ac4c277 in sta::ConcreteParasitics::disconnectPinBefore (this=0x555561898df0, pin=0x5555638bc0e0, network=0x55556197dfc0) at /home/cmoon/OR/OpenROAD/src/sta/parasitics/ConcreteParasitics.cc:865
#13 0x000055555ab60b6a in sta::Sta::disconnectPinBefore (this=0x5555618f7610, pin=0x5555638bc0e0) at /home/cmoon/OR/OpenROAD/src/sta/search/Sta.cc:4456
#14 0x000055555dc575f6 in sta::dbStaCbk::inDbITermPreDisconnect (this=0x555561aaf060, iterm=0x5555638bc0e0) at /home/cmoon/OR/OpenROAD/src/dbSta/src/dbSta.cc:1010
#15 0x000055555e148e7f in odb::dbITerm::disconnectDbNet (this=0x5555638bc0e0) at /home/cmoon/OR/OpenROAD/src/odb/src/db/dbITerm.cpp:597
#16 0x000055555e336ed0 in odb::dbModInst::swapMaster (this=0x5555638af448, new_module=0x5555638a6b50) at /home/cmoon/OR/OpenROAD/src/odb/src/db/dbModInst.cpp:632
#17 0x000055555dcbbac1 in sta::dbNetwork::replaceHierModule (this=0x55556197dfc0, mod_inst=0x5555638af448, module=0x5555638a6b50) at /home/cmoon/OR/OpenROAD/src/dbSta/src/dbNetwork.cc:3642

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.

That is the update timing stuff. As pins are disconnected the backend sta stuff is updated (a good thing !).

One small thought. I see when you are swapping modules you are dealing with the modnets (at the edge) and the flat nets. Recall in our model the flat nets are the physical wires in the flat world and the modnets are at the edge of each hierarchical module. Your code shows that you are handling those.

If the flat nets are not being disconnected from the module instance being deleted then it would be the case that a pin accessed by the netPinIterator would indeed not have a dbModule (same for moditerm). So I respectfully suggest checking that the flat connections are being correctly disconnected in the module being deleted.

@precisionmoon
Copy link
Copy Markdown
Contributor

On the point about dbModule::destroy. What happens is the the dbModule is removed from the table of dbModules from the block and marked as free. It can be brought back to life if the delete is undo.

My apologies... dbModule::destroy() does work as intended. My debugPrintContent was placed before destroy.

Signed-off-by: Cho Moon <cmoon@precisioninno.com>
@github-actions
Copy link
Copy Markdown
Contributor

clang-tidy review says "All clean, LGTM! 👍"

Signed-off-by: Cho Moon <cmoon@precisioninno.com>
@github-actions
Copy link
Copy Markdown
Contributor

clang-tidy review says "All clean, LGTM! 👍"

Signed-off-by: Cho Moon <cmoon@precisioninno.com>
1) clear driver pin data cache because it can get stale after netlist change like replace_hier_mod
2) updated replace_hier_mod1 to include reverse swap
3) resolved merge conflicts

Signed-off-by: Cho Moon <cmoon@precisioninno.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 1, 2025

clang-tidy review says "All clean, LGTM! 👍"

@precisionmoon
Copy link
Copy Markdown
Contributor

@andyfox-rushc @maliberty, I found the root cause of fatal in wire para estimation code EstimateWireParasitics.cc after module swap. This was due to stale net driver pin cache which stores driver pins of nets. This becomes stale after netlist change like module swap. Now I clear the cache at the beginning of each wire para estimation. This resolved the fatal, at the expense of slight increase in runtime.

Also, I modified one regression replace_hier_mod1.tcl to perform module swap, do incremental placement and legalization, and do reverse swap with another incremental place and legalization. The before and after QoR now matches up to 3 digits.

@maliberty
Copy link
Copy Markdown
Member

@precisionmoon I'll waive the DCO but please remember to sign your commits.

Comment on lines +428 to +430
// Call clearNetDrvrPinMap only without full blown ConcreteNetwork::clear()
// This is because netlist changes may invalidate cached net driver pin data
network_->Network::clear();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ok for now but should be replaced with mod objects callbacks (@andyfox-rushc )

@maliberty
Copy link
Copy Markdown
Member

In the future please be a non-functional but pervasive change like "replaced delimeter with delimiter" in a separate PR. It makes it harder to review the functional changes.

Comment thread src/dbSta/include/db_sta/dbNetwork.hh Outdated
Comment thread src/dbSta/src/dbNetwork.cc
Comment thread src/gpl/test/Testing/Temporary/CTestCostData.txt Outdated
Comment thread src/gpl/test/Testing/Temporary/LastTest.log Outdated
Comment thread src/odb/src/db/dbModInst.cpp Outdated
Comment on lines +661 to +663
msg = fmt::format(" disconnected all conns from new iterm {}",
new_iterm->getName());
debugPrint(logger, utl::ODB, "replace_design", 1, msg);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Doing this is less efficient. If the debug isn't printing then the fmt::format is never executed if you use the normal debugPrint idiom.

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.

Correct. I was trading off readability with inefficiency. Let me think of some other scheme to make it more efficient.

Don't know how this got added

Signed-off-by: Cho Moon <141182150+precisionmoon@users.noreply.github.com>
Don't know how this got added

Signed-off-by: Cho Moon <141182150+precisionmoon@users.noreply.github.com>
@precisionmoon
Copy link
Copy Markdown
Contributor

In the future please be a non-functional but pervasive change like "replaced delimeter with delimiter" in a separate PR. It makes it harder to review the functional changes.

Yes.

gadfort and others added 15 commits April 1, 2025 22:36
Signed-off-by: Peter Gadfort <peter.gadfort@gmail.com>
Signed-off-by: Peter Gadfort <peter.gadfort@gmail.com>
Signed-off-by: Cho Moon <cmoon@precisioninno.com>
Signed-off-by: Eder Monteiro <emrmonteiro@precisioninno.com>
Signed-off-by: Lucas Yuki Imamura <lucasyuki@yahoo.com.br>
Signed-off-by: Lucas Yuki Imamura <lucasyuki@yahoo.com.br>
Signed-off-by: Lucas Yuki Imamura <lucasyuki@yahoo.com.br>
Signed-off-by: Lucas Yuki Imamura <lucasyuki@yahoo.com.br>
Signed-off-by: Lucas Yuki Imamura <lucasyuki@yahoo.com.br>
Signed-off-by: Lucas Yuki Imamura <lucasyuki@yahoo.com.br>
Signed-off-by: Lucas Yuki Imamura <lucasyuki@yahoo.com.br>
Signed-off-by: Lucas Yuki Imamura <lucasyuki@yahoo.com.br>
Signed-off-by: Lucas Yuki Imamura <lucasyuki@yahoo.com.br>
Signed-off-by: Lucas Yuki Imamura <lucasyuki@yahoo.com.br>
Signed-off-by: Lucas Yuki Imamura <lucasyuki@yahoo.com.br>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 1, 2025

clang-tidy review says "All clean, LGTM! 👍"

@maliberty maliberty merged commit a88cef1 into The-OpenROAD-Project:master Apr 2, 2025
9 checks passed
@maliberty maliberty deleted the secure-module-swap11 branch April 2, 2025 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants