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

Enforce Unique Names #496

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

Enforce Unique Names #496

wants to merge 1 commit into from

Conversation

jameshegarty
Copy link
Collaborator

I suggest we change magma to enforce that module names are unique at definition time. Currently, if the user forgets to memoize a generator, their code will create thousands of duplicate module definitions, which the compiler will silently accept. This is causing us to have hour long compile times, and it's not possible to debug this if we don't raise an error.

I added a quick fix to enforce this behavior, but (if we agree this is the behavior we want), I will need help squashing all the duplicate name bugs. It looks like a large number of generators in the repo that are not being memoized.

@jameshegarty
Copy link
Collaborator Author

Also @leonardt there was a breaking change to the combinational file on my machine which I fixed (?) here.

@@ -275,7 +275,6 @@ def wrapped(fn):
else:
wrapped_combinational = ast_utils.inspect_enclosing_env(
_combinational,
decorators=[combinational],
st=env
decorators=[combinational]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you try updating to the latest version of ast_tools and reverting this change? (pip install --upgrade ast_tools), the st argument was introduced in the latest release.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok I guess I didn't realize I had to run pip upgrade, but that makes sense.

def EndDefine():
if currentDefinition:
if currentDefinition.name in __seenCircuitNames:
raise Exception(f"The circuit name '{currentDefinition.name}' was already used. Module names must be unique!")
__seenCircuitNames[currentDefinition.name] = 1
Copy link
Collaborator

Choose a reason for hiding this comment

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

For now, could we add this as a configurable option? That way we can merge it into the mainline release ASAP but then figure out how exactly we want to handle it and what the default behavior should be (I expect there to be some discussion).

We could add a simple API like set/get_debug_mode https://github.com/phanrahan/magma/blob/master/magma/config.py#L14-L24 to enable this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

IMO I would rather have the discussion and decide to fix the issue or not. We don't need to have this merged in immediately. What do people think? Are there any arguments on the other side?

@rsetaluri
Copy link
Collaborator

This issue has ping-ponged a bit in magma previously. I think this condition used to be enforced, but we changed it because not enforcing it was more general and robust. In particular, if you have a top level design that's using components from disparate places, they may not have unique names. And in fact they may not be modifiable (imagine you're importing some third party magma code or something).

Plus, the issue of not caching generators is separate and should be solved "directly". I think one reasonable thing would be to make auto-uniquification off by default in the compiler; i.e. this error is raised at compile time rather than define time. This mode already exists, it just has to be enabled.

@leonardt
Copy link
Collaborator

@rsetaluri I think that would help with performance (avoiding the repr uniquification time), another incremental option might be to allow selective whitelist of names to uniquify (so if there's a commonly used name such as Util or something, uniquification can be enabled for those circuits, while off by default.

@leonardt
Copy link
Collaborator

Another improvement would be to add automatic name generation in the Generator class, right now it caches so it avoids regenerating multiple instances, but I think if the use doesn't provide a name to the generated Circuit, it will still trigger uniquification downstream for each instance of the generator

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.

None yet

3 participants