macOS M1平台下编译使用ONNX Runtime

1
2
3
4
5
6
7
8
9
10
git clone --recursive --depth=1 --branch v1.18.0 https://github.com/microsoft/onnxruntime.git   
cd onnxruntime

conda create --name onnx python=3.10
conda activate onnx

# 如果系统中已经存在protobuf,nlohmann_json,会在编译时与onnxruntime内部使用的版本发生冲突,为了避免这种情况,在编译前先暂时删除掉
# brew remove protobuf nlohmann-json

./build.sh --config Release --use_coreml --build_shared_lib --parallel --compile_no_warning_as_error --skip_submodule_sync --cmake_extra_defines CMAKE_OSX_ARCHITECTURES=arm64

Please note that these instructions build the debug build, which may have performance tradeoffs. The “–config” parameter has four valid values: Debug, Release, RelWithDebInfo and MinSizeRel. Compared to “Release”, “RelWithDebInfo” not only has debug info, it also disables some inlines to make the binary easier to debug. Thus RelWithDebInfo is slower than Release.

Cross Android Compiling

1
./build.sh --parallel --config Release --android --build_shared_lib --android_sdk_path /Users/luohanjie/Library/Android/sdk --android_ndk_path /Users/luohanjie/Library/Android/sdk/ndk/27.0.12077973 --android_abi arm64-v8a --android_api 29 

Please use NDK 26 as it has a version of clang that handles the bfloat16 type.