Skip to content

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

Merged
merged 1 commit into from
Apr 15, 2025

Conversation

manuelcandales
Copy link
Contributor

@manuelcandales manuelcandales commented Apr 1, 2025

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

Copy link

pytorch-bot bot commented Apr 1, 2025

🔗 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 Failures

As of commit b29ea1c with merge base d28670b (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 1, 2025
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D72248082

@manuelcandales manuelcandales added the release notes: ops & kernels Changes to the opset and any new / changed kernel implementations label Apr 1, 2025
Copy link
Contributor

@swolchok swolchok left a 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

Comment on lines 924 to 926
#define ET_INTERNAL_SWITCH_CASE_BOOL_TYPES(CTYPE_ALIAS, ...) \
ET_INTERNAL_SWITCH_CASE( \
::executorch::aten::ScalarType::Bool, CTYPE_ALIAS, __VA_ARGS__)
Copy link
Contributor

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, ...) \
Copy link
Contributor

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"?

Copy link
Contributor Author

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

Comment on lines 956 to 962
#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, ...) \
Copy link
Contributor

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"?

Copy link
Contributor Author

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)

Comment on lines 969 to 973
#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, ...) \
Copy link
Contributor

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

Comment on lines 981 to 987
#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, ...) \
Copy link
Contributor

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.

Comment on lines 1212 to 1214
#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__)
Copy link
Contributor

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)

manuelcandales added a commit to manuelcandales/executorch-1 that referenced this pull request Apr 1, 2025
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
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D72248082

@manuelcandales manuelcandales added topic: not user facing and removed release notes: ops & kernels Changes to the opset and any new / changed kernel implementations labels Apr 1, 2025
Copy link
Contributor

@swolchok swolchok left a comment

Choose a reason for hiding this comment

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

seems fine

manuelcandales added a commit to manuelcandales/executorch-1 that referenced this pull request Apr 4, 2025
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
@facebook-github-bot
Copy link
Contributor

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
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D72248082

@facebook-github-bot facebook-github-bot merged commit 6d1caca into pytorch:main Apr 15, 2025
83 of 84 checks passed
keyprocedure pushed a commit to keyprocedure/executorch that referenced this pull request Apr 21, 2025
Differential Revision: D72248082

Pull Request resolved: pytorch#9802
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported topic: not user facing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants