|
1 |
| -# Platform Abstraction Layer |
| 1 | +# Runtime Platform Abstraction Layer (PAL) |
2 | 2 |
|
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. |
0 commit comments