Skip to content

Conversation

sequencer
Copy link
Member

@sequencer sequencer commented Jul 22, 2024

This PR adds Property support for SRAMInterface, instantiating the SRAMOM when using SRAMInterface. In our flow this is intend to replace the repl-sram and provide a unified Verilog for both synthesis tool and simulation tools.

Contributor Checklist

  • Did you add Scaladoc to every public function/method?
  • 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 add appropriate documentation in docs/src?
  • Did you request a desired merge strategy?
  • Did you add text to be included in the Release Notes for this change?

Type of Improvement

  • Feature (or new API)

Desired Merge Strategy

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

Release Notes

add property to SRAMInterface

Reviewer Checklist (only modified by reviewer)

  • Did you add the appropriate labels? (Select the most appropriate one based on the "Type of Improvement")
  • Did you mark the proper milestone (Bug fix: 3.6.x, 5.x, or 6.x depending on impact, API modification or big change: 7.0)?
  • Did you review?
  • Did you check whether all relevant Contributor checkboxes have been checked?
  • Did you do one of the following when ready to merge:
    • Squash: You/ the contributor Enable auto-merge (squash), clean up the commit message, and label with Please Merge.
    • Merge: Ensure that contributor has cleaned up their commit history, then merge with Create a merge commit.

@sequencer sequencer force-pushed the sram-interface-om branch 2 times, most recently from 3878620 to 1a7e329 Compare August 13, 2024 06:25
@sequencer sequencer added the Feature New feature, will be included in release notes label Aug 13, 2024
@sequencer sequencer force-pushed the sram-interface-om branch 4 times, most recently from f6fa892 to 2fb0879 Compare August 13, 2024 08:16
@sequencer sequencer force-pushed the sram-interface-om branch 2 times, most recently from 2fb0879 to cf9833c Compare August 20, 2024 04:59
Copy link
Contributor

@mikeurbach mikeurbach left a comment

Choose a reason for hiding this comment

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

I took a look through this, and I don't have any major concerns with the implementation.

This is opening an interesting door though...now that Chisel can support such information, what APIs merit having Objects built in within Chisel? Should this always be added in SRAM, or maybe there is a subclass or some other class that users can pick if they want the description.

I'm also keenly aware that CIRCT produces this information as it compiles memories. We have actually recently added support for this same information to be added automatically within CIRCT and bubbled up to the compilation unit's top level for all SRAMS. So there are a couple things to think about:

  • This shouldn't conflict with that, but it would be good to confirm
  • This could potentially replace the CIRCT pass adding the information

The last point it a worthy goal, but the CIRCT pass has some...peculiar requirements. And due to Hyrum's Law, those have now become entrenched. To fully replace the existing CIRCT pass that's already adding basically this information, we'd need to work out all the weird uses downstream. Specifically, there is a behavior in CIRCT that the hierarchy field is the hierarchical path before any SRAM extraction has happened, whereas if this is implemented in Chisel, it will always point to the final hierarchical path of the SRAM. That's arguably the right thing, but I know of downstream users who depend on the previous, non-intuitive behavior.

@sequencer sequencer force-pushed the sram-interface-om branch 4 times, most recently from a64f9df to 53359cb Compare August 21, 2024 08:16
@sequencer
Copy link
Member Author

This is opening an interesting door though...now that Chisel can support such information, what APIs merit having Objects built in within Chisel? Should this always be added in SRAM, or maybe there is a subclass or some other class that users can pick if they want the description.

In my team, I was proposing:

  • for each module, they should be serializable module and put all parameters and main class to Property, so we are planing provide each module the Serializable OM description;
  • power information: register that need to be associated with Path, it will be collected and generate the upf;
  • IP integration: interface and memory region definition that required by IP-XACT;

To fully replace the existing CIRCT pass that's already adding basically this information, we'd need to work out all the weird uses downstream. Specifically, there is a behavior in CIRCT that the hierarchy field is the hierarchical path before any SRAM extraction has happened, whereas if this is implemented in Chisel, it will always point to the final hierarchical path of the SRAM. That's arguably the right thing, but I know of downstream users who depend on the previous, non-intuitive behavior.

I do agree we should replace the CreateSiFiveMetadata pass, and because the name, I believe SiFive is the only downstream to that pass. So maybe migration should be simple?

@sequencer sequencer changed the title Add om support to SRAMInterface-based SRAM Add property support to SRAMInterface-based SRAM Aug 21, 2024
@sequencer
Copy link
Member Author

cc @debs-sifive and @jackkoenig, I reverted #4364 in a8cdaf4: since I think exposing the underlying API to users is not a good idea, and may introduce some inconvenience for future API change. I added 09254b9 instead with a private API and only used by the OM feature. For any users need the SRAM path, they can always retrieve the the Path via OM API in CIRCT.
WDYT?

@debs-sifive
Copy link
Contributor

@sequencer thanks for looking at this — I think your approach is definitely safer and more user-friendly than using underlying! There's some discussion on our end about being able to see hierarchy, which is the field I need. I'm copy-pasting @albertchen-sifive

could we make SRAMDescription a bundle with just property fields instead of an Class? I don’t think we have anyway of doing a field lookup like Property[SRAMDescription].hierarchy for properties? but if SRAMDescription was a Bundle and we had val description: SRAMDescription in SRAMInterface then we could do sram.description.hierarchy

@sequencer
Copy link
Member Author

could we make SRAMDescription a bundle with just property fields instead of an Class? I don’t think we have anyway of doing a field lookup like Property[SRAMDescription].hierarchy for properties? but if SRAMDescription was a Bundle and we had val description: SRAMDescription in SRAMInterface then we could do sram.description.hierarchy

If we are construction another standalone OM, e.g. SomeCoreL1DCacheDescription: Class, and only need a Path, it does makes sense. I think this flow can only add Path to SomeCoreL1DCacheDescription.hierarchy field, and append other fields, and do post-process, this reasonable. My question is what's the difference of using hierarchy: Property[Path] or SRAMDescription: Class? Since they are always used in the CIRCT side.

My concern is: a Class is a property for the whole SRAM metadata, and we only use the description after firtool compiling mlirbc. And I personally hope using this metadata to replace whole repl-sram pass and the metadata folder from circt output for better SRAM replacing experience.
Basically Path or Class are both OK in the flow designing, and for a standard ABI, I personally prefer using Class for SRAM, any other downstream user can always use the SRAMDescription to do the SRAM replacement flow. e.g. add their own pass find and match the Class.

@jackkoenig
Copy link
Contributor

My question is what's the difference of using hierarchy: Property[Path] or SRAMDescription: Class? Since they are always used in the CIRCT side.

The problem is that there is currently no way in Chisel to access the fields of the Property[SRAMDescription]. I think this is an issue with our current Property API, not with this PR per se, but we need the specific Property[Path] from SRAMDescription in the short term. I'm going to open a PR with a test that shows the lacking API in Property[_ <: Class] to show what I mean and then we can tackle it.

Basically Path or Class are both OK in the flow designing, and for a standard ABI, I personally prefer using Class for SRAM,

It's not Class vs. Path, it's Class vs. Bundle of the same properties that the Class had since it is possible to access fields of a Bundle. I do agree that Class is better though and maybe we can just make that work, see my coming PR showing what I mean.

Comment on lines 169 to 171
private val descriptionDefinition: Definition[SRAMDescription] = Instantiate.definition(new SRAMDescription)
private val descriptionType: ClassType = descriptionDefinition.getClassType
val description: Property[ClassType] = Property[descriptionType.Type]()
Copy link
Contributor

Choose a reason for hiding this comment

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

The Definition should not be a field of the Bundle, it should possibly be a field of the companion object (if we're saying there's only 1 definition for all SRAMDescriptions), or possibly an argument to the constructor. I'm thinking maybe we should go with argument to constructor because I suspect users are going to want to optionally add their own metadata to SRAMs which implies there may not be a single definition for all of them.

One thing to note is this is a very backwards incompatible change, anyone using

We also want the description to be typed, Property[SRAMDescription], otherwise this is weird and erased and not useful as a Chisel API (e.g. our use case of accessing the hierarchy field from it).

Copy link
Member Author

Choose a reason for hiding this comment

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

it should possibly be a field of the companion object

Sounds good, I will do it later. For user adding their own metadata, Explicitly instantiating the SRAMDescription and connect sounds dangerous, I think we should consider what to add and how to add. e.g. SRAM description string, Initial ROM, UPF fields, etc.

accessing the hierarchy field from it

yes if you need to access the hierarchy field, we need add new API to Class to extract it.

Comment on lines 87 to 88
@instantiable
private[chisel3] class SRAMDescription extends Class {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
@instantiable
private[chisel3] class SRAMDescription extends Class {
@instantiable
final class SRAMDescription extends Class {

This should be public and should be used in the type of the description property in the SRAMInterface.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, if you are going to use hierarchy: Property[Path] in Chisel, this should be public, but if not, private it will be better.

Copy link
Contributor

Choose a reason for hiding this comment

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

If we are telling people to use it via CIRCT API (as the ScalaDoc suggests, ScalaDoc that will not be published if it's private by the way), then this is a public API and should be public.

@jackkoenig jackkoenig added API Modification and removed Feature New feature, will be included in release notes labels Aug 27, 2024
@jackkoenig
Copy link
Contributor

Marked API Modification because this will break any use of SRAMInterface where the user instantiates it themselves rather than via the SRAM factory methods. They will have to hook up the new description field.

@sequencer
Copy link
Member Author

The problem is that there is currently no way in Chisel to access the fields of the Property[SRAMDescription].

Yes, That's a problem, in our side, we just throw the entire Property to another Property rather than filter out some internal property LOL, the output Top OM might be verbosity though...

@jackkoenig
Copy link
Contributor

I pushed a commit showing what I want to see, I thought we could get by with .getField but that doesn't seem to be defined on Property[ClassType] which seems like an oversight. I think if the test I pushed can pass, we're in good shape.

@sequencer
Copy link
Member Author

I pushed a commit showing what I want to see, I thought we could get by with .getField but that doesn't seem to be defined on Property[ClassType] which seems like an oversight. I think if the test I pushed can pass, we're in good shape.

I see. this is another key feature I also need, T1 has a fat OM due to this limitation

@jackkoenig
Copy link
Contributor

Or possible the issue is that instances of classes aren't the right API, but perhaps it really should be a of Properties... I'm playing around with the PR I promised but it does feel weird that classes are Module-like but I'm basically trying to use them as a struct of properties. I think this is a question for @mikeurbach and @albertchen-sifive about what really is the intended usage model here.

@sequencer
Copy link
Member Author

it does feel weird that classes are Module-like

I was confused by this for a long time. But this is the only way I made it successfully work😅

@jackkoenig
Copy link
Contributor

I changed SRAMDescription to a Bundle and it seems to work better.

Copy link
Contributor

@jackkoenig jackkoenig left a comment

Choose a reason for hiding this comment

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

I'm happy with this using a Bundle, we can revisit if any issues come up though.

@jackkoenig jackkoenig merged commit bc1a24d into main Aug 27, 2024
15 checks passed
@jackkoenig jackkoenig deleted the sram-interface-om branch August 27, 2024 20:05
@sequencer
Copy link
Member Author

cc @jackkoenig, Bundle make OM API extensively tricky to design, thus I switch to Class instead, I believe we need more APIs for Class API. rather than using Bundle for storage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants