Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address some &mfs crashes #30

Merged
merged 4 commits into from
Apr 11, 2024

Conversation

povik
Copy link
Member

@povik povik commented Mar 22, 2024

Yosys calls &mfs as part of the default abc9 flow but every time it does it's prepared for the worst, and is ready to recover when the command crashes (see YosysHQ/yosys#1974). In this PR we try to make it crash less, see the individual commits for details.

The former implementation of `Sfm_NtkDfs` was trying to serialize the
network while ordering all box inputs ahead of the box outputs. This is
sometimes impossible, leaving the result unordered, which led to crashes
in the `&mfs` code when it was reintegrating the result into the GIA
structure:

  ABC: Assertion failed: iLitNew >= 0 (src/aig/gia/giaMfs.c: Gia_ManInsertMfs: 388)

With a small change to `Gia_ManInsertMfs` which does the reintegration
we don't really need the ordering to see through boxes, ordering on the
paths between boxes is sufficient. Relaxing the ordering requirement, we
make `Sfm_NtkDfs` robust.
When the network is being handed over to the "sfm" core, all blackboxes
are modeled by inserting new PIs, POs, and those being connected by
buffers to the nodes representing the CIs, COs. Make two changes:

 * Robustly deny the fake PIs from being considered when shopping for
   LUT fanin substitutions. Such reconnection occurring would trip up
   the code reintegrating the result.

 * Make sure the buffer connecting the fake-PO to the CO doesn't get
   rewritten as part of the `mfs` transformation, and extend this
   protection to any whitebox models.
Copy link

@Ravenslofty Ravenslofty left a comment

Choose a reason for hiding this comment

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

Tiny nitpick, but thanks to @yrabbit generously testing this on the Project Apicula test suite, I am reasonably confident this doesn't break code in the wild, and even helps in some cases.

src/aig/gia/giaMfs.c Show resolved Hide resolved
@nakengelhardt nakengelhardt merged commit ccc02c4 into YosysHQ:yosys-experimental Apr 11, 2024
@povik povik mentioned this pull request Apr 22, 2024
@QuantamHD
Copy link

Should this be upstreamed to abc?

@povik
Copy link
Member Author

povik commented Apr 22, 2024

@QuantamHD Yes, but because of discouraging stories about how others tried to upstream ABC fixes, and because &mfs -b would need extra handling in this fix, I haven't opened a PR so far.

@@ -170,14 +171,33 @@ Vec_Int_t * Sfm_NtkDfs( Sfm_Ntk_t * p, Vec_Wec_t * vGroups, Vec_Int_t * vGroupMa
Vec_IntClear( vBoxesLeft );
vNodes = Vec_IntAlloc( p->nObjs );
Sfm_NtkIncrementTravId( p );
if ( fAllBoxes )

assert(!fAllBoxes); // TODO
Copy link
Member Author

Choose a reason for hiding this comment

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

See here; this assertion fails for &mfs -b

@QuantamHD
Copy link

@QuantamHD Yes, but because of discouraging stories about how others tried to upstream ABC fixes, and because &mfs -b would need extra handling in this fix, I haven't opened a PR so far.

We have a good relationship with Alan. I think it's worth opening a PR if you can, and I can signal boost it with him.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants