-
Notifications
You must be signed in to change notification settings - Fork 22.2k
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
Support iterating through an Enum class #42661
Conversation
💊 CI failures summary and remediationsAs of commit d37c553 (more details on the Dr. CI page):
🕵️ 1 new failure recognized by patternsThe following CI failures do not appear to be due to upstream breakages: pytorch_windows_vs2019_py36_cuda11.0_build (1/1)Step: "Build" (full log | diagnosis details | 🔁 rerun)
|
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.
@gmagogsfm has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
if (a1.isEnum()) { | ||
return a1.toEnumHolder() == a2.toEnumHolder(); | ||
} |
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.
Wasn't this in your other PR too?
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.
It is, I didn't want the PRs to depend on each other. Will resolve this conflict when one lands first.
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.
How come you didn't use ghstack
to stack them?
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.
No real reason, just not used to using it. Maybe I should try it some day.
enum_pure_values.push_back(name_sv.second->asValue(loc, m)); | ||
} | ||
Node* enum_pure_values_list = m.graph()->insertNode( | ||
m.graph()->createList(enum_type_, enum_pure_values)); |
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.
I wonder if it would be better to create this list upfront as a constant like we do with the enum values themselves and retrieve it here. If it ends up not being used, it'll be optimized out?
Do you know if there is already an optimization that recognizes that this list construction involves only graph constants and does not perform it at runtime?
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.
I think unused and constant enum values will be optimized out if unused. However, I am not entirely sure what benefit we get from creating them upfront. Could you help clarify?
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.
My worry is that this creates a prim::ListConstruct
node that creates the list at runtime through a corresponding LIST_CONSTRUCT
interpreter op. But we know at compile time how long this list is and what its contents are, so we can avoid constructing the list at run time.
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.
I am probably missing something. I thought that would get constant folded and become a list constant?
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.
If that's the case, that's fine too. I think you can probably print the graph
attribute in your test to find out for sure?
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.
Great catch! runCleanUpPasses actually doesn't run constant folding on mutable types (list). Just changed implementation make sure a list constant is generated.
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.
@gmagogsfm has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
@gmagogsfm merged this pull request in 9597af0. |
[5/N] Implement Enum JIT support
Implement Enum class iteration
Add aten.ne for EnumType
Supported:
Enum-typed function arguments
using Enum type and comparing them
Support getting name/value attrs of enums
Using Enum value as constant
Support Enum-typed return values
Support iterating through Enum class (enum value list)
TODO:
Support serialization and deserialization