Repository navigation
Compare each pair of device parameter sets once in netlist compare - #2548
nikosavola wants to merge 3 commits into
Conversation
|
Hi @nikosavola , [1] If the issue is not a critical bug, maybe you can first implement the fix in your own KLayout fork. [2] You can then inform the author to drop by and take a look when he has time.
[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 you have done so in this PR, then pls forgive me for my questions (I am not very knowledgeable). HTH everyone. |
|
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. |
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>
98c3ef4 to
73fa683
Compare
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.
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.