Skip to content

Migrate runtime-platform-abstraction-layer.md #623

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions docs/source/runtime-platform-abstraction-layer.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,36 @@
# Platform Abstraction Layer
# Runtime Platform Abstraction Layer (PAL)

TBA
The ExecuTorch _Platform Abstraction Layer_ (PAL) provides a way for execution
environments to override operations like:
- Getting the current time.
- Printing a log statement.
- Panicking the process/system.

The PAL function declarations are in
[`executorch/runtime/platform/platform.h`](https://github.com/pytorch/executorch/blob/main/runtime/platform/platform.h).

## Overriding the default PAL

The default PAL implementation is in
[`executorch/runtime/platform/target/Posix.cpp`](https://github.com/pytorch/executorch/blob/main/runtime/platform/target/Posix.cpp).
It uses `std::chrono::steady_clock` for the time, prints log messages to
`stderr`, and makes other default assumptions.

But, if they don't work for your system, you can override the default PAL by:
- Including
[`executorch/runtime/platform/platform.h`](https://github.com/pytorch/executorch/blob/main/runtime/platform/platform.h)
in one of your application's `.c` or `.cpp` files.
- Defining an implementation of one or more of the `et_pal_*()` functions.

No build system changes necessary. The default PAL functions are weak symbols,
so providing your own strong-symbol definition will override them at link time.

## Minimal PAL

If you run into build problems because your system doesn't support the functions
called by `Posix.cpp`, you can instead use the no-op minimal PAL at
[`executorch/runtime/platform/target/Minimal.cpp`](https://github.com/pytorch/executorch/blob/main/runtime/platform/target/Minimal.cpp)
by building with the `buck2` flag `-c executorch.pal_default=minimal`. This will
avoid calling `fprintf()`, `std::chrono::steady_clock`, and anything else that
`Posix.cpp` uses. But since the `Minimal.cpp` `et_pal_*()` functions are no-ops,
you will need to override all of them.
3 changes: 3 additions & 0 deletions docs/website/docs/tutorials/pal.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Platform Abstraction Layer

DEPRECATED: This document is moving to //executorch/docs/source/runtime-platform-abstraction-layer.md

The ExecuTorch Platform Abstraction Layer (PAL) provides a way for execution
environments to override operations like:
- Getting the current time
Expand Down