gia: skip the mapped network when only the CNF is wanted - #11
Open
TrevorHansen wants to merge 1 commit into
Open
gia: skip the mapped network when only the CNF is wanted#11TrevorHansen wants to merge 1 commit into
TrevorHansen wants to merge 1 commit into
Conversation
Mf_ManGenerateCnf() asks Mf_ManPerformMapping() for a mapping and then throws the network away, keeping only the Cnf_Dat_t hung off the original manager. Building that network is not free: Mf_ManDeriveMappingGia() walks every node in the mapping and runs each chosen cut's truth table through Kit_TruthToGia(), filling a second Gia manager that nothing ever reads. The CNF does not come from that network. Mf_ManDeriveCnf() and Mf_ManDeriveCnfs() read the map references, each node's best cut, the truth-table memory and the per-function clause counts, all of which cut computation has already produced. Add fCnfOnly to Jf_Par_t. With it set, Mf_ManPerformMapping() skips the derivation and returns no network, and the two places that would then dereference a null pointer are guarded: Gia_ManMappingVerify(), and the memory line in Mf_ManPrintQuit(), which reads pNew->vMapping ahead of its own fVerbose early return. Mf_ManGenerateCnf() sets the flag, so every caller that wants only a CNF stops paying for the network. The flag defaults to zero, which every Jf_Par_t user already gets from the memset in its *_ManSetDefaultPars(), so &mf and the other mappers sharing the structure are unchanged. Every in-tree caller of Mf_ManGenerateCnf() discards the manager it returns, which that function frees before returning, so none of them can observe the difference. Measured through a bit-vector solver that reaches this path for every query. On a bit-blasted circuit of about 12M gates, deriving the mapped network was around 14% of the time spent inside Mf_ManGenerateCnf(). Over three large queries, whole-run retired instructions fall by 8.9% to 15.0% at LUT size 6 and by 12.9% to 27.5% at LUT size 3, and peak resident memory on the largest drops from 2.50 GB to 1.96 GB. The CNF is byte-identical: 51 queries at each of four generator settings, 204 comparisons, no difference.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Mf_ManGenerateCnf()asksMf_ManPerformMapping()for a mapping and then throws the network away —Gia_ManStopP(&pNew)on the next line — keeping only theCnf_Dat_thung off the original manager. Building that network is not free:Mf_ManDeriveMappingGia()walks every node in the mapping and runs each chosen cut's truth table throughKit_TruthToGia(), filling a second Gia manager that nothing ever reads.The CNF does not come from that network.
Mf_ManDeriveCnf()andMf_ManDeriveCnfs()read the map references, each node's best cut, the truth-table memory and the per-function clause counts — all of which cut computation has already produced.The change
A new
fCnfOnlyfield onJf_Par_t. With it set,Mf_ManPerformMapping()skips the derivation and returns no network. Two places would then dereference a null pointer and are guarded:Gia_ManMappingVerify(pNew), which asserts the network has a mapping;Mf_ManPrintQuit(), which readspNew->vMappingbefore its ownfVerboseearly return, so it faults even in a quiet run. It now reports 0 MB when there is no network, which is what was built.Mf_ManGenerateCnf()sets the flag, so every caller that wants only a CNF stops paying for the network.Why this is safe for the rest of the tree
Mf_ManPerformMapping()has two callers:Mf_ManGenerateCnf(), and&mfinabc.c. The latter initialises its parameters withMf_ManSetDefaultPars(), which memsets the structure, so it getsfCnfOnly == 0and behaves exactly as before.Jf_Par_tis shared with the Jf, Lf, Of, Pf, Nf and Kf mappers. Every one of them initialises through a*_ManSetDefaultPars()that memsets the whole structure, and none of them reads the new field. Adding it changes nothing for them.Mf_ManGenerateCnf()— around forty-five sites acrossbmc,cec,pdr,glucose,acband thegiafiles — takes theCnf_Dat_tand discards the manager, whichMf_ManGenerateCnf()frees before returning. None of them can observe the missing network.Measurements
Measured through a bit-vector solver that reaches
Mf_ManGenerateCnf()for every query it solves. Profiling a bit-blasted circuit of about 12M gates put roughly 14% of the time insideMf_ManGenerateCnf()inMf_ManDeriveMappingGia().Whole-run retired instructions on three large bit-vector queries, stopping the solver right after CNF generation, median of three runs:
The share is larger at LUT size 3 because the CNF derivation itself is cheaper there, so the discarded network is a bigger fraction of the whole.
Peak resident memory on the 512-bit query at LUT 6 falls from 2.50 GB to 1.96 GB, since the second Gia manager is never allocated.
CNF equivalence
51 queries drawn across a corpus of large bit-vector benchmarks, at each of four CNF-generation settings (two LUT sizes over two front ends), comparing the generated CNF byte for byte against the same solver built on unpatched ABC: 204 comparisons, 204 identical, none mismatched, none skipped.