-
Notifications
You must be signed in to change notification settings - Fork 613
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
Avoid making unnecessary clones during binding #2611
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b2bf039
Avoid making unnecessary clones during binding
zyedidia c1255c5
Use lazy val for memoization
zyedidia 403e52d
Fix use of lazy val
zyedidia 41930f4
Make hasExternalRef private[chisel3]
zyedidia b3426fc
Add two more tests
zyedidia d66105e
Fix LazyCloneSpec interaction with other tests
zyedidia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,32 @@ | ||||||||
// SPDX-License-Identifier: Apache-2.0 | ||||||||
|
||||||||
package chiselTests | ||||||||
|
||||||||
import chisel3._ | ||||||||
import chisel3.stage.ChiselStage | ||||||||
import chiselTests.ChiselFlatSpec | ||||||||
|
||||||||
class LazyCloneSpec extends ChiselFlatSpec { | ||||||||
behavior.of("LazyClone") | ||||||||
|
||||||||
it should "lazily clone" in { | ||||||||
object Foo { | ||||||||
var count = 0L | ||||||||
} | ||||||||
|
||||||||
class Foo extends Bundle { | ||||||||
val a = UInt(8.W) | ||||||||
Foo.count += 1 | ||||||||
} | ||||||||
|
||||||||
class MyModule extends RawModule { | ||||||||
val io = IO(Flipped(new Bundle { | ||||||||
val foo = Output(new Foo) | ||||||||
val bar = Input(new Foo) | ||||||||
})) | ||||||||
} | ||||||||
ChiselStage.elaborate(new MyModule) | ||||||||
println(s"copies: ${Foo.count}") | ||||||||
Foo.count should be < 12L | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Also, it would be good to have a test that sharing a single class MyModule extends RawModule {
val foo = new Foo
val io = IO(Flipped(new Bundle {
val foo = Output(foo)
val bar = Input(foo)
}))
}
// This should have 3 Foos constructed object Bar {
var count = 0L
}
class Bar(x: UInt) extends Bundle {
val a = x
Bar += 1
}
class MyModule extends RawModule {
val io = IO(Flipped(new Bundle {
val foo = Output(new Bar(UInt(8.W)))
val bar = Input(new Bar(UInt(8.W)))
}))
}
// This should have 4 Bars constructed Also a test that shows an extra clone when you pass a |
||||||||
} | ||||||||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Scala actually has a built-in for this sort of thing 🙂 This should also use less memory because it only adds a 1 byte field (and uses 1 extra bit in the lazy val mask that already exists because we have other lazy vals in Bundles). Your approach adds a 4-byte field pointing to a 24-40 byte object. This might actually suggest rerunning the memory use check because 28-bytes per Bundle is non-trivial.