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

Reduce CDE lookups for IOBinders #1720

Merged
merged 1 commit into from
Dec 30, 2023
Merged

Conversation

tymcauley
Copy link
Contributor

@tymcauley tymcauley commented Dec 30, 2023

I recently noticed a performance degradation when emitting FIRRTL for a private SoC project, and tracked the issue down to this bit of IOBinders code. If you add a println statement to the IOBinder class, like this:

diff --git a/generators/chipyard/src/main/scala/iobinders/IOBinders.scala b/generators/chipyard/src/main/scala/iobinders/IOBinders.scala
index 45f72641..f67e7bf3 100644
--- a/generators/chipyard/src/main/scala/iobinders/IOBinders.scala
+++ b/generators/chipyard/src/main/scala/iobinders/IOBinders.scala
@@ -116,7 +116,10 @@ object GetSystemParameters {
 }

 class IOBinder[T](composer: Seq[IOBinderFunction] => Seq[IOBinderFunction])(implicit tag: ClassTag[T]) extends Config((site, here, up) => {
-  case IOBinders => up(IOBinders, site) + (tag.runtimeClass.toString -> composer(up(IOBinders, site)(tag.runtimeClass.toString)))
+  case IOBinders => {
+    println(s"Checking IOBinder ${tag.runtimeClass.toString}")
+    up(IOBinders, site) + (tag.runtimeClass.toString -> composer(up(IOBinders, site)(tag.runtimeClass.toString)))
+  }
 })

 class ConcreteIOBinder[T](composes: Boolean, fn: T => IOBinderTuple)(implicit tag: ClassTag[T]) extends IOBinder[T](

... and then build RocketConfig with:

make -C sims/vcs firrtl

Then you will see 524287 instances of that println message, with many duplicate checks of the same IOBinder classes. Seems that the extra CDE lookup call to up is causing a lot of issues. If you just make a single call to up, as in this PR, you'll only see 19 instances of that println message.

This performance hiccup isn't that noticeable for Rocket, but for my project, it's the difference between the make firrtl step taking 1 minute vs 8 minutes. I'm not adding that many extra IOBinders (maybe about 10), but there seems to be some greater-than-linear blowup in the CDE lookups with the two calls to up.

Related PRs / Issues:

Type of change:

  • Bug fix
  • New feature
  • Other enhancement

Impact:

  • RTL change
  • Software change (RISC-V software)
  • Build system change
  • Other

Contributor Checklist:

  • Did you set main as the base branch?
  • Is this PR's title suitable for inclusion in the changelog and have you added a changelog:<topic> label?
  • Did you state the type-of-change/impact?
  • Did you delete any extraneous prints/debugging code?
  • Did you mark the PR with a changelog: label?
  • (If applicable) Did you update the conda .conda-lock.yml file if you updated the conda requirements file?
  • (If applicable) Did you add documentation for the feature?
  • (If applicable) Did you add a test demonstrating the PR?
  • (If applicable) Did you mark the PR as Please Backport?

@tymcauley
Copy link
Contributor Author

Thinking about this a bit more, the speedup makes sense. Each call to up(IOBinders) is effectively a recursive call, and two recursive calls for each execution of the function leads to 2^n complexity.

Copy link
Contributor

@jerryz123 jerryz123 left a comment

Choose a reason for hiding this comment

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

Thanks for investigating this!

@jerryz123 jerryz123 merged commit 4c245ff into ucb-bar:main Dec 30, 2023
50 of 52 checks passed
@tymcauley tymcauley deleted the faster-iobinders branch December 30, 2023 18:15
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