-
Notifications
You must be signed in to change notification settings - Fork 537
Refactor internal switch cases #9802
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
Refactor internal switch cases #9802
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/9802
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit b29ea1c with merge base d28670b ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This pull request was exported from Phabricator. Differential Revision: D72248082 |
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.
an up-to-date English explanation of the taxonomy of types in a comment is probably in order so people don't have to read through all the macros.
would also like @mergennachin's opinion on this
#define ET_INTERNAL_SWITCH_CASE_BOOL_TYPES(CTYPE_ALIAS, ...) \ | ||
ET_INTERNAL_SWITCH_CASE( \ | ||
::executorch::aten::ScalarType::Bool, CTYPE_ALIAS, __VA_ARGS__) |
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.
why does this macro exist? what other types could it contain that aren't exactly ScalarType::Bool
?
ET_INTERNAL_SWITCH_CASE( \ | ||
::executorch::aten::ScalarType::UInt64, CTYPE_ALIAS, __VA_ARGS__) | ||
|
||
#define ET_INTERNAL_SWITCH_CASE_ALLINT_TYPES(CTYPE_ALIAS, ...) \ |
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.
why is "ALLINT" one word instead of "ALL_INT"?
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.
ALLINT is the name of the set, just like REALH and REALHBF16 are names
#define ET_INTERNAL_SWITCH_CASE_FLOAT_TYPES(CTYPE_ALIAS, ...) \ | ||
ET_INTERNAL_SWITCH_CASE( \ | ||
::executorch::aten::ScalarType::Float, CTYPE_ALIAS, __VA_ARGS__) \ | ||
ET_INTERNAL_SWITCH_CASE( \ | ||
::executorch::aten::ScalarType::Double, CTYPE_ALIAS, __VA_ARGS__) | ||
|
||
#define ET_INTERNAL_SWITCH_CASE_ALLFLOAT_TYPES(CTYPE_ALIAS, ...) \ |
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.
having these both exist is confusing -- "Half and BFloat16 are part of all float types, but they're not float types"?
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.
Half and BFloat16 are not part of the FLOAT set today. That's why we have FLOATH and FLOATHBF16.
I am using the prefix "ALL" to denote the set containing all of the types belonging to a given category (INT, FLOAT, REAL, COMPLEX, NUMERIC)
#define ET_INTERNAL_SWITCH_CASE_REAL_TYPES(CTYPE_ALIAS, ...) \ | ||
ET_INTERNAL_SWITCH_CASE_INT_TYPES(CTYPE_ALIAS, __VA_ARGS__) \ | ||
ET_INTERNAL_SWITCH_CASE_FLOAT_TYPES(CTYPE_ALIAS, __VA_ARGS__) | ||
|
||
#define ET_INTERNAL_SWITCH_CASE_ALLREAL_TYPES(CTYPE_ALIAS, ...) \ |
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.
same -- if ET_INTERNAL_SWITCH_CASE_REAL_TYPES should not be deprecated, then we need better names that make it clear when you would use each one
#define ET_INTERNAL_SWITCH_CASE_COMPLEX_TYPES(CTYPE_ALIAS, ...) \ | ||
ET_INTERNAL_SWITCH_CASE( \ | ||
::executorch::aten::ScalarType::ComplexFloat, CTYPE_ALIAS, __VA_ARGS__) \ | ||
ET_INTERNAL_SWITCH_CASE( \ | ||
::executorch::aten::ScalarType::ComplexDouble, CTYPE_ALIAS, __VA_ARGS__) | ||
|
||
#define ET_INTERNAL_SWITCH_CASE_ALLCOMPLEX_TYPES(CTYPE_ALIAS, ...) \ |
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.
same concern as before -- confusing, why isn't the old one deprecated, etc.
#define ET_SWITCH_REALHBBF16_AND_UINT_TYPES( \ | ||
TYPE, CONTEXT, NAME, CTYPE_ALIAS, ...) \ | ||
ET_INTERNAL_SWITCH( \ | ||
TYPE, \ | ||
CONTEXT, \ | ||
NAME, \ | ||
ET_INTERNAL_SWITCH_CASE_REAL_TYPES_AND3( \ | ||
Half, Bool, BFloat16, CTYPE_ALIAS, __VA_ARGS__) \ | ||
ET_INTERNAL_SWITCH_CASE( \ | ||
::executorch::aten::ScalarType::UInt16, \ | ||
CTYPE_ALIAS, \ | ||
__VA_ARGS__) \ | ||
ET_INTERNAL_SWITCH_CASE( \ | ||
::executorch::aten::ScalarType::UInt32, \ | ||
CTYPE_ALIAS, \ | ||
__VA_ARGS__) \ | ||
ET_INTERNAL_SWITCH_CASE( \ | ||
::executorch::aten::ScalarType::UInt64, \ | ||
CTYPE_ALIAS, \ | ||
__VA_ARGS__)) | ||
ET_SWITCH_ALLREALB_TYPES(TYPE, CONTEXT, NAME, CTYPE_ALIAS, __VA_ARGS__) |
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.
this is more easily accomplished as #define ET_SWITCH_REALHBBF16_AND_UINT_TYPES ET_SWITCH_ALLREALB_TYPES
(and similarly below)
Summary: There were multiple ET_INTERNAL_SWITCH_CASE_*_TYPES macros that repeated lists of types, for example: `ET_INTERNAL_SWITCH_CASE_INT_TYPES` `ET_INTERNAL_SWITCH_CASE_REAL_TYPES` `ET_INTERNAL_SWITCH_CASE_FLOAT_TYPES` `ET_INTERNAL_SWITCH_CASE_ALL_TYPES` In this PR, we refactor them building from the bottom up, for example reusing INT and FLOAT to build REAL and reusing REAL to build ALL Differential Revision: D72248082
b704763
to
ed3e10c
Compare
This pull request was exported from Phabricator. Differential Revision: D72248082 |
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.
seems fine
Summary: There were multiple ET_INTERNAL_SWITCH_CASE_*_TYPES macros that repeated lists of types, for example: `ET_INTERNAL_SWITCH_CASE_INT_TYPES` `ET_INTERNAL_SWITCH_CASE_REAL_TYPES` `ET_INTERNAL_SWITCH_CASE_FLOAT_TYPES` `ET_INTERNAL_SWITCH_CASE_ALL_TYPES` In this PR, we refactor them building from the bottom up, for example reusing INT and FLOAT to build REAL and reusing REAL to build ALL Reviewed By: swolchok Differential Revision: D72248082
ed3e10c
to
933fa0e
Compare
This pull request was exported from Phabricator. Differential Revision: D72248082 |
Summary: There were multiple ET_INTERNAL_SWITCH_CASE_*_TYPES macros that repeated lists of types, for example: `ET_INTERNAL_SWITCH_CASE_INT_TYPES` `ET_INTERNAL_SWITCH_CASE_REAL_TYPES` `ET_INTERNAL_SWITCH_CASE_FLOAT_TYPES` `ET_INTERNAL_SWITCH_CASE_ALL_TYPES` In this PR, we refactor them building from the bottom up, for example reusing INT and FLOAT to build REAL and reusing REAL to build ALL Reviewed By: swolchok Differential Revision: D72248082
933fa0e
to
b29ea1c
Compare
This pull request was exported from Phabricator. Differential Revision: D72248082 |
Differential Revision: D72248082 Pull Request resolved: pytorch#9802
There were multiple ET_INTERNAL_SWITCH_CASE_*_TYPES macros that repeated lists of types, for example:
ET_INTERNAL_SWITCH_CASE_INT_TYPES
ET_INTERNAL_SWITCH_CASE_REAL_TYPES
ET_INTERNAL_SWITCH_CASE_FLOAT_TYPES
ET_INTERNAL_SWITCH_CASE_ALL_TYPES
In this PR, we refactor them building from the bottom up, for example reusing INT and FLOAT to build REAL and reusing REAL to build ALL
Differential Revision: D72248082