* Initial commit for OpenVINO Execution Provider OpenVINO Execution Provider provides the interface for ONNX Runtime applications to access Intel's hardware accelerators using Intel's OpenVINO Toolkit. * Fixed bug in GetCapability to disable custom ops Signed-off-by: suryasidd <surya.siddharth.pemmaraju@intel.com> * Added OPENVINO ci pipeline Added new pipeline for openvino provider, made changes to support the docker build and onnxruntime build with openvino. Signed-off-by: Luis Daniel Castellanos <luis.daniel.castellanos@intel.com> * Enabled all unit tests for OpenVINO EP Signed-off-by: suryasidd <surya.siddharth.pemmaraju@intel.com> * Fixed syntax issue in run_docker_build.sh file * Added missing default OPENVINO_VERSION Default value for OPENVINO_VERSION env was missing causing the build to fail * Added install Model Optimizer deps step * Fixed python unit tests and some tests from onnx_backend_test_series Signed-off-by: suryasidd <surya.siddharth.pemmaraju@intel.com> * Fixed indentation bug Signed-off-by: suryasidd <surya.siddharth.pemmaraju@intel.com> * Disabled some of the python backend tests for OpenVINO Signed-off-by: suryasidd <surya.siddharth.pemmaraju@intel.com> * Disabled some model tests Signed-off-by: suryasidd <surya.siddharth.pemmaraju@intel.com> * Remove Duplicate checks for openvino in build.py Signed-off-by: suryasidd <surya.siddharth.pemmaraju@intel.com> * Modified GetCapability for FP16 Signed-off-by: suryasidd <surya.siddharth.pemmaraju@intel.com> * Disabled GPU FP32 tests that are not supported Signed-off-by: suryasidd <surya.siddharth.pemmaraju@intel.com> * Convert modelProto to string and use it in compile Signed-off-by: suryasidd <surya.siddharth.pemmaraju@intel.com> * Pass byte-array input args to MO * Serialized ModelProto passed in-memory to MO ModelOptimizer python module receives the serialized ModelProto in-memory. Uses appropriate ONNX function to load the serialized bytes. * Make Py_Finalize compatible with older python versions Also, remove pFunc unassigned variable possibility. * Fallback if input dims of Matmul is greater than 2 Signed-off-by: suryasidd <surya.siddharth.pemmaraju@intel.com> * fixup: Device #define syntax * Updated the documentation Signed-off-by: suryasidd <surya.siddharth.pemmaraju@intel.com> * Enable dynamic dim value * removed commented out code * Added Dockerfile for openvino EP Updated instructions on dockerfiles/README.md file Signed-off-by: Luis Daniel Castellanos <luis.daniel.castellanos@intel.com> * Disabled fp16_inception_v1 test Signed-off-by: suryasidd <surya.siddharth.pemmaraju@intel.com> * Code formatting with clang-format Uses style from the .clang-format file in root directory. * fixup: docker tag and build error fixes * Heuristics to automatically detect batching Distributes slices from batch into parallel infer-request objects. * Handle disabled tests in GetCapability Signed-off-by: suryasidd <surya.siddharth.pemmaraju@intel.com> * Disabled average pool and max pool if ceil_mode is 1 Also dilations are not supported if they are greater than 1 Signed-off-by: suryasidd <surya.siddharth.pemmaraju@intel.com> * Disabled Unsqueeze int32 test Signed-off-by: suryasidd <surya.siddharth.pemmaraju@intel.com> * changes to fix output results bug * Disabled a few C++ unit tests for MYRIAD FP16 Signed-off-by: suryasidd <surya.siddharth.pemmaraju@intel.com> * Manually revert '9fe162bb Enable dynamic dim value' Reverts compile time setting of dynamic shape Reverting manually due to significantly huge auto-revert conflicts. * Fixed unused variable warning Signed-off-by: suryasidd <surya.siddharth.pemmaraju@intel.com> * Disabled Mul test for GPU_FP16 due to accuracy issue Signed-off-by: suryasidd <surya.siddharth.pemmaraju@intel.com> * VPU documentation update * Disabled inception_v1 for MYRIAD and HDDL *Also disabled few C++ accuracy tests for HDDL Signed-off-by: suryasidd <surya.siddharth.pemmaraju@intel.com> * updates from upstream * use the new CustomOpApis for I/O interfacing * Pass initializers as subgraph meta-def inputs in GetCapability() Requirement due to API changes introduced with PR# 1019. * Remove obsolete functions * Save indexes of graph inputs from fused_node info Both inputs and initializers are passed as data inputs to the infer function. To identify only inputs among them, save thier index info from fused_node in Compile function. * Documentation changes to enable VPU * Fix VPU related changes in documentation * Fix minor changes in documentation * Fix VPU related changes in documentation * Use Node.In/OutputDefs() to track graph inputs and outputs. Don't use graph_viewer's GetInputs() or GetInputsIncludingInitializers(). * Permit "SAME_UPPER" auto_pad attribute from MaxPool * Disabled fp16_tiny_yolov2 in onnx model tests * Updated documentation to include configuration guides for myriad and hddl Signed-off-by: suryasidd <surya.siddharth.pemmaraju@intel.com> * Use 8 Infer requests only for VAD-R * disable debug prints * Clang-format source files * Updated BUILD.md with OpenVINO R5 links Signed-off-by: suryasidd <surya.siddharth.pemmaraju@intel.com> * Disabled same upper python tests Signed-off-by: suryasidd <surya.siddharth.pemmaraju@intel.com> * Update test exclusion syntax * Change path of install_onnx.sh Signed-off-by: suryasidd <surya.siddharth.pemmaraju@intel.com> * Disable tiny_yolov2 in broken tests Signed-off-by: suryasidd <surya.siddharth.pemmaraju@intel.com> * Revert "Change path of install_onnx.sh" This reverts commit ba9db165f3be430f2aff1ef413299ed04637196a. This change is only required for Intel internal CI pipeline until the settings are matched with the upstream's CI pipeline. * Added debug statements for debugging CI error Signed-off-by: suryasidd <surya.siddharth.pemmaraju@intel.com> * Add --build_wheel to linux openvino pipeline Signed-off-by: suryasidd <surya.siddharth.pemmaraju@intel.com> * Added -v option to onnx_test_runner for debugging Signed-off-by: suryasidd <surya.siddharth.pemmaraju@intel.com> * Removed path change patch Signed-off-by: suryasidd <surya.siddharth.pemmaraju@intel.com> * Added -c 1 to onnx_test_runner Signed-off-by: suryasidd <surya.siddharth.pemmaraju@intel.com> * Refactor MO python invocation in separate function Cleans up Model Optimizer python invocation check and conversion logic. Invokes MO only once in GetCapability() and passes the IR strings (xml and bin) to the Compiler as meta-def attributes. * Add comments * code cleanup and comments * Code cleanup for GetCapability Signed-off-by: suryasidd <surya.siddharth.pemmaraju@intel.com> * Removed unnecessary files Signed-off-by: suryasidd <surya.siddharth.pemmaraju@intel.com> * Revert "Added -v option to onnx_test_runner for debugging" This reverts commit d1dd70938a94d648df1a1dbbc2e48d0b97e49ec8. * Revert "Added debug statements for debugging CI error" This reverts commit b86d41afed2aa29c3508155d6f9c8d3a7263cc60. * incorporate Status Code changes * ComputeFunc returns Status::OK() on success * Use test names to disable tests for MYRIAD and VAD-R Signed-off-by: suryasidd <surya.siddharth.pemmaraju@intel.com> * Rename local identifiers from CNNNetwork to OpenVINO network CNNNetwork is an OpenVINO's API class that represents more than just convolutional neural networks (CNNs). Renaming helps to avoid confusion that the API's only support CNN type models. * Added error message if building on windows * Removed duplicate option in Cmake * Removed unnecessary parameters in activation_opt_test Signed-off-by: suryasidd <surya.siddharth.pemmaraju@intel.com> * Refactor Map search and access logic for efficiently and cleanliness. * use C++ style casts * Use os.path.join for python directory path operations * use C++ style casts * EP classes should use onnxruntime namespace * Clean up fixes from PR comments * Don't explicitly shutdown Py interpreter * Remove debug print statements Prints will be re-enabled later with a logging mechanism with debug/verbose printing options. * Decrement ref counts for used pyObjects * Restore build instructions for other compilers Content under the "Using other compilers" section has been accidentally deleted by a previous commit. Restoring back that content from the latest upstream repo. * CMake code cleanup Code clean up, commenting and formatting of CMake code. * Don't pass the unused device_info parameter to OpenVINOGraph ctor. * Add support for multiple I/O data types Adds support for the following tensor data types for graph inputs and outputs: 1) float 2) float16 3) int32 4) int16 5) int8 6) uint16 7) uint8 * cleanup setup.py module list definition * Deduce index of input using tracked input index map Ignores initializers in case they are ordered before inputs. * Removed debug statement in MO code Signed-off-by: suryasidd <surya.siddharth.pemmaraju@intel.com> * PR feedback * Removed per_sample_tolerance for openvino * Removed unnecessary disabled tests Signed-off-by: suryasidd <surya.siddharth.pemmaraju@intel.com> * Removed debug function Signed-off-by: suryasidd <surya.siddharth.pemmaraju@intel.com> * Disabled tiny_yolo_v2 due to accuracy issues Signed-off-by: suryasidd <surya.siddharth.pemmaraju@intel.com> * Changed the disabled reason for broken tests Signed-off-by: suryasidd <surya.siddharth.pemmaraju@intel.com> * Disabled Reshape with no input Signed-off-by: suryasidd <surya.siddharth.pemmaraju@intel.com> * Python formatting with Autopep8 * Minor fix for MYRIAD devices * Added zero dimension check *Removed setting batch size for the network Signed-off-by: suryasidd <surya.siddharth.pemmaraju@intel.com> * Set the threshold to larger value for MNIST Signed-off-by: suryasidd <surya.siddharth.pemmaraju@intel.com> * Removed setting higher threshold in provider_test_utils Signed-off-by: suryasidd <surya.siddharth.pemmaraju@intel.com> * Check for --use_openvino in python wheel setup.py Add openvino modules to the setup script for building the wheel package only for --use_openvino a build option. * Removed nullptr checks for GetNode() Signed-off-by: suryasidd <surya.siddharth.pemmaraju@intel.com>
20 KiB
Build ONNX Runtime
Supported architectures
| x86_32 | x86_64 | ARM32v7 | ARM64 | |
|---|---|---|---|---|
| Windows | YES | YES | YES | YES |
| Linux | YES | YES | YES | YES |
| Mac OS X | NO | YES | NO | NO |
Supported dev environments
| OS | Supports CPU | Supports GPU | Notes |
|---|---|---|---|
| Windows 10 | YES | YES | Must use VS 2017 or the latest VS2015 |
| Windows 10 Subsystem for Linux |
YES | NO | |
| Ubuntu 16.x | YES | YES | Also supported on ARM32v7 (experimental) |
- Red Hat Enterprise Linux and CentOS are not supported.
- Other version of Ubuntu might work but we don't support them officially.
- GCC 4.x and below are not supported.
OS/Compiler Matrix:
| OS/Compiler | Supports VC | Supports GCC |
|---|---|---|
| Windows 10 | YES | Not tested |
| Linux | NO | YES(gcc>=5.0) |
ONNX Runtime python binding only supports Python 3.5, 3.6 and 3.7.
Build
- Checkout the source tree:
git clone --recursive https://github.com/Microsoft/onnxruntime cd onnxruntime - Install cmake-3.13 or better from https://cmake.org/download/.
- (optional) Install protobuf 3.6.1 from source code (cmake/external/protobuf). CMake flag protobuf_BUILD_SHARED_LIBS must be turned OFF on Windows and turned ON on Linux. After the installation, you should have the 'protoc' executable in your PATH. On Linux it is recommended to run
ldconfigto make sure protobuf libraries are found. - If you installed your protobuf in a non standard location it would be helpful on Linux build to set the following env var:
export CMAKE_ARGS="-DONNX_CUSTOM_PROTOC_EXECUTABLE=full path to protoc"so ONNX build can find it. On Linux also runldconfig <protobuf lib folder path>so the linker can find protobuf libraries. - (optional) Install onnx from source code (cmake/external/onnx)
export ONNX_ML=1 python3 setup.py bdist_wheel pip3 install --upgrade dist/*.whl - Run
./build.sh --config RelWithDebInfo --build_wheelfor Linux (orbuild.bat --config RelWithDebInfo --build_wheelfor Windows). Upon successful build you should be able to find the wheel underdistfolder.
The build script runs all unit tests by default (for native builds and skips tests by default for cross-compiled builds).
The complete list of build options can be found by running ./build.sh (or ./build.bat) --help
Build x86
- For Windows, just add --x86 argument when launching build.bat
- For Linux, it must be built out of a x86 os, --x86 argument also needs be specified to build.sh
Build ONNX Runtime Server on Linux
- In the ONNX Runtime root folder, run
./build.sh --config RelWithDebInfo --build_server --use_openmp --parallel
Build/Test Flavors for CI
CI Build Environments
| Build Job Name | Environment | Dependency | Test Coverage | Scripts |
|---|---|---|---|---|
| Linux_CI_Dev | Ubuntu 16.04 | python=3.5 | Unit tests; ONNXModelZoo | script |
| Linux_CI_GPU_Dev | Ubuntu 16.04 | python=3.5; nvidia-docker | Unit tests; ONNXModelZoo | script |
| Windows_CI_Dev | Windows Server 2016 | python=3.5 | Unit tests; ONNXModelZoo | script |
| Windows_CI_GPU_Dev | Windows Server 2016 | cuda=9.1; cudnn=7.1; python=3.5 | Unit tests; ONNXModelZoo | script |
Additional Build Flavors
The complete list of build flavors can be seen by running ./build.sh --help or ./build.bat --help. Here are some common flavors.
Windows CUDA Build
ONNX Runtime supports CUDA builds. You will need to download and install CUDA and CUDNN.
ONNX Runtime is built and tested with CUDA 9.1 and CUDNN 7.1 using the Visual Studio 2017 14.11 toolset (i.e. Visual Studio 2017 v15.3). CUDA versions from 9.1 up to 10.0, and CUDNN versions from 7.1 up to 7.4 should also work with Visual Studio 2017.
- The path to the CUDA installation must be provided via the CUDA_PATH environment variable, or the
--cuda_home parameter. - The path to the CUDNN installation (include the
cudafolder in the path) must be provided via the CUDNN_PATH environment variable, or--cudnn_home parameter. The CUDNN path should containbin,includeandlibdirectories. - The path to the CUDNN bin directory must be added to the PATH environment variable so that cudnn64_7.dll is found.
You can build with:
./build.sh --use_cuda --cudnn_home /usr --cuda_home /usr/local/cuda (Linux)
./build.bat --use_cuda --cudnn_home <cudnn home path> --cuda_home <cuda home path> (Windows)
Depending on compatibility between the CUDA, CUDNN, and Visual Studio 2017 versions you are using, you may need to explicitly install an earlier version of the MSVC toolset.
- CUDA 10.0 is known to work with toolsets from 14.11 up to 14.16 (Visual Studio 2017 15.9), and should continue to work with future Visual Studio versions
- CUDA 9.2 is known to work with the 14.11 MSVC toolset (Visual Studio 15.3 and 15.4)
To install the 14.11 MSVC toolset, see https://blogs.msdn.microsoft.com/vcblog/2017/11/15/side-by-side-minor-version-msvc-toolsets-in-visual-studio-2017/
To use the 14.11 toolset with a later version of Visual Studio 2017 you have two options:
-
Setup the Visual Studio environment variables to point to the 14.11 toolset by running vcvarsall.bat, prior to running the build script
- e.g. if you have VS2017 Enterprise, an x64 build would use the following command
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" amd64 -vcvars_ver=14.11 - For convenience, build.amd64.1411.bat will do this and can be used in the same way as build.bat.
- e.g.
.\build.amd64.1411.bat --use_cuda
- e.g.
- e.g. if you have VS2017 Enterprise, an x64 build would use the following command
-
Alternatively if you have CMake 3.12 or later you can specify the toolset version via the
--msvc_toolsetbuild script parameter.- e.g.
.\build.bat --msvc_toolset 14.11
- e.g.
Side note: If you have multiple versions of CUDA installed on a Windows machine and are building with Visual Studio, CMake will use the build files for the highest version of CUDA it finds in the BuildCustomization folder. e.g. C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\VC\VCTargets\BuildCustomizations. If you want to build with an earlier version, you must temporarily remove the 'CUDA x.y.*' files for later versions from this directory.
MKL-DNN/MKLML
To build ONNX Runtime with MKL-DNN support, build it with ./build.sh --use_mkldnn
To build ONNX Runtime using MKL-DNN built with dependency on MKL small libraries, build it with ./build.sh --use_mkldnn --use_mklml
nGraph
ONNX runtime with nGraph as an execution provider (released as preview) can be built on Linux as follows : ./build.sh --use_ngraph. Similarly, on Windows use .\build.bat --use_ngraph.
TensorRT
ONNX Runtime supports the TensorRT execution provider (released as preview). You will need to download and install CUDA, CUDNN and TensorRT.
The TensorRT execution provider for ONNX Runtime is built and tested with CUDA 9.0/CUDA 10.0, CUDNN 7.1 and TensorRT 5.0.2.6.
- The path to the CUDA installation must be provided via the CUDA_PATH environment variable, or the
--cuda_home parameter. The CUDA path should containbin,includeandlibdirectories. - The path to the CUDA
bindirectory must be added to the PATH environment variable so thatnvccis found. - The path to the CUDNN installation (path to folder that contains libcudnn.so) must be provided via the CUDNN_PATH environment variable, or
--cudnn_home parameter. - The path to TensorRT installation must be provided via the
--tensorrt_home parameter.
You can build from source on Linux by using the following cmd from the onnxruntime directory:
./build.sh --cudnn_home <path to CUDNN e.g. /usr/lib/x86_64-linux-gnu/> --cuda_home <path to folder for CUDA e.g. /usr/local/cuda> --use_tensorrt --tensorrt_home <path to TensorRT home> (Linux)
OpenVINO Build
ONNX Runtime supports OpenVINO Execution Provider to enable deep learning inference using Intel® OpenVINOTM Toolkit. This execution provider supports several Intel hardware device types - CPU, integrated GPU, Intel® MovidiusTM VPUs and Intel® Vision accelerator Design with 8 Intel MovidiusTM MyriadX VPUs.
The OpenVINO Execution Provider can be built using the following commands:
-
Install the OpenVINO 2018 R5.0.1 release along with its dependencies from (https://software.intel.com/en-us/openvino-toolkit).
-
Install the model optimizer prerequisites for ONNX by running
<openvino_install_dir>/deployment_tools/model_optimizer/install_prerequisites/install_prerequisites_onnx.sh -
Initialize the OpenVINO environment by running the setupvars.sh in
<openvino_install_directory>/binusing the below command:source setupvars.sh -
To configure Intel® Processor Graphics(GPU), please follow the installation steps from (https://docs.openvinotoolkit.org/2018_R5/_docs_install_guides_installing_openvino_linux.html#GPU-steps)
-
To configure Intel® MovidiusTM USB, please follow the getting started guide from (https://docs.openvinotoolkit.org/2018_R5/_docs_install_guides_installing_openvino_linux.html#Movidius-steps)
-
To configure Intel® Vision Accelerator Design based on 8 MovidiusTM MyriadX VPUs, please follow the configuration guide from (https://docs.openvinotoolkit.org/2018_R5/_docs_install_guides_installing_openvino_linux.html#Vision-Accelerator-Design-steps)
-
Build ONNX Runtime using the below command.
./build.sh --config RelWithDebInfo --use_openvino <hardware_option>--use_openvino: Builds the OpenVINO Execution Provider in ONNX Runtime.<hardware_option>: Specifies the hardware target for building OpenVINO Execution Provider. Below are the options for different Intel target devices.
| Hardware Option | Target Device |
|---|---|
CPU_FP32 |
Intel® CPUs |
GPU_FP32 |
Intel® Integrated Graphics |
GPU_FP16 |
Intel® Integrated Graphics with FP16 quantization of models |
MYRIAD_FP16 |
Intel® MovidiusTM USB sticks |
VAD-R_FP16 |
Intel® Vision Accelerator Design based on 8 MovidiusTM MyriadX VPUs |
For more information on OpenVINO Execution Provider's ONNX Layer support, Topology support, and Intel hardware enabled, please refer to the document OpenVINO-ExecutionProvider.md in $onnxruntime_root/docs/execution_providers
OpenBLAS
Windows
Instructions how to build OpenBLAS for windows can be found here https://github.com/xianyi/OpenBLAS/wiki/How-to-use-OpenBLAS-in-Microsoft-Visual-Studio#build-openblas-for-universal-windows-platform.
Once you have the OpenBLAS binaries, build ONNX Runtime with ./build.bat --use_openblas
Linux
For Linux (e.g. Ubuntu 16.04), install libopenblas-dev package
sudo apt-get install libopenblas-dev and build with ./build.sh --use_openblas
OpenMP
./build.sh --use_openmp (for Linux)
./build.bat --use_openmp (for Windows)
Build with Docker on Linux
Install Docker: https://docs.docker.com/install/
CPU
cd tools/ci_build/github/linux/docker
docker build -t onnxruntime_dev --build-arg OS_VERSION=16.04 -f Dockerfile.ubuntu .
docker run --rm -it onnxruntime_dev /bin/bash
GPU
If you need GPU support, please also install:
- nvidia driver. Before doing this please add
nomodeset rd.driver.blacklist=nouveauto your linux kernel boot parameters. - nvidia-docker2: Install doc
To test if your nvidia-docker works:
docker run --runtime=nvidia --rm nvidia/cuda nvidia-smi
Then build a docker image. We provided a sample for use:
cd tools/ci_build/github/linux/docker
docker build -t cuda_dev -f Dockerfile.ubuntu_gpu .
Then run it
./tools/ci_build/github/linux/run_dockerbuild.sh
ARM Builds
We have experimental support for Linux ARM builds. Windows on ARM is well tested.
Cross compiling for ARM with Docker (Linux/Windows - FASTER, RECOMMENDED)
This method allows you to compile using a desktop or cloud VM. This is much faster than compiling natively and avoids out-of-memory issues that may be encountered when on lower-powered ARM devices. The resulting ONNX Runtime Python wheel (.whl) file is then deployed to an ARM device where it can be invoked in Python 3 scripts.
The Dockerfile used in these instructions specifically targets Raspberry Pi 3/3+ running Raspbian Stretch. The same approach should work for other ARM devices, but may require some changes to the Dockerfile such as choosing a different base image (Line 0: FROM ...).
-
Install DockerCE on your development machine by following the instructions here
-
Create an empty local directory
mkdir onnx-build cd onnx-build -
Save the Dockerfile to your new directory
-
Run docker build
This will build all the dependencies first, then build ONNX Runtime and its Python bindings. This will take several hours.
docker build -t onnxruntime-arm32v7 -f Dockerfile.arm32v7 . -
Note the full path of the
.whlfile- Reported at the end of the build, after the
# Build Outputline. - It should follow the format
onnxruntime-0.3.0-cp35-cp35m-linux_armv7l.whl, but version number may have changed. You'll use this path to extract the wheel file later.
- Reported at the end of the build, after the
-
Check that the build succeeded
Upon completion, you should see an image tagged
onnxruntime-arm32v7in your list of docker images:docker images -
Extract the Python wheel file from the docker image
(Update the path/version of the
.whlfile with the one noted in step 5)docker create -ti --name onnxruntime_temp onnxruntime-arm32v7 bash docker cp onnxruntime_temp:/code/onnxruntime/build/Linux/MinSizeRel/dist/onnxruntime-0.3.0-cp35-cp35m-linux_armv7l.whl . docker rm -fv onnxruntime_tempThis will save a copy of the wheel file,
onnxruntime-0.3.0-cp35-cp35m-linux_armv7l.whl, to your working directory on your host machine. -
Copy the wheel file (
onnxruntime-0.3.0-cp35-cp35m-linux_armv7l.whl) to your Raspberry Pi or other ARM device -
On device, install the ONNX Runtime wheel file
sudo apt-get update sudo apt-get install -y python3 python3-pip pip3 install numpy # Install ONNX Runtime # Important: Update path/version to match the name and location of your .whl file pip3 install onnxruntime-0.3.0-cp35-cp35m-linux_armv7l.whl -
Test installation by following the instructions here
Cross compiling on Linux (without Docker)
-
Get the corresponding toolchain. For example, if your device is Raspberry Pi and the device os is Ubuntu 16.04, you may use gcc-linaro-6.3.1 from https://releases.linaro.org/components/toolchain/binaries
-
Setup env vars
export PATH=/opt/gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf/bin:$PATH export CC=arm-linux-gnueabihf-gcc export CXX=arm-linux-gnueabihf-g++ -
Get a pre-compiled protoc:
You may get it from https://github.com/protocolbuffers/protobuf/releases/download/v3.6.1/protoc-3.6.1-linux-x86_64.zip . Please unzip it after downloading.
-
(optional) Setup sysroot for enabling python extension. (TODO: will add details later)
-
Save the following content as tool.cmake
set(CMAKE_SYSTEM_NAME Linux) set(CMAKE_SYSTEM_PROCESSOR arm) set(CMAKE_CXX_COMPILER arm-linux-gnueabihf-c++) set(CMAKE_C_COMPILER arm-linux-gnueabihf-gcc) 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_FIND_ROOT_PATH_MODE_PACKAGE ONLY) -
Append
-DONNX_CUSTOM_PROTOC_EXECUTABLE=/path/to/protoc -DCMAKE_TOOLCHAIN_FILE=path/to/tool.cmaketo your cmake args, run cmake and make to build it.
Native compiling on Linux ARM device (SLOWER)
Docker build runs on a Raspberry Pi 3B with Raspbian Stretch Lite OS (Desktop version will run out memory when linking the .so file) will take 8-9 hours in total.
sudo apt-get update
sudo apt-get install -y \
sudo \
build-essential \
curl \
libcurl4-openssl-dev \
libssl-dev \
wget \
python3 \
python3-pip \
python3-dev \
git \
tar
pip3 install --upgrade pip
pip3 install --upgrade setuptools
pip3 install --upgrade wheel
pip3 install numpy
# Build the latest cmake
mkdir /code
cd /code
wget https://cmake.org/files/v3.12/cmake-3.12.3.tar.gz;
tar zxf cmake-3.12.3.tar.gz
cd /code/cmake-3.12.3
./configure --system-curl
make
sudo make install
# Prepare onnxruntime Repo
cd /code
git clone --recursive https://github.com/Microsoft/onnxruntime
# Start the basic build
cd /code/onnxruntime
./build.sh --config MinSizeRel --arm --update --build
# Build Shared Library
./build.sh --config MinSizeRel --arm --build_shared_lib
# Build Python Bindings and Wheel
./build.sh --config MinSizeRel --arm --enable_pybind --build_wheel
# Build Output
ls -l /code/onnxruntime/build/Linux/MinSizeRel/*.so
ls -l /code/onnxruntime/build/Linux/MinSizeRel/dist/*.whl
Cross compiling on Windows
Using Visual C++ compilers
-
Download and install Visual C++ compilers and libraries for ARM(64). If you have Visual Studio installed, please use the Visual Studio Installer (look under the section
Individual componentsafter choosing tomodifyVisual Studio) to download and install the corresponding ARM(64) compilers and libraries. -
Use
build.batand specify--armor--arm64as the build option to start building. Preferably useDeveloper Command Prompt for VSor make sure all the installed cross-compilers are findable from the command prompt being used to build using the PATH environmant variable.
Using other compilers
(TODO)
Android Builds
Cross compiling on Linux
-
Get Android NDK from https://developer.android.com/ndk/downloads. Please unzip it after downloading.
-
Get a pre-compiled protoc:
You may get it from https://github.com/protocolbuffers/protobuf/releases/download/v3.6.1/protoc-3.6.1-linux-x86_64.zip. Please unzip it after downloading.
-
Denote the unzip destination in step 1 as $ANDROID_NDK, append
-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake -DANDROID_ABI=arm64-v8a -DONNX_CUSTOM_PROTOC_EXECUTABLE=path/to/protocto your cmake args, run cmake and make to build it.
Note: For 32-bit devices, replace -DANDROID_ABI=arm64-v8a to -DANDROID_ABI=armeabi-v7a.