Skip to content

Compare each pair of device parameter sets once in netlist compare - #2548

Open
nikosavola wants to merge 3 commits into
KLayout:masterfrom
nikosavola:pr/netcmp-param-sets
Open

nikosavola wants to merge 3 commits into
KLayout:masterfrom
nikosavola:pr/netcmp-param-sets

Conversation

@nikosavola

@nikosavola nikosavola commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

In large LVS runs most of the netlist compare time goes into comparing device parameters. Each time the graph sorts or matches two device transitions, it calls the compare delegate again. On the vexriscv LVS test that is about 250 million calls for only about 160 different parameter sets.

Devices of one class with the same values for the parameters the delegate looks at now share a signature. The delegate runs once per pair of signatures, through the three-way compare on DeviceCompare that Matthias suggested in #2467, and later compares look the result up. A compare through the delegate looks up the device class and its delegate, then runs the tolerance check on every primary parameter, and it does this in both directions to tell less from equal. Equal devices are the slowest case because no parameter ends the loop early, and with only 160 parameter sets the sorts compare many of them. With a tolerance set, each call also builds a std::set. Two devices with the same signature are now equal after one pointer check, and any other pair reads one byte from the table. On vexriscv that saves about 33 ns per call.

1 thread, Xeon Gold 6230 master three-way compare only this PR
vexriscv LVS, netlist compare 11.9 s 11.9 s 3.7 s
vexriscv LVS, whole run 31.7 s 32.0 s 23.7 s
vexriscv LVS, peak memory 437 MB 437 MB 449 MB
20k MOS4 chain, 8 W/L sets 1.63 s 1.60 s 0.40 s
same, 1% tolerance on W and L 3.81 s 3.74 s 0.41 s
same W/L, AS/AD/PS/PD differ per device 1.63 s 1.60 s 0.40 s
W differs per device 0.75 s 0.61 s 0.65 s

These are medians of six rounds on one core of an exclusive node, with the build order changed every round, and all rounds agreed within 4%. With 4 or 8 threads the vexriscv numbers are within 2% of these. The netlist result is the same.

Signatures are never merged by tolerance, because the tolerance compare is not transitive. There are some downsides. Only the built-in compare delegates use signatures, so a custom delegate gets no gain, and a new built-in delegate has to be added to the list. The cached result is only valid if all devices of a category are compared through the same primary class, so if a category mixes primary classes, only the first one gets signatures. The table stops growing at 1024 signatures, and devices past that are compared as before. Peak memory grows by about 12 MB on vexriscv, most likely from the map that keeps the signature of each device during the graph build. To keep the transition at 32 bytes, its category and IDs are now 32-bit values. The table is filled while the graphs are sorted, so it is not safe for the parallel sorts on the parallelize branch yet.

Matthias, let me know what you think. The speedup is large, but so is the added code, and I am happy to cut it back. If it is too much, the first two commits also work without the cache.

This PR was developed with AI assistance from the open-weight DeepSeek V4.1 Flash 1017 model, including the implementation and checks.

@chkkbim

chkkbim commented Nov 12, 2026

Copy link
Copy Markdown

Hi @nikosavola ,

[1] If the issue is not a critical bug, maybe you can first implement the fix in your own KLayout fork.
So that your work is not held up.

[2] You can then inform the author to drop by and take a look when he has time.
In your heads-up, you can provide an executive summary of 5 short sentences addressing the following points :

  • how severe is the problem ? etc nuisance / major / critical / PC crash / universe will implode
  • does the problem occur with "vanilla" / "OOTB" KLayout installation ?
  • problem description
  • solution description

[3] If I am not wrong, the author takes a deep craftsman approach to the code, rather than making KLayout the "best" layout software (for "everyone"). So he is very thoughtful about the code architecture (current & future) etc.

[4] Going forward, can you also indicate :

  • if AI was involved in generating the proposed code (including checks), in any way ?
  • if so, where and how ?

If you have done so in this PR, then pls forgive me for my questions (I am not very knowledgeable).

HTH everyone.

@nikosavola

Copy link
Copy Markdown
Contributor Author

Thanks for the suggestions. This is an optional speedup for large LVS runs in standard KLayout, so there's no urgency. It caches repeated device parameter comparisons at the cost of some memory and added complexity. I used AI for the implementation and checks and should have mentioned that in the description.

nikosavola and others added 3 commits November 12, 2026 15:53
The tests pin down the order and equality of device transitions and graph nodes, with the default delegate, a custom one and explicit parameters, plus tolerance cases on a resistor star.

Co-Authored-By: DeepSeek V4.1 Flash 1017 <noreply@deepseek.com>
DeviceClass::compare finds the compare delegate once and asks it at most twice. A device compared with itself is equal without asking.

Co-Authored-By: DeepSeek V4.1 Flash 1017 <noreply@deepseek.com>
Devices of one class with the same values for the parameters the delegate looks at share a signature, and the compare delegate runs once per pair of signatures. This is only done for the built-in compare delegates. Others still compare the devices. The transition stays at 32 bytes by storing its IDs as 32-bit values.

Co-Authored-By: DeepSeek V4.1 Flash 1017 <noreply@deepseek.com>
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.

2 participants