Skip to content

Adopt runtime::FunctionRef in thread_parallel_interface.h and thread_parallel.h #10442

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 8 commits into from
Apr 25, 2025

Conversation

swolchok
Copy link
Contributor

This saves a ton of size by no longer requiring callers to create std::function.

Test Plan: bash test/build_optimized_size_test.sh && size test/size_test_all_optimized_ops

before:

ExecuTorch with no ops binary size, unstripped:
-rwxr-xr-x  1 swolchok  staff  153928 Apr 24 13:11 cmake-out/test/size_test
ExecuTorch with portable ops binary size, unstripped:
-rwxr-xr-x  1 swolchok  staff  2150960 Apr 24 13:11 cmake-out/test/size_test_all_ops
ExecuTorch with optimized ops binary size, unstripped:
-rwxr-xr-x  1 swolchok  staff  11182136 Apr 24 13:11 cmake-out/test/size_test_all_optimized_ops

__TEXT	__DATA	__OBJC	others	dec	hex
5341184	98304	0	4300800000	4306239488	100ac0000

after:

ExecuTorch with no ops binary size, unstripped:
-rwxr-xr-x  1 swolchok  staff  153928 Apr 24 13:07 cmake-out/test/size_test
ExecuTorch with portable ops binary size, unstripped:
-rwxr-xr-x  1 swolchok  staff  2150960 Apr 24 13:07 cmake-out/test/size_test_all_ops
ExecuTorch with optimized ops binary size, unstripped:
-rwxr-xr-x  1 swolchok  staff  5927336 Apr 24 13:07 cmake-out/test/size_test_all_optimized_ops

__TEXT	__DATA	__OBJC	others	dec	hex
4505600	98304	0	4296376320	4300980224	1005bc000

__TEXT size improvement is 835584 bytes, or 15%.

[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
@swolchok swolchok requested a review from kimishpatel as a code owner April 24, 2025 20:15
Copy link

pytorch-bot bot commented Apr 24, 2025

🔗 Helpful Links

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

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

⏳ No Failures, 4 Pending

As of commit 5bc4b0c with merge base 6feb623 (image):
💚 Looks good so far! There are no failures yet. 💚

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

swolchok added a commit that referenced this pull request Apr 24, 2025
…parallel.h

This saves a *ton* of size by no longer requiring callers to create std::function.

Test Plan: bash test/build_optimized_size_test.sh && size test/size_test_all_optimized_ops

before:
```
ExecuTorch with no ops binary size, unstripped:
-rwxr-xr-x  1 swolchok  staff  153928 Apr 24 13:11 cmake-out/test/size_test
ExecuTorch with portable ops binary size, unstripped:
-rwxr-xr-x  1 swolchok  staff  2150960 Apr 24 13:11 cmake-out/test/size_test_all_ops
ExecuTorch with optimized ops binary size, unstripped:
-rwxr-xr-x  1 swolchok  staff  11182136 Apr 24 13:11 cmake-out/test/size_test_all_optimized_ops

__TEXT	__DATA	__OBJC	others	dec	hex
5341184	98304	0	4300800000	4306239488	100ac0000
```

after:
```
ExecuTorch with no ops binary size, unstripped:
-rwxr-xr-x  1 swolchok  staff  153928 Apr 24 13:07 cmake-out/test/size_test
ExecuTorch with portable ops binary size, unstripped:
-rwxr-xr-x  1 swolchok  staff  2150960 Apr 24 13:07 cmake-out/test/size_test_all_ops
ExecuTorch with optimized ops binary size, unstripped:
-rwxr-xr-x  1 swolchok  staff  5927336 Apr 24 13:07 cmake-out/test/size_test_all_optimized_ops

__TEXT	__DATA	__OBJC	others	dec	hex
4505600	98304	0	4296376320	4300980224	1005bc000
````
`__TEXT` size improvement is 835584 bytes, or 15%.


ghstack-source-id: 2482ad7
ghstack-comment-id: 2828755250
Pull-Request-resolved: #10442
@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 24, 2025
Copy link
Contributor

@digantdesai digantdesai left a comment

Choose a reason for hiding this comment

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

curious how did you find this optimization?

[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
swolchok added a commit that referenced this pull request Apr 25, 2025
…parallel.h

This saves a *ton* of size by no longer requiring callers to create std::function.

Test Plan: bash test/build_optimized_size_test.sh && size test/size_test_all_optimized_ops

before:
```
ExecuTorch with no ops binary size, unstripped:
-rwxr-xr-x  1 swolchok  staff  153928 Apr 24 13:11 cmake-out/test/size_test
ExecuTorch with portable ops binary size, unstripped:
-rwxr-xr-x  1 swolchok  staff  2150960 Apr 24 13:11 cmake-out/test/size_test_all_ops
ExecuTorch with optimized ops binary size, unstripped:
-rwxr-xr-x  1 swolchok  staff  11182136 Apr 24 13:11 cmake-out/test/size_test_all_optimized_ops

__TEXT	__DATA	__OBJC	others	dec	hex
5341184	98304	0	4300800000	4306239488	100ac0000
```

after:
```
ExecuTorch with no ops binary size, unstripped:
-rwxr-xr-x  1 swolchok  staff  153928 Apr 24 13:07 cmake-out/test/size_test
ExecuTorch with portable ops binary size, unstripped:
-rwxr-xr-x  1 swolchok  staff  2150960 Apr 24 13:07 cmake-out/test/size_test_all_ops
ExecuTorch with optimized ops binary size, unstripped:
-rwxr-xr-x  1 swolchok  staff  5927336 Apr 24 13:07 cmake-out/test/size_test_all_optimized_ops

__TEXT	__DATA	__OBJC	others	dec	hex
4505600	98304	0	4296376320	4300980224	1005bc000
````
`__TEXT` size improvement is 835584 bytes, or 15%.


ghstack-source-id: 516b5a7
ghstack-comment-id: 2828755250
Pull-Request-resolved: #10442
@swolchok
Copy link
Contributor Author

curious how did you find this optimization?

@digantdesai I was working on reapplying #9842 and #9841 (reverted due to size regression) and iteratively using bloaty on the result of bash test/build_optimized_size_test.sh. There was a clear huge size increase from std::function, and after struggling with how to avoid it, I found my way to function_ref.

@swolchok
Copy link
Contributor Author

Unit tests look good despite two apparent flakes. will merge after rebase.

[ghstack-poisoned]
[ghstack-poisoned]
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. topic: not user facing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants