Skip to content

Commit

Permalink
Make some compile change for Android NNAPI provider using DNNLibrary (#…
Browse files Browse the repository at this point in the history
…3935)

* Change compile settings for NNAPI with DNNLib

* update build.py

* update build readme
  • Loading branch information
guoyu-wang authored May 14, 2020
1 parent 84c108a commit cba8bdc
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 30 deletions.
4 changes: 2 additions & 2 deletions BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -326,13 +326,13 @@ The basic build commands are below. There are also some other parameters for bui
##### Cross compiling on Windows
```bash
./build.bat --android --android_sdk_path <android sdk path> --android_ndk_path <android ndk path> --dnnlibrary
./build.bat --android --android_sdk_path <android sdk path> --android_ndk_path <android ndk path> --use_dnnlibrary
```

##### Cross compiling on Linux

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

---
Expand Down
4 changes: 2 additions & 2 deletions cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ option(onnxruntime_ENABLE_MEMLEAK_CHECKER "Experimental: Enable memory leak chec
option(onnxruntime_USE_CUDA "Build with CUDA support" OFF)
option(onnxruntime_USE_OPENVINO "Build with OpenVINO support" OFF)
option(onnxruntime_USE_EIGEN_FOR_BLAS "Use eign for blas" ON)
option(onnxruntime_USE_NNAPI "Build with DNNLibrary for Android NNAPI support" OFF)
option(onnxruntime_USE_NNAPI_DNNLIBRARY "Build with DNNLibrary for Android NNAPI support" OFF)
option(onnxruntime_USE_RKNPU "Build with RKNPU support" OFF)
option(onnxruntime_USE_DNNL "Build with DNNL support" OFF)
option(onnxruntime_USE_MKLML "Build the default cpu provider with MKL-ML binary dependency" OFF)
Expand Down Expand Up @@ -880,7 +880,7 @@ if (onnxruntime_ENABLE_TRAINING)
add_subdirectory(horovod EXCLUDE_FROM_ALL)
# use external/horovod/third_party/gloo/cmake/Modules/Findnccl.cmake to locate nccl lib path
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/external/horovod/third_party/gloo/cmake/Modules/)
find_package(nccl REQUIRED)
find_package(nccl REQUIRED)
list(APPEND onnxruntime_EXTERNAL_LIBRARIES horovod ${NCCL_LIBRARIES} ${MPI_CXX_LIBRARIES} ${MPI_CXX_LINK_FLAGS})
endif()
endif()
Expand Down
4 changes: 2 additions & 2 deletions cmake/onnxruntime_java.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ set_source_files_properties(${JAVA_OUTPUT_JAR} PROPERTIES GENERATED TRUE)
set_property(TARGET onnxruntime4j APPEND PROPERTY ADDITIONAL_CLEAN_FILES "${JAVA_OUTPUT_DIR}")

# Specify the native sources
file(GLOB onnxruntime4j_native_src
file(GLOB onnxruntime4j_native_src
"${JAVA_ROOT}/src/main/native/*.c"
"${JAVA_ROOT}/src/main/native/*.h"
"${REPO_ROOT}/include/onnxruntime/core/session/*.h"
Expand All @@ -73,7 +73,7 @@ endif()
if (onnxruntime_USE_TENSORRT)
target_compile_definitions(onnxruntime4j_jni PRIVATE USE_TENSORRT=1)
endif()
if (onnxruntime_USE_NNAPI)
if (onnxruntime_USE_NNAPI_DNNLIBRARY)
target_compile_definitions(onnxruntime4j_jni PRIVATE USE_NNAPI=1)
endif()
if (onnxruntime_USE_NUPHAR)
Expand Down
4 changes: 2 additions & 2 deletions cmake/onnxruntime_providers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ if(onnxruntime_USE_TENSORRT)
set(PROVIDERS_TENSORRT onnxruntime_providers_tensorrt)
list(APPEND ONNXRUNTIME_PROVIDER_NAMES tensorrt)
endif()
if(onnxruntime_USE_NNAPI)
if(onnxruntime_USE_NNAPI_DNNLIBRARY)
set(PROVIDERS_NNAPI onnxruntime_providers_nnapi)
list(APPEND ONNXRUNTIME_PROVIDER_NAMES nnapi)
endif()
Expand Down Expand Up @@ -461,7 +461,7 @@ if (onnxruntime_USE_OPENVINO)

endif()

if (onnxruntime_USE_NNAPI)
if (onnxruntime_USE_NNAPI_DNNLIBRARY)
add_definitions(-DUSE_NNAPI=1)
option(DNN_READ_ONNX "" ON)
set(DNN_CUSTOM_PROTOC_EXECUTABLE ${ONNX_CUSTOM_PROTOC_EXECUTABLE})
Expand Down
2 changes: 1 addition & 1 deletion cmake/onnxruntime_unittests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ if (onnxruntime_USE_NGRAPH)
list(APPEND onnxruntime_test_providers_src ${onnxruntime_test_providers_ngraph_src})
endif()

if (onnxruntime_USE_NNAPI)
if (onnxruntime_USE_NNAPI_DNNLIBRARY)
file(GLOB_RECURSE onnxruntime_test_providers_nnapi_src CONFIGURE_DEPENDS
"${TEST_SRC_DIR}/providers/nnapi/*"
)
Expand Down
7 changes: 2 additions & 5 deletions samples/c_cxx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ endif()
#onnxruntime providers
option(onnxruntime_USE_CUDA "Build with CUDA support" OFF)
option(onnxruntime_USE_OPENVINO "Build with OpenVINO support" OFF)
option(onnxruntime_USE_NNAPI "Build with DNNLibrary for Android NNAPI support" OFF)
option(onnxruntime_USE_NNAPI_DNNLIBRARY "Build with DNNLibrary for Android NNAPI support" OFF)
option(onnxruntime_USE_DNNL "Build with DNNL support" OFF)
option(onnxruntime_USE_NGRAPH "Build with nGraph support" OFF)
option(onnxruntime_USE_NUPHAR "Build with Nuphar" OFF)
Expand Down Expand Up @@ -57,10 +57,7 @@ endif()
if(onnxruntime_USE_OPENVINO)
add_definitions(-DUSE_OPENVINO)
endif()
if(onnxruntime_USE_NNAPI)
add_definitions(-DUSE_NNAPI)
endif()
if(onnxruntime_USE_NNAPI)
if(onnxruntime_USE_NNAPI_DNNLIBRARY)
add_definitions(-DUSE_NNAPI)
endif()
if(onnxruntime_USE_DNNL)
Expand Down
26 changes: 13 additions & 13 deletions server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ project(onnxruntime C CXX)

option(onnxruntime_USE_CUDA "Build with CUDA support" OFF)
option(onnxruntime_USE_OPENVINO "Build with OpenVINO support" OFF)
option(onnxruntime_USE_NNAPI "Build with DNNLibrary for Android NNAPI support" OFF)
option(onnxruntime_USE_NNAPI_DNNLIBRARY "Build with DNNLibrary for Android NNAPI support" OFF)
option(onnxruntime_USE_DNNL "Build with DNNL support" OFF)
option(onnxruntime_USE_NGRAPH "Build with nGraph support" OFF)
option(onnxruntime_USE_NUPHAR "Build with Nuphar" OFF)
Expand All @@ -23,7 +23,7 @@ endif()
if(onnxruntime_USE_OPENVINO)
add_definitions(-DUSE_OPENVINO=1)
endif()
if(onnxruntime_USE_NNAPI)
if(onnxruntime_USE_NNAPI_DNNLIBRARY)
add_definitions(-DUSE_NNAPI=1)
endif()
if(onnxruntime_USE_DNNL)
Expand Down Expand Up @@ -88,7 +88,7 @@ endif()
add_custom_command(
OUTPUT "${grpc_srcs}" "${grpc_hdrs}"
COMMAND protoc
ARGS
ARGS
--cpp_out "${CMAKE_CURRENT_BINARY_DIR}"
--grpc_out "${CMAKE_CURRENT_BINARY_DIR}"
--plugin=protoc-gen-grpc="${_gRPC_CPP_PLUGIN_EXECUTABLE}"
Expand Down Expand Up @@ -155,7 +155,7 @@ target_include_directories(onnxruntime_server_http_core_lib
${ONNXRUNTIME_SERVER_ROOT}/http/core
${ONNXRUNTIME_SERVER_ROOT}/core
${Boost_INCLUDE_DIR}

)
add_dependencies(onnxruntime_server_http_core_lib Boost)

Expand All @@ -167,7 +167,7 @@ target_include_directories(onnxruntime_server_lib PRIVATE
${ONNXRUNTIME_SERVER_ROOT}
${ONNXRUNTIME_SERVER_ROOT}/http
${ONNXRUNTIME_SERVER_ROOT}/logging
${ONNXRUNTIME_SERVER_ROOT}/core
${ONNXRUNTIME_SERVER_ROOT}/core
PUBLIC
${ONNXRUNTIME_SERVER_ROOT}/external/spdlog/include
${ONNXRUNTIME_SERVER_ROOT}/http/core
Expand Down Expand Up @@ -208,10 +208,10 @@ target_include_directories(${SERVER_APP_NAME} PRIVATE
target_link_libraries(${SERVER_APP_NAME} PRIVATE
onnxruntime_server_http_core_lib
onnxruntime_server_lib
${grpc_reflection} #Note that this will break the tests if we try to link it to the lib so just link to the executable.
${grpc_reflection} #Note that this will break the tests if we try to link it to the lib so just link to the executable.
server_grpc_proto server_proto
${Boost_LIBRARIES}
onnxruntime_server_http_core_lib
onnxruntime_server_http_core_lib
${grpc_static_libs} protobuf::libprotobuf
spdlog::spdlog
onnxruntime gtest re2 ${CMAKE_DL_LIBS} Threads::Threads
Expand All @@ -237,34 +237,34 @@ file(GLOB onnxruntime_test_server_src
set_source_files_properties("test/unit_tests/executor_test.cc" PROPERTIES COMPILE_FLAGS -Wno-unused-parameter)
endif()
endif()

add_executable(onnxruntime_server_tests ${onnxruntime_test_server_src})
add_dependencies(onnxruntime_server_tests server_proto Boost)
target_link_libraries(onnxruntime_server_tests PRIVATE onnxruntime_server_http_core_lib
onnxruntime_server_lib
${grpc_reflection} #Note that this will break the tests if we try to link it to the lib so just link to the executable.
${grpc_reflection} #Note that this will break the tests if we try to link it to the lib so just link to the executable.
server_grpc_proto server_proto
${Boost_LIBRARIES}
onnxruntime_server_http_core_lib
onnxruntime_server_http_core_lib
${grpc_static_libs} protobuf::libprotobuf
spdlog::spdlog
onnxruntime gtest re2 gtest ${CMAKE_DL_LIBS} Threads::Threads)
target_include_directories(onnxruntime_server_tests PRIVATE ${ONNXRUNTIME_SERVER_ROOT}/external/spdlog/include
${ONNXRUNTIME_SERVER_ROOT}/http/core
${ONNXRUNTIME_SERVER_ROOT} ${ONNXRUNTIME_SERVER_ROOT}/core)
onnxruntime_protobuf_generate(
APPEND_PATH IMPORT_DIRS ${ONNXRUNTIME_SERVER_ROOT}/protobuf
APPEND_PATH IMPORT_DIRS ${ONNXRUNTIME_SERVER_ROOT}/protobuf
PROTOS ${ONNXRUNTIME_SERVER_ROOT}/protobuf/predict.proto protobuf/onnx-ml.proto
LANGUAGE python
TARGET onnxruntime_server_tests
OUT_VAR server_test_py)

set(grpc_py "${CMAKE_CURRENT_BINARY_DIR}/prediction_service_pb2_grpc.py")

add_custom_command(
TARGET onnxruntime_server_tests
COMMAND protoc
ARGS
ARGS
--grpc_out "${CMAKE_CURRENT_BINARY_DIR}"
--plugin=protoc-gen-grpc=${_gRPC_PYTHON_PLUGIN_EXECUTABLE}
-I ${grpc_proto_path}
Expand Down
6 changes: 3 additions & 3 deletions tools/ci_build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ def generate_build_tree(cmake_path, source_dir, build_dir, cuda_home,
"ON" if args.use_openvino == "VAD-F_FP32" else "OFF"),
"-Donnxruntime_USE_OPENVINO_BINARY=" + (
"ON" if args.use_openvino else "OFF"),
"-Donnxruntime_USE_NNAPI=" + ("ON" if args.use_dnnlibrary else "OFF"),
"-Donnxruntime_USE_NNAPI_DNNLIBRARY=" + ("ON" if args.use_dnnlibrary else "OFF"),
"-Donnxruntime_USE_RKNPU=" + ("ON" if args.use_rknpu else "OFF"),
"-Donnxruntime_USE_OPENMP=" + (
"ON" if args.use_openmp and not (
Expand Down Expand Up @@ -1545,6 +1545,8 @@ def main():
if args.update:
cmake_extra_args = []
path_to_protoc_exe = args.path_to_protoc_exe
if not args.skip_submodule_sync:
update_submodules(source_dir)
if is_windows():
if args.cmake_generator == 'Ninja':
if args.x86 or args.arm or args.arm64:
Expand Down Expand Up @@ -1617,8 +1619,6 @@ def main():
install_python_deps()
if args.enable_pybind and is_windows():
install_python_deps(args.numpy_version)
if not args.skip_submodule_sync:
update_submodules(source_dir)
if args.enable_onnx_tests:
setup_test_data(build_dir, configs)
generate_build_tree(
Expand Down

0 comments on commit cba8bdc

Please sign in to comment.