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

Memoize first clock type of defn #685

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

Conversation

rsetaluri
Copy link
Collaborator

No description provided.


@functools.lru_cache(maxsize=None)
def wireclocktype(defn, inst, clocktype):
defnclk = _get_first_clock_of_defn(defn, clocktype)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we want to memoize the _get_first_clock function right? But I'm not sure if this is really where the best savings will occur, since for one definition, we'll only need to get the first clock once.

I think where it becomes useful is in the wiring of instances. We may have a large number of instances, and we have to check each of their interfaces to find the first clock. If we can memoize the first clock for a definition, then for each instance we can simply lookup the default clock rather than traversing the interface. I suspect most of the savings will come here, since will be repeating the clock lookup logic for instances of the same definition, while definitions only need to lookup their internal clock once

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, wireclock will repeat this logic for each clock type. I think it would be more efficient to wire a set of clock types and handle them all as we're traversing the interface once (rather than traversing the interface each time for each clock type).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

(a) yes, oops, sorry put the decorator on the wrong function.

(b) with the decorator on the right function, we will only traverse the interface once per (definition, type) pair. If I understand correctly, you're suggesting we simultaneously do the traversal for all the types?

(c) yes, good point about instances. Even if we find we can find the first clock of a defn fast, we still find all the clocks for each instance, and this is repeated even for multiple instances of the same defn. Will try to implement this.

I think the best way to do this is to have an acceleration data structure associated with each defn which is Map[Type, List[String]], where for each type we have the name of all the ports which match that type. We can make this a query and then cache the result per definition. I think it would also be prudent to have an option to stop on the first one if needed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@leonardt I can try to implement the above.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually, I realize (c) is more complicated for nested types. If for example, defn.x[0].y[1] happens to be a clock type, re-targetting that reference to an instance is non-trivial (we basically need to capture all the clock types "by reference"). Will think about the best way to do this.

If we avoid nested types this becomes much easier as all we have to do is save the port name and do getattr on instances. But it sounds like nested clocks are definitely important.

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.

2 participants