Skip to content

Introduce PAL function table #10675

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
Jun 5, 2025

Conversation

GregoryComer
Copy link
Member

Summary:
This is part 1 of the implementation of the PAL changes described in #10432. This PR introduces a struct (pal_table) to hold function pointers to the PAL function implementations. There is a singleton instance of this struct, which is initialized with the weak/strong et_pal_ functions - maintaining backwards compatibility with the existing override mechanism.

I've then added wrapper functions for the PAL into the executorch::runtime namespace which dispatch through the function table. It is intended that callers use these functions instead of the "raw" et_pal_ methods in order to correctly dispatch through the function table. In the following PR, I update ET callers to do this.

Differential Revision: D74121895

Copy link

pytorch-bot bot commented May 4, 2025

🔗 Helpful Links

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

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

⏳ No Failures, 1 Pending

As of commit c504b9b with merge base bfea626 (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 May 4, 2025
@facebook-github-bot
Copy link
Contributor

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

@GregoryComer GregoryComer added the release notes: runtime Changes related to the core runtime which loads the program methods, initializes delegates, and runs label May 4, 2025
GregoryComer added a commit to GregoryComer/executorch that referenced this pull request May 21, 2025
Summary:

This is the implementation of the PAL changes described in pytorch#10432. This PR introduces a struct (`pal_table`) to hold function pointers to the PAL function implementations. There is a singleton instance of this struct, which is initialized with the weak/strong et_pal_ functions - maintaining backwards compatibility with the existing override mechanism.

I've then added wrapper functions for the PAL into the executorch::runtime namespace which dispatch through the function table. It is intended that callers use these functions instead of the "raw" et_pal_ methods in order to correctly dispatch through the function table. I also update ET callers to do this.

Differential Revision: D74121895
@facebook-github-bot
Copy link
Contributor

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

GregoryComer added a commit to GregoryComer/executorch that referenced this pull request May 21, 2025
Summary:

This is the implementation of the PAL changes described in pytorch#10432. This PR introduces a struct (`pal_table`) to hold function pointers to the PAL function implementations. There is a singleton instance of this struct, which is initialized with the weak/strong et_pal_ functions - maintaining backwards compatibility with the existing override mechanism.

I've then added wrapper functions for the PAL into the executorch::runtime namespace which dispatch through the function table. It is intended that callers use these functions instead of the "raw" et_pal_ methods in order to correctly dispatch through the function table. I also update ET callers to do this.

Differential Revision: D74121895
@facebook-github-bot
Copy link
Contributor

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

GregoryComer added a commit to GregoryComer/executorch that referenced this pull request May 21, 2025
Summary:

This is the implementation of the PAL changes described in pytorch#10432. This PR introduces a struct (`pal_table`) to hold function pointers to the PAL function implementations. There is a singleton instance of this struct, which is initialized with the weak/strong et_pal_ functions - maintaining backwards compatibility with the existing override mechanism.

I've then added wrapper functions for the PAL into the executorch::runtime namespace which dispatch through the function table. It is intended that callers use these functions instead of the "raw" et_pal_ methods in order to correctly dispatch through the function table. I also update ET callers to do this.

Differential Revision: D74121895
GregoryComer added a commit to GregoryComer/executorch that referenced this pull request May 21, 2025
Summary:

This is the implementation of the PAL changes described in pytorch#10432. This PR introduces a struct (`pal_table`) to hold function pointers to the PAL function implementations. There is a singleton instance of this struct, which is initialized with the weak/strong et_pal_ functions - maintaining backwards compatibility with the existing override mechanism.

I've then added wrapper functions for the PAL into the executorch::runtime namespace which dispatch through the function table. It is intended that callers use these functions instead of the "raw" et_pal_ methods in order to correctly dispatch through the function table. I also update ET callers to do this.

Differential Revision: D74121895
*
* Returns true if the registration was successful, false otherwise.
*/
bool register_pal(pal_table impl);
Copy link
Member Author

Choose a reason for hiding this comment

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

This API is returning bool primarily because using Error would introduce a circular header dependency and there's no current way for this call to fail. I'm open to switching to error, but would require a little bit of a header refactor.

GregoryComer added a commit to GregoryComer/executorch that referenced this pull request May 21, 2025
Summary:

This is the implementation of the PAL changes described in pytorch#10432. This PR introduces a struct (`pal_table`) to hold function pointers to the PAL function implementations. There is a singleton instance of this struct, which is initialized with the weak/strong et_pal_ functions - maintaining backwards compatibility with the existing override mechanism.

I've then added wrapper functions for the PAL into the executorch::runtime namespace which dispatch through the function table. It is intended that callers use these functions instead of the "raw" et_pal_ methods in order to correctly dispatch through the function table. I also update ET callers to do this.

Differential Revision: D74121895
GregoryComer added a commit to GregoryComer/executorch that referenced this pull request May 21, 2025
Summary:

This is the implementation of the PAL changes described in pytorch#10432. This PR introduces a struct (`pal_table`) to hold function pointers to the PAL function implementations. There is a singleton instance of this struct, which is initialized with the weak/strong et_pal_ functions - maintaining backwards compatibility with the existing override mechanism.

I've then added wrapper functions for the PAL into the executorch::runtime namespace which dispatch through the function table. It is intended that callers use these functions instead of the "raw" et_pal_ methods in order to correctly dispatch through the function table. I also update ET callers to do this.

Differential Revision: D74121895
@GregoryComer
Copy link
Member Author

GregoryComer commented May 29, 2025

Trying to repro the size test failure locally to investigate. For some reason, I'm only seeing a 64-byte increase in size between this PR and the base revision, which is more in line with what I'd expect. I am on Clang 14 locally vs 12 in CI. Maybe that's related?

Main:

-rwxr-xr-x  1 gregory gregory   51664 May 29 03:34 size_test
-rwxr-xr-x  1 gregory gregory 1915080 May 29 03:33 size_test_all_ops
-rwxr-xr-x  1 gregory gregory   70872 May 29 03:34 size_test_unstripped 

PR:

-rwxr-xr-x  1 gregory gregory   51728 May 29 03:38 size_test
-rwxr-xr-x  1 gregory gregory 1915840 May 29 03:37 size_test_all_ops
-rwxr-xr-x  1 gregory gregory   71936 May 29 03:37 size_test_unstripped

Edit: Interestingly, it does seem to be reproducible on Clang 12:

Main:

-rwxr-xr-x  1 gregory gregory   47560 May 29 03:57 size_test
-rwxr-xr-x  1 gregory gregory 1748816 May 29 03:57 size_test_all_ops
-rwxr-xr-x  1 gregory gregory   66504 May 29 03:57 size_test_unstripped

PR:

-rwxr-xr-x  1 gregory gregory   51720 May 29 03:55 size_test
-rwxr-xr-x  1 gregory gregory 1749880 May 29 03:54 size_test_all_ops
-rwxr-xr-x  1 gregory gregory   71664 May 29 03:55 size_test_unstripped

GregoryComer added a commit to GregoryComer/executorch that referenced this pull request May 31, 2025
Summary:

This is the implementation of the PAL changes described in pytorch#10432. This PR introduces a struct (`pal_table`) to hold function pointers to the PAL function implementations. There is a singleton instance of this struct, which is initialized with the weak/strong et_pal_ functions - maintaining backwards compatibility with the existing override mechanism.

I've then added wrapper functions for the PAL into the executorch::runtime namespace which dispatch through the function table. It is intended that callers use these functions instead of the "raw" et_pal_ methods in order to correctly dispatch through the function table. I also update ET callers to do this.

Differential Revision: D74121895
GregoryComer added a commit to GregoryComer/executorch that referenced this pull request May 31, 2025
Summary:

This is the implementation of the PAL changes described in pytorch#10432. This PR introduces a struct (`pal_table`) to hold function pointers to the PAL function implementations. There is a singleton instance of this struct, which is initialized with the weak/strong et_pal_ functions - maintaining backwards compatibility with the existing override mechanism.

I've then added wrapper functions for the PAL into the executorch::runtime namespace which dispatch through the function table. It is intended that callers use these functions instead of the "raw" et_pal_ methods in order to correctly dispatch through the function table. I also update ET callers to do this.

Differential Revision: D74121895
GregoryComer added a commit to GregoryComer/executorch that referenced this pull request May 31, 2025
Summary:

This is the implementation of the PAL changes described in pytorch#10432. This PR introduces a struct (`pal_table`) to hold function pointers to the PAL function implementations. There is a singleton instance of this struct, which is initialized with the weak/strong et_pal_ functions - maintaining backwards compatibility with the existing override mechanism.

I've then added wrapper functions for the PAL into the executorch::runtime namespace which dispatch through the function table. It is intended that callers use these functions instead of the "raw" et_pal_ methods in order to correctly dispatch through the function table. I also update ET callers to do this.

Differential Revision: D74121895
GregoryComer added a commit to GregoryComer/executorch that referenced this pull request Jun 3, 2025
Summary:

This is the implementation of the PAL changes described in pytorch#10432. This PR introduces a struct (`pal_table`) to hold function pointers to the PAL function implementations. There is a singleton instance of this struct, which is initialized with the weak/strong et_pal_ functions - maintaining backwards compatibility with the existing override mechanism.

I've then added wrapper functions for the PAL into the executorch::runtime namespace which dispatch through the function table. It is intended that callers use these functions instead of the "raw" et_pal_ methods in order to correctly dispatch through the function table. I also update ET callers to do this.

Differential Revision: D74121895
GregoryComer added a commit to GregoryComer/executorch that referenced this pull request Jun 3, 2025
Summary:

This is the implementation of the PAL changes described in pytorch#10432. This PR introduces a struct (`pal_table`) to hold function pointers to the PAL function implementations. There is a singleton instance of this struct, which is initialized with the weak/strong et_pal_ functions - maintaining backwards compatibility with the existing override mechanism.

I've then added wrapper functions for the PAL into the executorch::runtime namespace which dispatch through the function table. It is intended that callers use these functions instead of the "raw" et_pal_ methods in order to correctly dispatch through the function table. I also update ET callers to do this.

Differential Revision: D74121895
@@ -371,7 +371,7 @@ jobs:
size=${arr[4]}
# threshold=48120 on devserver with gcc11.4
# todo(lfq): update once binary size is below 50kb.
threshold="51408"
threshold="55584"
Copy link
Member Author

@GregoryComer GregoryComer Jun 3, 2025

Choose a reason for hiding this comment

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

Note that the "true" size increase is around ~80 bytes, due to some instability in the size test on older toolchains. See https://github.com/pytorch/executorch/pull/11217/files. This is confirmed with manual builds on newer toolchains and Meta app build size checks.

@@ -406,7 +406,7 @@ jobs:
output=$(ls -la cmake-out/test/size_test)
arr=($output)
size=${arr[4]}
threshold="47560"
threshold="51720"
Copy link
Member Author

Choose a reason for hiding this comment

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

Similar to above, note that the "true" size increase is around ~64 bytes. See https://github.com/pytorch/executorch/pull/11217/files.

@facebook-github-bot
Copy link
Contributor

@GregoryComer has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

GregoryComer added a commit to GregoryComer/executorch that referenced this pull request Jun 5, 2025
Summary:

This is the implementation of the PAL changes described in pytorch#10432. This PR introduces a struct (`pal_table`) to hold function pointers to the PAL function implementations. There is a singleton instance of this struct, which is initialized with the weak/strong et_pal_ functions - maintaining backwards compatibility with the existing override mechanism.

I've then added wrapper functions for the PAL into the executorch::runtime namespace which dispatch through the function table. It is intended that callers use these functions instead of the "raw" et_pal_ methods in order to correctly dispatch through the function table. I also update ET callers to do this.

Differential Revision: D74121895
Summary:

This is the implementation of the PAL changes described in pytorch#10432. This PR introduces a struct (`pal_table`) to hold function pointers to the PAL function implementations. There is a singleton instance of this struct, which is initialized with the weak/strong et_pal_ functions - maintaining backwards compatibility with the existing override mechanism.

I've then added wrapper functions for the PAL into the executorch::runtime namespace which dispatch through the function table. It is intended that callers use these functions instead of the "raw" et_pal_ methods in order to correctly dispatch through the function table. I also update ET callers to do this.

Differential Revision: D74121895
@facebook-github-bot
Copy link
Contributor

@GregoryComer has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@GregoryComer GregoryComer merged commit 60929cf into pytorch:main Jun 5, 2025
114 of 115 checks passed
GregoryComer added a commit that referenced this pull request Jun 5, 2025
### Summary
The recent PAL changes
(#10675) increased runtime
size slightly. This was approved and size targets were updated for the
main size jobs. However, I missed the Cortex-M job and am updating here.

### Test plan
CI
GregoryComer added a commit that referenced this pull request Jun 24, 2025
### Summary
Update PAL docs in using-executorch-runtime-integration.md to describe
the new PAL override mechanism introduced in
#10675. I've left the docs in
for the weak symbol override mechanism, as well, though I've recommended
use of the runtime APIs.

### Test plan
I built the docs locally to validate form and content.
hinriksnaer pushed a commit to hinriksnaer/executorch that referenced this pull request Jun 26, 2025
### Summary
Update PAL docs in using-executorch-runtime-integration.md to describe
the new PAL override mechanism introduced in
pytorch#10675. I've left the docs in
for the weak symbol override mechanism, as well, though I've recommended
use of the runtime APIs.

### Test plan
I built the docs locally to validate form and content.
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 release notes: runtime Changes related to the core runtime which loads the program methods, initializes delegates, and runs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants