Name | Date | Size | #Lines | LOC | ||
---|---|---|---|---|---|---|
.. | - | - | ||||
_passes/ | H | 25-Apr-2025 | - | 81 | 60 | |
quantizer/ | H | 25-Apr-2025 | - | 488 | 370 | |
runtime/ | H | 25-Apr-2025 | - | 4,452 | 2,105 | |
scripts/ | H | 25-Apr-2025 | - | 119 | 75 | |
CMakeLists.txt | H A D | 25-Apr-2025 | 1.6 KiB | 50 | 44 | |
README.md | H A D | 25-Apr-2025 | 3.5 KiB | 79 | 55 | |
__init__.py | H A D | 25-Apr-2025 | 229 | 6 | 4 | |
partitioner.py | H A D | 25-Apr-2025 | 3.6 KiB | 102 | 76 | |
preprocess.py | H A D | 25-Apr-2025 | 2.7 KiB | 74 | 56 | |
requirements.txt | H A D | 25-Apr-2025 | 86 | 9 | 8 |
README.md
1# MediaTek Backend on ExecuTorch 2MediaTek backend empowers ExecuTorch to speed up PyTorch models on edge devices that equips with MediaTek Neuron Processing Unit (NPU). This document offers a step-by-step guide to set up the build environment for the MediaTek ExecuTorch libraries. 3 4## Supported Chips 5 6The examples provided in this repository are tested and supported on the following MediaTek chip: 7 8- MediaTek Dimensity 9300 (D9300) 9 10## Build Instructions 11 12### Prerequisites 13 14Before you begin, ensure you have the following prerequisites installed and configured: 15 16#### 1. Buck2 Build Tool 17 18- **Download Buck2**: Obtain Buck2 from the official [releases page](https://github.com/facebook/buck2/releases/tag/2024-02-01). 19- **Add to PATH**: Extract the downloaded file and add the directory to your system's `$PATH` environment variable. 20 ```bash 21 export PATH=<path_to_buck>:$PATH 22 ``` 23 24#### 2. Android NDK 25 26- **Download Android NDK**: Acquire the Android NDK version 26.3.11579264 from the [Android developer site](https://developer.android.com/ndk/downloads). 27- **Set NDK Path**: Ensure that the `$ANDROID_NDK` environment variable is set to the path where the NDK is located. 28 ```bash 29 export ANDROID_NDK=<path_to_android_ndk> 30 ``` 31 32#### 3. MediaTek ExecuTorch Libraries 33 34Download [NeuroPilot Express SDK](https://neuropilot.mediatek.com/resources/public/npexpress/en/docs/npexpress) from MediaTek's NeuroPilot portal: 35 36- `libneuronusdk_adapter.mtk.so`: This universal SDK contains the implementation required for executing target-dependent code on the MediaTek chip. 37- `libneuron_buffer_allocator.so`: This utility library is designed for allocating DMA buffers necessary for model inference. 38- `mtk_converter-8.8.0.dev20240723+public.d1467db9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl`: This library preprocess the model into a MediaTek representation. 39- `mtk_neuron-8.2.2-py3-none-linux_x86_64.whl`: This library converts the model to binaries. 40 41### Setup 42 43Follow the steps below to setup your build environment: 44 451. **Setup ExecuTorch Environment**: Refer to the [Setting up ExecuTorch](https://pytorch.org/executorch/stable/getting-started-setup) guide for detailed instructions on setting up the ExecuTorch environment. 46 472. **Setup MediaTek Backend Environment** 48- Install the dependent libs. Ensure that you are inside backends/mediatek/ directory 49 ```bash 50 pip3 install -r requirements.txt 51 ``` 52- Install the two .whl downloaded from NeuroPilot Portal 53 ```bash 54 pip3 install mtk_neuron-8.2.2-py3-none-linux_x86_64.whl 55 pip3 install mtk_converter-8.8.0.dev20240723+public.d1467db9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl 56 ``` 57- Set evironment variables for building backend 58 ```bash 59 export NEURON_BUFFER_ALLOCATOR_LIB=<path_to_buffer_allocator> 60 ``` 61 62### Build 631. Navigate to `scripts/` directory. 64 652. **Build MediaTek Backend**: Once the prerequisites are in place, run the `mtk_build.sh` script to start the build process, MediaTek backend will be built under `cmake-android-out/backends/` as `libneuron_backend.so` 66 67 ```bash 68 ./mtk_build.sh 69 ``` 70 71### Run 72 731. **Push MediaTek universal SDK and MediaTek backend to the device**: push `libneuronusdk_adapter.mtk.so` and `libneuron_backend.so` to the phone and export it to the `$LD_LIBRARY_PATH` environment variable before executing ExecuTorch with MediaTek backend. 74 75 ```bash 76 export LD_LIBRARY_PATH=<path_to_usdk>:<path_to_neuron_backend>:$LD_LIBRARY_PATH 77 ``` 78 79Please refer to `executorch/examples/mediatek/` for export and execution examples of various of models.