Skip to content
This repository has been archived by the owner on Aug 20, 2024. It is now read-only.

Speed up InferTypes and CInferTypes #1601

Merged
merged 2 commits into from
May 14, 2020
Merged

Speed up InferTypes and CInferTypes #1601

merged 2 commits into from
May 14, 2020

Conversation

jackkoenig
Copy link
Contributor

@jackkoenig jackkoenig commented May 13, 2020

A couple of minor improvements to performance of InferTypes and CInferTypes.

I've marked this for backporting but I did the deprecation warnings assuming it won't be included in the 1.3.1 release tomorrow.

The reason the traversal was redundant in DefNode was that it already mapped on its expression to get the type of the node itself. Due to declaration before use requirements, the node itself cannot be used in it's RHS.

Benchmarks results

In a normal compilation of FIRRTL, InferTypes is run 6 times and CInferTypes is run once.

Full compiler run

Design Before Runtime (s) After Runtime (s) Speedup
small 47.10 ± 0.75 45.23 ± 0.33 4 %
medium 117.8 ± 0.45 108.35 ± 2.5 8 %
large 384.9 ± 30.7 380.64 ± 8.0 uncertainty too high

JMH Results of LowerTypes

Design Before (ms) After (ms) Speedup
small 283 ± 9.1 178 ± 12.8 37 %
medium 698 ± 82.5 506 ± 23.6 28 %
large 1715 ± 250 1290 ± 109 25%

Contributor Checklist

  • Did you add Scaladoc to every public function/method?
  • Did you update the FIRRTL spec to include every new feature/behavior?
  • Did you add at least one test demonstrating the PR?
  • Did you delete any extraneous printlns/debugging code?
  • Did you specify the type of improvement?
  • Did you state the API impact?
  • Did you specify the code generation impact?
  • Did you request a desired merge strategy?
  • Did you add text to be included in the Release Notes for this change?

Type of Improvement

  • performance improvement

API Impact

Deprecates type aliases in InferTypes and CInferTypes

Backend Code Generation Impact

None

Desired Merge Strategy

  • Rebase: You will rebase the PR onto master and it will be merged with a merge commit.

Release Notes

Improve performance of InferTypes and CInferTypes

Reviewer Checklist (only modified by reviewer)

  • Did you add the appropriate labels?
  • Did you mark the proper milestone (1.2.x, 1.3.0, 1.4.0) ?
  • Did you review?
  • Did you check whether all relevant Contributor checkboxes have been checked?
  • Did you mark as Please Merge?

@jackkoenig jackkoenig added this to the 1.3.x milestone May 13, 2020
@jackkoenig jackkoenig requested a review from a team as a code owner May 13, 2020 05:41
@albert-magyar
Copy link
Contributor

A couple of minor improvements to performance of InferTypes and CInferTypes.

I've marked this for backporting but I did the deprecation warnings assuming it won't be included in the 1.3.1 release tomorrow.

The reason the traversal was redundant in DefNode was that it already mapped on its expression to get the type of the node itself. Due to declaration before use requirements, the node itself cannot be used in it's RHS.

Makes sense, and several transforms will error or fail to terminate if they are run on a circuit violating this constraint, so CheckHighForm is already a true, hard requirement.

Copy link
Contributor

@albert-magyar albert-magyar left a comment

Choose a reason for hiding this comment

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

LGTM. One small question: why 'N'TypeMap?

type TypeMap = collection.mutable.LinkedHashMap[String, Type]

private type NTypeMap = collection.mutable.HashMap[String, Type]
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the 'N'? This holds the types for all declared components, not just nodes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

N was for "new", should I rename it to make it more clear?

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess? I guess it doesn't really matter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll make it `New, it's 2 whole more characters and if it confused you now it'll confuse people later (myself included lol)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I renamed it to TypeLookup

src/main/scala/firrtl/passes/InferTypes.scala Show resolved Hide resolved
@jackkoenig
Copy link
Contributor Author

@albert-magyar should I backport this to 1.2.x or leave it 1.3.x?

@albert-magyar albert-magyar modified the milestones: 1.3.x, 1.2.X May 13, 2020
@albert-magyar
Copy link
Contributor

I think 1.2.x. Both changes are just really simple and solid.

@jackkoenig jackkoenig force-pushed the speed-up-infer-types branch 2 times, most recently from 4647e4c to 7ad1549 Compare May 13, 2020 22:01
@jackkoenig jackkoenig force-pushed the speed-up-infer-types branch from 7ad1549 to 26693f7 Compare May 14, 2020 00:56
@jackkoenig jackkoenig merged commit f4e4ee0 into master May 14, 2020
@mergify mergify bot added the Backported This PR has been backported to marked stable branch label May 14, 2020
mergify bot added a commit that referenced this pull request May 14, 2020
* Use HashMap instead of LinkedHashMap in InferTypes

Do the same in CInferTypes

(cherry picked from commit a15f65c)

* Remove a redundant Expression traversal in InferTypes

(cherry picked from commit 26693f7)

Co-authored-by: Jack Koenig <koenig@sifive.com>
seldridge pushed a commit that referenced this pull request Jun 3, 2020
* Use HashMap instead of LinkedHashMap in InferTypes
* Remove a redundant Expression traversal in InferTypes
* fixup! Use HashMap instead of LinkedHashMap in InferTypes
@jackkoenig jackkoenig deleted the speed-up-infer-types branch September 16, 2020 17:34
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Backported This PR has been backported to marked stable branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants