Skip to content

Arm backend: Size Test for Cortex-M #9569

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 6 commits into from
Apr 3, 2025
Merged

Arm backend: Size Test for Cortex-M #9569

merged 6 commits into from
Apr 3, 2025

Conversation

digantdesai
Copy link
Contributor

Summary

Add size test for cortex-M and add it in the CI

Copy link

pytorch-bot bot commented Mar 25, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/9569

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit af648de with merge base b66c319 (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 Mar 25, 2025
@digantdesai digantdesai added ciflow/trunk topic: not user facing and removed CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. labels Mar 25, 2025
@digantdesai digantdesai marked this pull request as draft March 25, 2025 06:56
@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 Mar 25, 2025
@zingo zingo changed the title Size Test for Cortex-M Arm backend: Size Test for Cortex-M Mar 25, 2025
@zingo zingo added the module: arm Issues related to arm backend label Mar 25, 2025
sys.exit(1)

def _get_nm_output(self) -> Dict[str, Symbol]:
args = ["--print-size", "--size-sort", "--reverse-sort", "--demangle"]
Copy link
Contributor

Choose a reason for hiding this comment

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

you might want to specify the format. it can differ between systems.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added!

Comment on lines 62 to 70
symbol_pattern = re.compile(
r"(?P<addr>[0-9a-fA-F]+)\s+(?P<size>[0-9a-fA-F]+)\s+(?P<type>\w)\s+(?P<name>.+)"
)
match = symbol_pattern.match(line)
Copy link
Contributor

Choose a reason for hiding this comment

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

as written, compiling this regex doesn't help. you'd need to store it somewhere that outlives a single call to this function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed by moving it up out of the function. Thanks.

@@ -0,0 +1,167 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
Copy link
Contributor

Choose a reason for hiding this comment

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

perhaps we could use bloaty?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah I did think about it. This is just nm TBH so not sure if we need it to be more complicated than that. Wrote a python wrapper to print sorted table, and use cross-tools. But bloaty is nice though a bit "bloated" with dependency etc.

@digantdesai digantdesai force-pushed the size_test_m branch 7 times, most recently from 0ffc0cb to 25c5dea Compare April 1, 2025 04:18
@digantdesai digantdesai marked this pull request as ready for review April 1, 2025 16:36
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.

sure why not

Comment on lines 127 to 128
self.filter is None
or self.filter not in ["all", "executorch", "executorch_text"]
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: isn't the None check redundant?

Copy link
Contributor

Choose a reason for hiding this comment

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

you could make this easier to maintain and extend by creating a FILTER_NAME_TO_FILTER_AND_LABEL table:

def is_executorch_symbol(s):
    return "executorch" in s.name or s.name.startswith("et")

FILTER_NAME_TO_FILTER_AND_LABEL = {
    "all": (None, "All"),
    "executorch": (is_executorch_symbol, "ExecuTorch"),
    "executorch_text": (lambda s: is_executorch_symbol(s) and s.symbol_type.lower() == "t", "ExecuTorch .text")
}

then access it as

filter, label = FILTER_NAME_TO_FILTER_AND_LABEL.get(self.filter, FILTER_NAME_TO_FILTER_AND_LABEL["all"])
print_table(filter, label)

and use FILTER_NAME_TO_FILTER_AND_LABEL.keys() in the argument definition below

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Prints useful tables about binary size.

TODO: expand it to parse linker map and also dump module, objects, and
section names with a given symbol.
Just getting started. We will build on top of this.
required=False,
default="all",
help="Filter symbols by pre-defined filters",
choices=["all", "executorch", "executorch_text"],
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be FILTER_NAME_TO_FILTER_AND_LABEL.keys() (wrapped in list() if we must)

@digantdesai digantdesai merged commit 3600d4f into main Apr 3, 2025
173 checks passed
@digantdesai digantdesai deleted the size_test_m branch April 3, 2025 04:28
kirklandsign pushed a commit that referenced this pull request Apr 11, 2025
### Summary
Add size test for cortex-M and add it in the CI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ciflow/trunk CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. module: arm Issues related to arm backend topic: not user facing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants