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

Turn dynamic to static #1419

Merged
merged 45 commits into from
May 17, 2023
Merged

Turn dynamic to static #1419

merged 45 commits into from
May 17, 2023

Conversation

paili0628
Copy link
Contributor

@paili0628 paili0628 commented Apr 24, 2023

This pr modifies the infer-static-timing pass to produce static groups for all groups whose latency can be inferred.
All the changes are currently in the group-static-promotion pass. I have not put the new pass into the pipeline in order not to mess things up.

@rachitnigam
Copy link
Contributor

Don't yet have time to review but I recommend:

  1. Name it something better than infer-static-timing-new. Maybe group-static-promotion or something
  2. Create a new compilation pipeline where you run all the static passes and remove the soon-to-be-deprecated old compiler passes. Maybe the alias for the compilation pipeline can be -p static

calyx-ir/src/guard.rs Outdated Show resolved Hide resolved
calyx-ir/src/guard.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@rachitnigam rachitnigam left a comment

Choose a reason for hiding this comment

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

Seems like most of the code in the PR is the same as InferStaticTiming. Maybe the right thing to do here is to completely get rid of that pass and replace it with group promotion. We can wait for #1418 to be merged so that fewer tests break when this is merged.

@rachitnigam
Copy link
Contributor

@paili0628 let me know when this is ready for re-review

@paili0628
Copy link
Contributor Author

paili0628 commented May 5, 2023

@rachitnigam @calebmkim This pr is now ready for re-review. I've now found out that the original infer-static-timing pass does not correctly infer the static timing for components. In a newly added test case, a component that is inferred to run for 4 cycles in fact runs for 8 cycles. I think we should combine the part of control-promotion (turn a seq into a static seq if all its stmts are static) with the group-static-promotion pass and only infer the latency of a component when its control is Control::Static(_).

@calebmkim
Copy link
Contributor

calebmkim commented May 5, 2023

Alternatively, why don't we just wait until the control-promotion pass runs to infer the latency of components?
Currently, infer-static-timing does both group promotion and control promotion, but I think what we should separate those passes out.

@rachitnigam
Copy link
Contributor

I agree with @calebmkim: the two should be different passes unless @paili0628 you have a different argument to combine the two. If not, can we make it so that this pass only handles transforming groups into static groups and replacing their enables with static enables?

@@ -1,5 +1,5 @@
{
"cycles": 42,
"cycles": 100,
Copy link
Contributor

Choose a reason for hiding this comment

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

Another program where the cycle count blew up

Copy link
Contributor

@rachitnigam rachitnigam left a comment

Choose a reason for hiding this comment

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

Left some more comments! The most concerning thing here is that the cycle counts of programs is going up with this PR which is unexpected (to me)

@calebmkim
Copy link
Contributor

Ok, so after digging around a bit, there a few reasons for the cycle counts increase. I've tried to fix some of them (and some tests may fail bc the cycle count is now lower; can fix this later).
For the non-Dahlia test cases, I think these changes are enough to get better cycle counts than before.

Here are the reasons I've "fixed":

  • simplify-with-control was generating groups with a static annotation of 1, but the guards for the done signal were in the form group[done] = reg.done ? 1'd1, so static-promotion wasn't able to infer it. Obvious solution is just to generate static groups instead (since we know latency will be 1 anyways).
  • the static-promotion pass isn't detecting invoke std_reg()() (which comes from the group2invoke pass), since even though we know a std_reg static latency, it isn't considered a "static" primitive yet and therefore isn't statically invoked. The solution for now is just moving compile-invoke before static-promotion, since static-promotion can infer the latency this way. This is probably not the most ideal solution but it works to significantly decrease cycle counts compared to before.

Ones that we still need to "fix"

  • This Dahlia PR (Calyx Backend uses static groups instead of attribute cucapra/dahlia#400) still isn't merged yet. however, I've been (locally) doing some testing of cycle counts, and even after, we're still a couple cycles more than before (which is still obviously better than 2x more like before). My guess is that, once we can turn the @bound annotations into static repeats in the Dahlia->Calyx backend, that will probably help us a lot.
  • calyx-py should use static groups instead of static annotations.

@rachitnigam
Copy link
Contributor

Thanks for digging into it! I think that for this PR, we should at least ensure that the cycles counts are no worse than what they were before. Would it make sense to have @static annotation promotion pass that helps us wrap this up for now and eventually gets removed with #1429?

@calebmkim
Copy link
Contributor

calebmkim commented May 16, 2023

Yeah. I think for the time being, especially having a pass that converts @bound annotations into static repeat will help the cycle counts.

@calebmkim
Copy link
Contributor

ok, so there's one remaining test that is worse for cycle count: tests/correctness/sync/sync-dot-product-opt.futil.
Weirdly, what's making it worse is moving compile-invoke to run before static-promotion (which was the move that was helping us for other test cases). I've tried to look at the -p pre-opt futil files using the two different pass orders, and I can't figure out why moving compile-invoke is hurting the cycle count. Maybe @paili0628 would know what's going on?

@sampsyo
Copy link
Contributor

sampsyo commented May 16, 2023

Nice digging! It would be cool to understand more, but a @sync-related test case can perhaps be forgiven for behaving a little oddly…

@calebmkim
Copy link
Contributor

calebmkim commented May 16, 2023

wait I just realized the error is actually on the output value of the sync test, not the cycle count.... which is not good. I can try to look into it as well as @paili0628 if you could as well, since you wrote the sync pass. But either way, we obv need to fix this before we merge it. I'll try to work on getting a minimal failing case example.

@calebmkim
Copy link
Contributor

Ok, so after investigating the @syncfailing test stuff, I've found that manually changing the .futil file's static timing so that there is a one cycle difference makes it correct. E.g.:

static<2> group my_group {
      // contents of group 
}

is wrong,

static<3> group my_group {
      // exact same contents of group 
} 

is right.

Here are the files:
zgood.futil.txt
zbad.futil.txt
z.data.txt

running:

fud e zgood.futil -s verilog.data z.data --to dat -s futil.flags "-d static-promotion -d cell-share " --through icarus-verilog -v

gives the correct output

fud e zbad.futil -s verilog.data z.data --to dat -s futil.flags "-d static-promotion -d cell-share " --through icarus-verilog -v

gives the incorrect output.

(And again, the only difference in the two files is the static<3> annotation on the group).
@paili0628 any ideas on what could be going on?

@paili0628
Copy link
Contributor Author

So I think sync-dot-product-opt.futil is currently broken because of a bug in the original code. The new StaticControl changed the program's timing behavior, thereby exposing the bug. This probably deserves its own pr because I have now dedicated substantial time into fixing this without success. So let's skip this test for this pr and I will fix it in a subsequent pr.

@rachitnigam
Copy link
Contributor

Ah, thanks for digging into it! I agree with @paili0628 that we should disable this test for now (by renaming the corresponding .expect file to .skip) and merge this

@paili0628
Copy link
Contributor Author

Alright I'm gonna merge this for now. Thanks everyone!

@paili0628 paili0628 merged commit 86c6762 into master May 17, 2023
@paili0628 paili0628 deleted the turn-dynamic-to-static branch May 17, 2023 14:32
@rachitnigam
Copy link
Contributor

Great! Please close related issues that have been addressed by this PR

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.

4 participants