Skip to content

Commit 9ef850c

Browse files
dbortfacebook-github-bot
authored andcommitted
Migrate runtime-platform-abstraction-layer.md (#623)
Summary: Pull Request resolved: #623 Copy the existing PAL docs, with some minor tweaks. Reviewed By: digantdesai Differential Revision: D49932047 fbshipit-source-id: 9c44042d06a2d4784fae2aef7a9935cfbfbfdc76
1 parent 0e5ddd1 commit 9ef850c

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed
Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,36 @@
1-
# Platform Abstraction Layer
1+
# Runtime Platform Abstraction Layer (PAL)
22

3-
TBA
3+
The ExecuTorch _Platform Abstraction Layer_ (PAL) provides a way for execution
4+
environments to override operations like:
5+
- Getting the current time.
6+
- Printing a log statement.
7+
- Panicking the process/system.
8+
9+
The PAL function declarations are in
10+
[`executorch/runtime/platform/platform.h`](https://github.com/pytorch/executorch/blob/main/runtime/platform/platform.h).
11+
12+
## Overriding the default PAL
13+
14+
The default PAL implementation is in
15+
[`executorch/runtime/platform/target/Posix.cpp`](https://github.com/pytorch/executorch/blob/main/runtime/platform/target/Posix.cpp).
16+
It uses `std::chrono::steady_clock` for the time, prints log messages to
17+
`stderr`, and makes other default assumptions.
18+
19+
But, if they don't work for your system, you can override the default PAL by:
20+
- Including
21+
[`executorch/runtime/platform/platform.h`](https://github.com/pytorch/executorch/blob/main/runtime/platform/platform.h)
22+
in one of your application's `.c` or `.cpp` files.
23+
- Defining an implementation of one or more of the `et_pal_*()` functions.
24+
25+
No build system changes necessary. The default PAL functions are weak symbols,
26+
so providing your own strong-symbol definition will override them at link time.
27+
28+
## Minimal PAL
29+
30+
If you run into build problems because your system doesn't support the functions
31+
called by `Posix.cpp`, you can instead use the no-op minimal PAL at
32+
[`executorch/runtime/platform/target/Minimal.cpp`](https://github.com/pytorch/executorch/blob/main/runtime/platform/target/Minimal.cpp)
33+
by building with the `buck2` flag `-c executorch.pal_default=minimal`. This will
34+
avoid calling `fprintf()`, `std::chrono::steady_clock`, and anything else that
35+
`Posix.cpp` uses. But since the `Minimal.cpp` `et_pal_*()` functions are no-ops,
36+
you will need to override all of them.

docs/website/docs/tutorials/pal.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# Platform Abstraction Layer
2+
3+
DEPRECATED: This document is moving to //executorch/docs/source/runtime-platform-abstraction-layer.md
4+
25
The ExecuTorch Platform Abstraction Layer (PAL) provides a way for execution
36
environments to override operations like:
47
- Getting the current time

0 commit comments

Comments
 (0)