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

feat(LogPerfHelper): reuse LogPerfHelper if visible #86

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

klin02
Copy link
Member

@klin02 klin02 commented Nov 21, 2024

Modified from Difftest Repo. See details in Difftest PR#261 and #309.

To avoid a large number of duplicated LogPerfHelper instantiated in same module, we allow reusing previous instances if visible.

Note instances in when scope cannot be accessed from other, such instances is not visible and cannot be reused, we will still instantiate another duplicated one.

Modified from Difftest Repo. See details in Difftest PR#261 and #309.

To avoid a large number of duplicated LogPerfHelper instantiated in
same module, we allow reusing previous instances if visible.

Note instances in when scope cannot be accessed from other, such
instances is not visible and cannot be reused, we will still instantiate
another duplicated one.
@klin02
Copy link
Member Author

klin02 commented Nov 21, 2024

After this change, number of LogPerfHelper instantiated in XiangShan reduces from thousands to nearly 300, which will speed up compilation speed of Palladium. And other simulator may also benefit from it.

@klin02
Copy link
Member Author

klin02 commented Nov 21, 2024

Chisel isVisible API implemented by @poemonsense :)

private val instances = scala.collection.mutable.ListBuffer.empty[LogPerfIO]
private def instantiate(): LogPerfIO = instances.addOne(WireInit(Module(new LogPerfHelper).io)).last

def apply(): LogPerfIO = instances.find(gen => isVisible(gen)).getOrElse(instantiate())
Copy link
Member

Choose a reason for hiding this comment

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

One question: after this change, the design will not be compatible with older versions of Chisel before v6.1.0. Is this accpepted by XiangShan and its submodules? @Tang-Haojin

Instead of calling isVisible here, I would prefer using Scala reflection to call the LogPerfControl in DiffTest. Only if that does not exist (the module using utility is not simulated by DiffTest), we use the one currently defined in utility. Then we don't need to copy the isVisible code here and the code would always align with DiffTest. I believe in the future, we will replace the one in DiffTest with tapAndRead.

Copy link
Member

Choose a reason for hiding this comment

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

One question: after this change, the design will not be compatible with older versions of Chisel before v6.1.0. Is this accpepted by XiangShan and its submodules? @Tang-Haojin

This is okay for XiangShan, but may be carefully checked for submodules.

Instead of calling isVisible here, I would prefer using Scala reflection to call the LogPerfControl in DiffTest. Only if that does not exist (the module using utility is not simulated by DiffTest), we use the one currently defined in utility. Then we don't need to copy the isVisible code here and the code would always align with DiffTest. I believe in the future, we will replace the one in DiffTest with tapAndRead.

I agree to use tapAndRead instead and actually I have tried it few months ago locally. I pushed it to our repositories just now. Maybe @klin02 can help me to review it and if you think it okay, you may also help to rebase it towards master.

Here are the related repos and branches:
https://github.com/OpenXiangShan/XiangShan/tree/tap-and-read
https://github.com/OpenXiangShan/CoupledL2/tree/tap-and-read
https://github.com/OpenXiangShan/HuanCun/tree/tap-and-read
https://github.com/OpenXiangShan/Utility/tree/tap-and-read

Copy link
Member

Choose a reason for hiding this comment

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

But tapAndRead also has some dedup issues so I write a transform to dedup manually.

Copy link
Member Author

Choose a reason for hiding this comment

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

Previously I also try to use tapAndRead for perfIO(Register source first and assign tap to sink somewhere). However, It brings a lot of middle ports like addSource and addSink.

I think that's because chisel use probe ports (can be seen in firrtl module ports) to implement tap. And output probe(child source to parent sink) can be replaced by hierarchical reference like aa.bb.cc, but input probe will still be generated as IOs.

Does current tap supports hidden middle IO?I also agree modified tap is better to logPerf.

Copy link
Member

Choose a reason for hiding this comment

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

No, chisel still cannot generate non-hierarchical XMR in Verilog, and it generates IO ports. But I think it is okay.

Copy link
Member Author

Choose a reason for hiding this comment

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

I can have a try for hierarchical name first. The problem is instance can only be accessed after elaboration.

If it works, maybe we can collect logPerf directly.

Copy link
Member

Choose a reason for hiding this comment

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

That is ok but printing hierarchical name (%m) may be a new problem.

I see. This is indeed a problem.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hierarchical name(for both data or module) can be accessed by xx.pathName after circuit elaboration ( Stage.execute), which means we may need another method called after elaboration, generating macros of hierarchical module name, is it acceptable?
Alternatively, during elaboration, we can get currentModule name up to top module name using recursive DataMirror.getParent. Like SimTop.Mod1.Mod2... instead of SimTop.Inst1.Inst2... But it may be mixed up with multi instances with same modName

Copy link
Member Author

Choose a reason for hiding this comment

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

Seems ChiselDB and Constantin already have similar calling interface after elaboration like addToFileRegisters

Copy link
Member

@poemonsense poemonsense Nov 23, 2024

Choose a reason for hiding this comment

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

Hierarchical name(for both data or module) can be accessed by xx.pathName after circuit elaboration ( Stage.execute), which means we may need another method called after elaboration, generating macros of hierarchical module name, is it acceptable? Alternatively, during elaboration, we can get currentModule name up to top module name using recursive DataMirror.getParent. Like SimTop.Mod1.Mod2... instead of SimTop.Inst1.Inst2... But it may be mixed up with multi instances with same modName

I think it's good. We can add this optional interface to difftest or utility, to be called after elaboration.

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.

3 participants