8000 Improve Static Inline by calebmkim · Pull Request #1734 · calyxir/calyx · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Improve Static Inline #1734

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

Merged
merged 2 commits into from
Oct 10, 2023
Merged

Improve Static Inline #1734

merged 2 commits into from
Oct 10, 2023

Conversation

calebmkim
Copy link
Contributor

When looking into systolic array resource usage, I realized that inlining:

static if port {
  // one cycle body
} 

Was generating a register to hold port's value. If it is more than one cycle, we need this register, in case port changes during execution of the body. But we shouldn't generate this register if the body is one cycle, since we don't need this. This was generating a ton of unnecesary registers in the systolic array.

@rachitnigam
Copy link
Contributor

Awesome! Can you give the intuition behind the new transformation? Is it simply that you generate a group that inlines the assignments and adds a guard in front of the assignments?

@calebmkim
Copy link
Contributor Author
calebmkim commented Oct 9, 2023

Suppose we have:

static if cond_port {
  // tbranch 
} 
else {
  // optional fbranch 
} 

Before

Before, we had some logic

// write cond_port to cond_reg in the first cycle 
cond_reg.write_en = %0 ? 1'd1 
cond_reg.in = %0 ? cond_port 
// cond_wire looks directly at port during the first cycle, but to cond_reg after that in case cond_port changes during execution of the while group 
cond.wire.in = %0 ? cond_port : cond_reg 
// tbranch assigns guarded by cond_wire
// fbranch assigns guarded by !cond_wire

After

None of this cond_reg or cond_wire stuff is necessary (so we don't need this register).

// tbranch assigns guarded by cond_port
// fbranch assings guarded by !cond_port

Another (small) thing, separate from the if statement stuff

I also decided to do another small thing:
If you are inlining, for example, a

static par {
  A; // takes 5 cycles 
  B; // takes 5 cycles 
  C; // takes 5 cycles 
} 

The inlining would generate a group with %[0:5] in front of it. These guards are unnecessary. I changed the pass to not include them in this case. That's what this line is doing.

@rachitnigam
Copy link
Contributor

Awesome, this all sounds reasonable to me!

@calebmkim calebmkim merged commit 746f6a8 into master Oct 10, 2023
@calebmkim calebmkim deleted the improve-static-inline branch October 10, 2023 00:17
rachitnigam pushed a commit that referenced this pull request Feb 16, 2024
* improved static inline

* clippy
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
0