-
Notifications
You must be signed in to change notification settings - Fork 1
Cy add doc #1
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
base: main
Are you sure you want to change the base?
Cy add doc #1
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| # Getting Started on Linux with Cross-Compilation | ||
|
|
||
| <!-- | ||
| Notes to those updating this guide: | ||
|
|
||
| * This document should be __simple__ and cover essential items only. | ||
| Notes for optional components should go in separate files. | ||
| --> | ||
|
|
||
| This guide walks through cross-compiling IREE core runtime towards the embedded | ||
| Linux platform. Cross-compiling IREE compilers is not supported at the moment. | ||
|
|
||
| Cross-compilation involves both a *host* platform and a *target* platform. One | ||
| invokes compiler toolchains on the host platform to generate libraries and | ||
|
Comment on lines
+13
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggest: "The compiler toolchain on the host platform is used to generate..." |
||
| executables that can be run on the target platform. | ||
|
|
||
| The following steps will use aarch64 as the embedded platform. These steps has | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "have" instead of "has" |
||
| been tested on Ubuntu 18.04. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| ### Set up host development environment | ||
|
|
||
| The host platform should have been set up for developing IREE. Please make sure | ||
| you have followed the steps for | ||
| [Linux](./getting_started_linux_cmake.md). | ||
|
|
||
| ### Install GCC/G++-10 Cross Toolchain | ||
|
|
||
| If Ubuntu version is eariler than Ubuntu 20.04, we need to add apt-repository | ||
| entry for newer gcc/g++. | ||
|
|
||
| ```shell | ||
| # Again, this is not required for Ubuntu 20.04 | ||
| $ sudo add-apt-repository ppa:ubuntu-toolchain-r/test | ||
| $ sudo vi /etc/apt/sources.list | ||
| # add this line | ||
| deb http://de.archive.ubuntu.com/ubuntu groovy main | ||
| ``` | ||
|
|
||
| Install gcc/g++-10 | ||
|
|
||
| ```shell | ||
| $ sudo apt-get update | ||
| $ sudo apt install gcc-10 g++-10 | ||
| $ sudo apt install gcc-10-aarch64-linux-gnu g++-10-aarch64-linux-gnu | ||
| ``` | ||
|
|
||
| ### Create CMake Cross-Toolchain File | ||
|
|
||
| Create cmake cross-toolchain file. We use aarch64 as an example. | ||
|
|
||
| ```shell | ||
| $ vi aarch64-toolchain.cmake | ||
| ``` | ||
|
|
||
| Then copy-paste the following: | ||
|
|
||
| ```cmake | ||
| set(CMAKE_SYSTEM_NAME Linux) | ||
| set(CMAKE_SYSTEM_PROCESSOR aarch64) | ||
|
|
||
| set(CMAKE_C_COMPILER "aarch64-linux-gnu-gcc-10") | ||
| set(CMAKE_CXX_COMPILER "aarch64-linux-gnu-g++-10") | ||
|
|
||
| set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) | ||
| set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) | ||
| set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) | ||
|
|
||
| set(CMAKE_C_FLAGS "-march=armv8-a") | ||
| set(CMAKE_CXX_FLAGS "-march=armv8-a") | ||
| ``` | ||
|
|
||
| ## Configure and Build | ||
|
|
||
| ### Configure on Linux | ||
|
|
||
| ```shell | ||
| $ cmake -G Ninja /path/to/iree \ | ||
| -DCMAKE_TOOLCHAIN_FILE=aarch64-toolchain.cmake \ | ||
| -B build-aarch64 \ | ||
| -DIREE_BUILD_COMPILER=OFF -DIREE_BUILD_SAMPLES=OFF \ | ||
| -DIREE_HOST_C_COMPILER=/usr/bin/gcc-10 \ | ||
| -DIREE_HOST_CXX_COMPILER=/usr/bin/g++-10 | ||
| ``` | ||
|
|
||
| ### Build | ||
|
|
||
| ```shell | ||
| $ cmake --build build-aarch64/ | ||
| ``` | ||
|
|
||
| ## Test on Embedded Device | ||
|
|
||
| Translate a source MLIR into IREE module: | ||
|
|
||
| ```shell | ||
| # Assuming in IREE source root | ||
| $ build-aarch64/host/bin/iree-translate \ | ||
| -iree-mlir-to-vm-bytecode-module \ | ||
| -iree-hal-target-backends=vmla \ | ||
| iree/tools/test/simple.mlir \ | ||
| -o /tmp/simple-vmla.vmfb | ||
| ``` | ||
|
|
||
| Then copy the IREE runtime executable and module to the device: | ||
|
|
||
| ```shell | ||
| $ scp build-aarch64/iree/tools/iree-run-module ${device}:~ | ||
| $ scp /tmp/simple-vulkan.vmfb ${device}:~ | ||
| ``` | ||
|
|
||
| Log into device: | ||
|
|
||
| ```shell | ||
| $ ssh ${device} | ||
|
|
||
| aarch64-ubuntu $ ./iree-run-module -driver=vmla \ | ||
| -input_file=simple-vmla.vmfb \ | ||
| -entry_function=abs \ | ||
| -inputs="i32=-5" | ||
|
|
||
| EXEC @abs | ||
| i32=5 | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,160 @@ | ||
| # Getting Started on Linux with Qemu-User | ||
|
|
||
| <!-- | ||
| Notes to those updating this guide: | ||
|
|
||
| * This document should be __simple__ and cover essential items only. | ||
| Notes for optional components should go in separate files. | ||
| --> | ||
|
|
||
| This guide walks through using qemu-user to build the core compiler and runtime | ||
| parts of IREE towards the embedded linux platform. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggest: "for an" instead of "towards the" |
||
|
|
||
| The following steps will use aarch64 as the embedded platform. These steps has | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "have" instead of "has" |
||
| been tested on Ubuntu 18.04. It may take around 7 hours to build everything on | ||
| the x86 machines with 8 hardware threads running on 3.4 GHz + 16 GB RAM. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| ### Install Qemu User | ||
|
|
||
| Install qemu-user to run aarch64 based rootfs (root file system). | ||
|
|
||
| ```shell | ||
| $ sudo apt install qemu-user-static | ||
| ``` | ||
|
|
||
| ### Prepare AArch64 Based Ubuntu Rootfs | ||
|
|
||
| Download aarch64 ubuntu-base rootfs from official site and use sudo to untar it | ||
| in ubuntu-18.04-arm64 foler. `sudo` is required here since there are special | ||
| device node files which need to be created under root permission. | ||
|
|
||
| ```shell | ||
| $ export ROOTFS=$PWD | ||
| $ wget http://cdimage.ubuntu.com/ubuntu-base/releases/18.04/release/ubuntu-base-18.04-base-arm64.tar.gz | ||
| $ mkdir ubuntu-18.04-arm64 && cd ubuntu-18.04-arm64 | ||
| $ sudo tar -xf ../ubuntu-base-18.04-base-arm64.tar.gz -C ./ | ||
| ``` | ||
|
|
||
| Copy `qemu-aarch64-static` to the aarch64 rootfs for executing aarch64 | ||
| binaries on the host x86. Copy `resolv.conf` to the aarch64 rootfs for network | ||
| access. | ||
|
|
||
| ```shell | ||
| $ sudo cp /usr/bin/qemu-aarch64-static $ROOTFS/usr/bin/ | ||
| $ sudo cp /etc/resolv.conf $ROOTFS/etc | ||
| ``` | ||
|
|
||
| ### Prepare Folders Shared between Host and Rootfs | ||
|
|
||
| It is very convenient to have some shared folders between the host and the | ||
| aarch64 rootfs, this example creates iree source and build folder on the host, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe a full-stop instead of a comma. I.e. "...rootfs. This example creates..." There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IREE instead of iree? Some places in the file have it capitalised, some don't. |
||
| then bind it to the aarch64 rootfs. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggest: "binds" instead of "bind" |
||
|
|
||
| ```shell | ||
| $ sudo mkdir -p $ROOTFS/path/to/iree | ||
| $ sudo mkdir -p $ROOTFS/path/to/iree-build | ||
| $ sudo mount --bind /path/to/iree $ROOTFS/path/to/iree | ||
| $ sudo mount --bind /path/to/iree-build $ROOTFS/path/to/iree-build | ||
| ``` | ||
|
|
||
| ### Bind System Nodes to Aarch64 Rootfs, then Chroot | ||
|
|
||
| Bind system nodes and start emulating aarch64 on host. | ||
|
|
||
| ```shell | ||
| $ sudo mount --bind /proc proc | ||
| $ sudo mount --bind /sys sys | ||
| $ sudo mount --bind /dev dev | ||
| $ sudo chroot $ROOTFS | ||
| ``` | ||
|
|
||
| ## Setup Build Environment for Aarch64 Rootfs | ||
|
|
||
| ```shell | ||
| # apt-get update | ||
| # apt-get install build-essential wget python3 git ninja-build | ||
| ``` | ||
|
|
||
| ### Install CMake | ||
|
|
||
| IREE uses CMake version `>= 3.13`, default installed cmake for ubuntu 18.04 is | ||
| older than 3.13, so build and install newer version cmake for the aarch64 | ||
| rootfs. This example uses cmake 3.15.2. | ||
|
|
||
| ```shell | ||
| # wget https://github.com/Kitware/CMake/releases/download/v3.15.2/cmake-3.15.2.tar.gz | ||
| # tar -zxf cmake-3.15.2.tar.gz | ||
| # cd cmake-3.15.2 | ||
| # ./bootstrap | ||
| # make -j8 && sudo make install | ||
| ``` | ||
|
|
||
| ### Install a Compiler | ||
|
|
||
| We recommend Clang. GCC version `>= 9` is also supported. | ||
|
|
||
| ```shell | ||
| # wget https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.0/clang+llvm-10.0.0-aarch64-linux-gnu.tar.xz | ||
| # tar -xf clang+llvm-10.0.0-aarch64-linux-gnu.tar.xz | ||
| ``` | ||
|
|
||
| ### [Optional] Prepare Vulkan | ||
|
|
||
| Assume vulkan include and lib are available, then create a folder and copy | ||
| header and lib into this folder. | ||
|
|
||
| ```shell | ||
| # mkdir vulkan-sdk | ||
| # cp -r /path/to/vulkan/include vulkan-sdk | ||
| # cp -r /path/to/vulkan/lib vulkan-sdk | ||
| ``` | ||
|
|
||
| The vulkan-sdk folder struct | ||
| ```shell | ||
| vulkan-sdk/ | ||
| ├── include | ||
| │ └── vulkan | ||
| │ ├── vk_android_native_buffer | ||
| ... | ||
| │ ├── vk_android_native_buffer.h | ||
| ... | ||
| └── lib | ||
| └── libvulkan.so | ||
| ``` | ||
|
|
||
| ### Build | ||
|
|
||
| Build IREE with lld linker and experimental on. | ||
|
|
||
| ```shell | ||
| # export IREE_LLVMAOT_LINKER_PATH="$(which ld)" | ||
| # export VULKAN_SDK=/path/to/vulkan-sdk | ||
| # cmake -G Ninja /path/to/iree \ | ||
| -B /path/to/iree-build/build-aarch64 \ | ||
| -DIREE_BUILD_EXPERIMENTAL=ON \ | ||
| -DIREE_ENABLE_LLD=ON \ | ||
| -DCMAKE_C_COMPILER=./clang+llvm-10.0.0-aarch64-linux-gnu/bin/clang \ | ||
| -DCMAKE_CXX_COMPILER=./clang+llvm-10.0.0-aarch64-linux-gnu/bin/clang++ | ||
| # cmake --build /path/to/iree-build/build-aarch64 | ||
| ``` | ||
|
|
||
| ## What's next? | ||
|
|
||
| ### Take a Look Around | ||
|
|
||
| Check out the contents of the 'experimental test' build directory: | ||
|
|
||
| ```shell | ||
| # cd /path/to/iree-build/build-aarch64 | ||
| # ls experimental/ModelBuilder/test | ||
| ``` | ||
|
|
||
| Scp these tests and `third_party/llvm-project/llvm/lib/libvulkan-runtime-wrappers.so.12git` | ||
| to real device, then run it. | ||
|
|
||
| ```shell | ||
| $ ./bench-matmul-vector-jit | ||
| $ ./test-matmul-vulkan | ||
| ``` | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest: "for an embedded Linux platform"