Skip to content

Commit

Permalink
Merge branch 'master' into java-api
Browse files Browse the repository at this point in the history
  • Loading branch information
shahasad authored Dec 10, 2019
2 parents 5b42825 + 41fc820 commit b4a79e6
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 22 deletions.
40 changes: 28 additions & 12 deletions BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ The complete list of build options can be found by running `./build.sh (or .\bui
* [Intel DNNL/MKL-ML](#DNNL-and-MKLML)
* [Intel nGraph](#nGraph)
* [Intel OpenVINO](#openvino)
* [Android NNAPI](#Android)
* [Android NNAPI](#Android-NNAPI)
* [Nuphar Model Compiler](#Nuphar)
* [DirectML](#DirectML)
Expand All @@ -111,6 +111,7 @@ The complete list of build options can be found by running `./build.sh (or .\bui
**Architectures**
* [x86](#x86)
* [ARM](#ARM)
* [Android](#Android)
---
Expand Down Expand Up @@ -276,18 +277,9 @@ For more information on OpenVINO Execution Provider's ONNX Layer support, To
---
### Android
#### Cross compiling on Linux
1. Get Android NDK from https://developer.android.com/ndk/downloads. Please unzip it after downloading.
### Android NNAPI
2. Get a pre-compiled protoc from [here](https://github.com/protocolbuffers/protobuf/releases/download/v3.6.1/protoc-3.6.1-linux-x86_64.zip). Please unzip it after downloading.
3. 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/protoc` to your cmake args, run cmake and make to build it.
#### Notes
* For 32-bit devices, replace `-DANDROID_ABI=arm64-v8a` with `-DANDROID_ABI=armeabi-v7a`.
See information on the NNAPI Execution Provider [here](./docs/execution_providers/NNAPI-ExecutionProvider.md).
---
Expand Down Expand Up @@ -540,3 +532,27 @@ ls -l /code/onnxruntime/build/Linux/MinSizeRel/dist/*.whl

2. Use `.\build.bat` and specify `--arm` or `--arm64` as the build option to start building. Preferably use `Developer Command Prompt for VS` or make sure all the installed cross-compilers are findable from the command prompt being used to build using the PATH environmant variable.

---

### Android

#### Pre-Requisites

Install Android NDK from https://developer.android.com/ndk/downloads

#### Build Instructions

##### Cross compiling on Windows

```bash
./build.bat --android --android_ndk_path <android ndk path> --android_abi <android abi, e.g., arm64-v8a (default) or armeabi-v7a> --android_api <android api level, e.g., 27 (default)>
```

##### Cross compiling on Linux

```bash
./build.sh --android --android_ndk_path <android ndk path> --android_abi <android abi, e.g., arm64-v8a (default) or armeabi-v7a> --android_api <android api level, e.g., 27 (default)>
```

If you want to use NNAPI Execution Provider on Android, see [docs/execution_providers/NNAPI-ExecutionProvider.md](/docs/execution_providers/NNAPI-ExecutionProvider.md).

6 changes: 6 additions & 0 deletions cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,12 @@ else()
add_library(protobuf::libprotobuf ALIAS libprotobuf-lite)
endif()
add_executable(protobuf::protoc ALIAS protoc)

if(UNIX AND onnxruntime_ENABLE_LTO)
#https://github.com/protocolbuffers/protobuf/issues/5923
target_link_options(protoc PRIVATE "-Wl,--no-as-needed")
endif()

include(protobuf_function.cmake)

if (onnxruntime_DISABLE_CONTRIB_OPS)
Expand Down
47 changes: 47 additions & 0 deletions docs/execution_providers/NNAPI-ExecutionProvider.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# NNAPI Execution Provider

[Android Neural Networks API (NNAPI)](https://developer.android.com/ndk/guides/neuralnetworks) is a unified interface to CPU, GPU, and NN accelerators on Android. It is supported by onnxruntime via [DNNLibrary](https://github.com/JDAI-CV/DNNLibrary).

## Minimum requirements

The NNAPI EP requires Android devices with Android 8.1 or higher.

## Build NNAPI EP

### Pre-Requisites

To build onnxruntime with NNAPI EP, install Android NDK first (see [BUILD.md](/BUILD.md#android))

### Build Instructions

The basic commands are following. There are also some other parameters for building the Android version. See [BUILD.md](/BUILD.md#android) for the details.

#### Cross compiling on Windows

```bash
./build.bat --android --android_ndk_path <android ndk path> --dnnlibrary
```

#### Cross compiling on Linux

```bash
./build.sh --android --android_ndk_path <android ndk path> --dnnlibrary
```

## Using NNAPI EP in C/C++

To use NNAPI EP for inferencing, please register it as below.
```
InferenceSession session_object{so};
session_object.RegisterExecutionProvider(std::make_unique<::onnxruntime::NnapiExecutionProvider>());
status = session_object.Load(model_file_name);
```
The C API details are [here](../C_API.md#c-api).

## Performance

![NNAPI EP on RK3399](./images/nnapi-ep-rk3399.png)

![NNAPI EP on OnePlus 6T](./images/nnapi-ep-oneplus6t.png)

![NNAPI EP on Huawei Honor V10](./images/nnapi-ep-huaweihonorv10.png)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 1 addition & 10 deletions tools/ci_build/github/azure-pipelines/win-ci-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,6 @@ jobs:
arguments: '--config $(BuildConfig) --build_dir $(Build.BinariesDirectory) --skip_submodule_sync --build_shared_lib --update --cmake_generator "Visual Studio 16 2019" --build_wheel --use_automl --use_dnnl --use_openmp --build_shared_lib --enable_onnx_tests --build_java'
workingDirectory: '$(Build.BinariesDirectory)'

# - task: BatchScript@1
# displayName: 'Add PATH to build directory'
# inputs:
# filename: '$(Build.SourcesDirectory)\tools\ci_build\github\windows\set_path_to_build_dir.bat'
# arguments: '$(Build.BinariesDirectory)\$(BuildConfig)\$(BuildConfig)'
# modifyEnvironment: true
# workingFolder: '$(Build.BinariesDirectory)'

- task: VSBuild@1
displayName: 'Build'
inputs:
Expand Down Expand Up @@ -79,7 +71,6 @@ jobs:
displayName: 'setup env'
inputs:
filename: '$(Build.SourcesDirectory)\tools\ci_build\github\windows\$(EnvSetupScript)'
# arguments: '$(Build.BinariesDirectory)\$(BuildConfig)\$(BuildConfig)'
modifyEnvironment: true
workingFolder: '$(Build.BinariesDirectory)'

Expand Down Expand Up @@ -121,7 +112,7 @@ jobs:
set /p WHEEL_FILENAME=<wheel_filename_file
del wheel_filename_file
python.exe -m pip install -q --upgrade %WHEEL_FILENAME%
set PATH=%PATH%;$(Build.BinariesDirectory)\$(BuildConfig)\$(BuildConfig)
set PATH=%PATH%;$(Build.BinariesDirectory)\$(BuildConfig)\$(BuildConfig)
python $(Build.SourcesDirectory)\tools\ci_build\build.py --config $(BuildConfig) --build_dir $(Build.BinariesDirectory) --skip_submodule_sync --build_shared_lib --test --cmake_generator "Visual Studio 16 2019" --use_dnnl --build_wheel --enable_onnx_tests
workingDirectory: '$(Build.BinariesDirectory)\$(BuildConfig)\$(BuildConfig)'
Expand Down

0 comments on commit b4a79e6

Please sign in to comment.